diff --git a/reactos/dll/directx/wine/d3d8/buffer.c b/reactos/dll/directx/wine/d3d8/buffer.c index 8cf55311ba9..4ab6524c2c0 100644 --- a/reactos/dll/directx/wine/d3d8/buffer.c +++ b/reactos/dll/directx/wine/d3d8/buffer.c @@ -17,10 +17,16 @@ */ #include "config.h" +#include #include "d3d8_private.h" WINE_DEFAULT_DEBUG_CHANNEL(d3d8); +static inline IDirect3DVertexBuffer8Impl *impl_from_IDirect3DVertexBuffer8(IDirect3DVertexBuffer8 *iface) +{ + return CONTAINING_RECORD(iface, IDirect3DVertexBuffer8Impl, IDirect3DVertexBuffer8_iface); +} + static HRESULT WINAPI d3d8_vertexbuffer_QueryInterface(IDirect3DVertexBuffer8 *iface, REFIID riid, void **object) { TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); @@ -42,7 +48,7 @@ static HRESULT WINAPI d3d8_vertexbuffer_QueryInterface(IDirect3DVertexBuffer8 *i static ULONG WINAPI d3d8_vertexbuffer_AddRef(IDirect3DVertexBuffer8 *iface) { - IDirect3DVertexBuffer8Impl *buffer = (IDirect3DVertexBuffer8Impl *)iface; + IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface); ULONG refcount = InterlockedIncrement(&buffer->ref); TRACE("%p increasing refcount to %u.\n", iface, refcount); @@ -60,7 +66,7 @@ static ULONG WINAPI d3d8_vertexbuffer_AddRef(IDirect3DVertexBuffer8 *iface) static ULONG WINAPI d3d8_vertexbuffer_Release(IDirect3DVertexBuffer8 *iface) { - IDirect3DVertexBuffer8Impl *buffer = (IDirect3DVertexBuffer8Impl *)iface; + IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface); ULONG refcount = InterlockedDecrement(&buffer->ref); TRACE("%p decreasing refcount to %u.\n", iface, refcount); @@ -80,11 +86,14 @@ static ULONG WINAPI d3d8_vertexbuffer_Release(IDirect3DVertexBuffer8 *iface) return refcount; } -static HRESULT WINAPI d3d8_vertexbuffer_GetDevice(IDirect3DVertexBuffer8 *iface, IDirect3DDevice8 **device) +static HRESULT WINAPI d3d8_vertexbuffer_GetDevice(IDirect3DVertexBuffer8 *iface, + IDirect3DDevice8 **device) { + IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface); + TRACE("iface %p, device %p.\n", iface, device); - *device = (IDirect3DDevice8 *)((IDirect3DVertexBuffer8Impl *)iface)->parentDevice; + *device = buffer->parentDevice; IDirect3DDevice8_AddRef(*device); TRACE("Returning device %p.\n", *device); @@ -95,14 +104,16 @@ static HRESULT WINAPI d3d8_vertexbuffer_GetDevice(IDirect3DVertexBuffer8 *iface, static HRESULT WINAPI d3d8_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer8 *iface, REFGUID guid, const void *data, DWORD data_size, DWORD flags) { + IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", iface, debugstr_guid(guid), data, data_size, flags); wined3d_mutex_lock(); - hr = wined3d_buffer_set_private_data(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer, - guid, data, data_size, flags); + resource = wined3d_buffer_get_resource(buffer->wineD3DVertexBuffer); + hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags); wined3d_mutex_unlock(); return hr; @@ -111,14 +122,16 @@ static HRESULT WINAPI d3d8_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer8 *i static HRESULT WINAPI d3d8_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer8 *iface, REFGUID guid, void *data, DWORD *data_size) { + IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %p.\n", iface, debugstr_guid(guid), data, data_size); wined3d_mutex_lock(); - hr = wined3d_buffer_get_private_data(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer, - guid, data, data_size); + resource = wined3d_buffer_get_resource(buffer->wineD3DVertexBuffer); + hr = wined3d_resource_get_private_data(resource, guid, data, data_size); wined3d_mutex_unlock(); return hr; @@ -126,12 +139,15 @@ static HRESULT WINAPI d3d8_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer8 *i static HRESULT WINAPI d3d8_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer8 *iface, REFGUID guid) { + IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid)); wined3d_mutex_lock(); - hr = wined3d_buffer_free_private_data(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer, guid); + resource = wined3d_buffer_get_resource(buffer->wineD3DVertexBuffer); + hr = wined3d_resource_free_private_data(resource, guid); wined3d_mutex_unlock(); return hr; @@ -139,12 +155,13 @@ static HRESULT WINAPI d3d8_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer8 * static DWORD WINAPI d3d8_vertexbuffer_SetPriority(IDirect3DVertexBuffer8 *iface, DWORD priority) { + IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface); DWORD previous; TRACE("iface %p, priority %u.\n", iface, priority); wined3d_mutex_lock(); - previous = wined3d_buffer_set_priority(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer, priority); + previous = wined3d_buffer_set_priority(buffer->wineD3DVertexBuffer, priority); wined3d_mutex_unlock(); return previous; @@ -152,12 +169,13 @@ static DWORD WINAPI d3d8_vertexbuffer_SetPriority(IDirect3DVertexBuffer8 *iface, static DWORD WINAPI d3d8_vertexbuffer_GetPriority(IDirect3DVertexBuffer8 *iface) { + IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface); DWORD priority; TRACE("iface %p.\n", iface); wined3d_mutex_lock(); - priority = wined3d_buffer_get_priority(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer); + priority = wined3d_buffer_get_priority(buffer->wineD3DVertexBuffer); wined3d_mutex_unlock(); return priority; @@ -165,10 +183,12 @@ static DWORD WINAPI d3d8_vertexbuffer_GetPriority(IDirect3DVertexBuffer8 *iface) static void WINAPI d3d8_vertexbuffer_PreLoad(IDirect3DVertexBuffer8 *iface) { + IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface); + TRACE("iface %p.\n", iface); wined3d_mutex_lock(); - wined3d_buffer_preload(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer); + wined3d_buffer_preload(buffer->wineD3DVertexBuffer); wined3d_mutex_unlock(); } @@ -179,17 +199,17 @@ static D3DRESOURCETYPE WINAPI d3d8_vertexbuffer_GetType(IDirect3DVertexBuffer8 * return D3DRTYPE_VERTEXBUFFER; } -static HRESULT WINAPI d3d8_vertexbuffer_Lock(IDirect3DVertexBuffer8 *iface, - UINT offset, UINT size, BYTE **data, DWORD flags) +static HRESULT WINAPI d3d8_vertexbuffer_Lock(IDirect3DVertexBuffer8 *iface, UINT offset, UINT size, + BYTE **data, DWORD flags) { + IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface); HRESULT hr; TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n", iface, offset, size, data, flags); wined3d_mutex_lock(); - hr = wined3d_buffer_map(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer, - offset, size, data, flags); + hr = wined3d_buffer_map(buffer->wineD3DVertexBuffer, offset, size, data, flags); wined3d_mutex_unlock(); return hr; @@ -197,18 +217,21 @@ static HRESULT WINAPI d3d8_vertexbuffer_Lock(IDirect3DVertexBuffer8 *iface, static HRESULT WINAPI d3d8_vertexbuffer_Unlock(IDirect3DVertexBuffer8 *iface) { + IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface); + TRACE("iface %p.\n", iface); wined3d_mutex_lock(); - wined3d_buffer_unmap(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer); + wined3d_buffer_unmap(buffer->wineD3DVertexBuffer); wined3d_mutex_unlock(); return D3D_OK; } -static HRESULT WINAPI d3d8_vertexbuffer_GetDesc(IDirect3DVertexBuffer8 *iface, D3DVERTEXBUFFER_DESC *desc) +static HRESULT WINAPI d3d8_vertexbuffer_GetDesc(IDirect3DVertexBuffer8 *iface, + D3DVERTEXBUFFER_DESC *desc) { - IDirect3DVertexBuffer8Impl *buffer = (IDirect3DVertexBuffer8Impl *)iface; + IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface); struct wined3d_resource_desc wined3d_desc; struct wined3d_resource *wined3d_resource; @@ -220,7 +243,7 @@ static HRESULT WINAPI d3d8_vertexbuffer_GetDesc(IDirect3DVertexBuffer8 *iface, D wined3d_mutex_unlock(); desc->Type = D3DRTYPE_VERTEXBUFFER; - desc->Usage = wined3d_desc.usage; + desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->Size = wined3d_desc.size; desc->FVF = buffer->fvf; @@ -265,13 +288,13 @@ HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Im { HRESULT hr; - buffer->lpVtbl = &Direct3DVertexBuffer8_Vtbl; + buffer->IDirect3DVertexBuffer8_iface.lpVtbl = &Direct3DVertexBuffer8_Vtbl; buffer->ref = 1; buffer->fvf = fvf; wined3d_mutex_lock(); hr = wined3d_buffer_create_vb(device->wined3d_device, size, usage & WINED3DUSAGE_MASK, - (WINED3DPOOL)pool, buffer, &d3d8_vertexbuffer_wined3d_parent_ops, &buffer->wineD3DVertexBuffer); + (enum wined3d_pool)pool, buffer, &d3d8_vertexbuffer_wined3d_parent_ops, &buffer->wineD3DVertexBuffer); wined3d_mutex_unlock(); if (FAILED(hr)) { @@ -285,6 +308,20 @@ HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Im return D3D_OK; } +IDirect3DVertexBuffer8Impl *unsafe_impl_from_IDirect3DVertexBuffer8(IDirect3DVertexBuffer8 *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &Direct3DVertexBuffer8_Vtbl); + + return impl_from_IDirect3DVertexBuffer8(iface); +} + +static inline IDirect3DIndexBuffer8Impl *impl_from_IDirect3DIndexBuffer8(IDirect3DIndexBuffer8 *iface) +{ + return CONTAINING_RECORD(iface, IDirect3DIndexBuffer8Impl, IDirect3DIndexBuffer8_iface); +} + static HRESULT WINAPI d3d8_indexbuffer_QueryInterface(IDirect3DIndexBuffer8 *iface, REFIID riid, void **object) { TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); @@ -306,7 +343,7 @@ static HRESULT WINAPI d3d8_indexbuffer_QueryInterface(IDirect3DIndexBuffer8 *ifa static ULONG WINAPI d3d8_indexbuffer_AddRef(IDirect3DIndexBuffer8 *iface) { - IDirect3DIndexBuffer8Impl *buffer = (IDirect3DIndexBuffer8Impl *)iface; + IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface); ULONG refcount = InterlockedIncrement(&buffer->ref); TRACE("%p increasing refcount to %u.\n", iface, refcount); @@ -324,7 +361,7 @@ static ULONG WINAPI d3d8_indexbuffer_AddRef(IDirect3DIndexBuffer8 *iface) static ULONG WINAPI d3d8_indexbuffer_Release(IDirect3DIndexBuffer8 *iface) { - IDirect3DIndexBuffer8Impl *buffer = (IDirect3DIndexBuffer8Impl *)iface; + IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface); ULONG refcount = InterlockedDecrement(&buffer->ref); TRACE("%p decreasing refcount to %u.\n", iface, refcount); @@ -344,11 +381,14 @@ static ULONG WINAPI d3d8_indexbuffer_Release(IDirect3DIndexBuffer8 *iface) return refcount; } -static HRESULT WINAPI d3d8_indexbuffer_GetDevice(IDirect3DIndexBuffer8 *iface, IDirect3DDevice8 **device) +static HRESULT WINAPI d3d8_indexbuffer_GetDevice(IDirect3DIndexBuffer8 *iface, + IDirect3DDevice8 **device) { + IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface); + TRACE("iface %p, device %p.\n", iface, device); - *device = (IDirect3DDevice8 *)((IDirect3DIndexBuffer8Impl *)iface)->parentDevice; + *device = buffer->parentDevice; IDirect3DDevice8_AddRef(*device); TRACE("Returning device %p.\n", *device); @@ -359,14 +399,16 @@ static HRESULT WINAPI d3d8_indexbuffer_GetDevice(IDirect3DIndexBuffer8 *iface, I static HRESULT WINAPI d3d8_indexbuffer_SetPrivateData(IDirect3DIndexBuffer8 *iface, REFGUID guid, const void *data, DWORD data_size, DWORD flags) { + IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", iface, debugstr_guid(guid), data, data_size, flags); wined3d_mutex_lock(); - hr = wined3d_buffer_set_private_data(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer, - guid, data, data_size, flags); + resource = wined3d_buffer_get_resource(buffer->wineD3DIndexBuffer); + hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags); wined3d_mutex_unlock(); return hr; @@ -375,14 +417,16 @@ static HRESULT WINAPI d3d8_indexbuffer_SetPrivateData(IDirect3DIndexBuffer8 *ifa static HRESULT WINAPI d3d8_indexbuffer_GetPrivateData(IDirect3DIndexBuffer8 *iface, REFGUID guid, void *data, DWORD *data_size) { + IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %p.\n", iface, debugstr_guid(guid), data, data_size); wined3d_mutex_lock(); - hr = wined3d_buffer_get_private_data(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer, - guid, data, data_size); + resource = wined3d_buffer_get_resource(buffer->wineD3DIndexBuffer); + hr = wined3d_resource_get_private_data(resource, guid, data, data_size); wined3d_mutex_unlock(); return hr; @@ -390,12 +434,15 @@ static HRESULT WINAPI d3d8_indexbuffer_GetPrivateData(IDirect3DIndexBuffer8 *ifa static HRESULT WINAPI d3d8_indexbuffer_FreePrivateData(IDirect3DIndexBuffer8 *iface, REFGUID guid) { + IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid)); wined3d_mutex_lock(); - hr = wined3d_buffer_free_private_data(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer, guid); + resource = wined3d_buffer_get_resource(buffer->wineD3DIndexBuffer); + hr = wined3d_resource_free_private_data(resource, guid); wined3d_mutex_unlock(); return hr; @@ -403,12 +450,13 @@ static HRESULT WINAPI d3d8_indexbuffer_FreePrivateData(IDirect3DIndexBuffer8 *if static DWORD WINAPI d3d8_indexbuffer_SetPriority(IDirect3DIndexBuffer8 *iface, DWORD priority) { + IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface); DWORD previous; TRACE("iface %p, priority %u.\n", iface, priority); wined3d_mutex_lock(); - previous = wined3d_buffer_set_priority(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer, priority); + previous = wined3d_buffer_set_priority(buffer->wineD3DIndexBuffer, priority); wined3d_mutex_unlock(); return previous; @@ -416,12 +464,13 @@ static DWORD WINAPI d3d8_indexbuffer_SetPriority(IDirect3DIndexBuffer8 *iface, D static DWORD WINAPI d3d8_indexbuffer_GetPriority(IDirect3DIndexBuffer8 *iface) { + IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface); DWORD priority; TRACE("iface %p.\n", iface); wined3d_mutex_lock(); - priority = wined3d_buffer_get_priority(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer); + priority = wined3d_buffer_get_priority(buffer->wineD3DIndexBuffer); wined3d_mutex_unlock(); return priority; @@ -429,10 +478,12 @@ static DWORD WINAPI d3d8_indexbuffer_GetPriority(IDirect3DIndexBuffer8 *iface) static void WINAPI d3d8_indexbuffer_PreLoad(IDirect3DIndexBuffer8 *iface) { + IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface); + TRACE("iface %p.\n", iface); wined3d_mutex_lock(); - wined3d_buffer_preload(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer); + wined3d_buffer_preload(buffer->wineD3DIndexBuffer); wined3d_mutex_unlock(); } @@ -443,17 +494,17 @@ static D3DRESOURCETYPE WINAPI d3d8_indexbuffer_GetType(IDirect3DIndexBuffer8 *if return D3DRTYPE_INDEXBUFFER; } -static HRESULT WINAPI d3d8_indexbuffer_Lock(IDirect3DIndexBuffer8 *iface, - UINT offset, UINT size, BYTE **data, DWORD flags) +static HRESULT WINAPI d3d8_indexbuffer_Lock(IDirect3DIndexBuffer8 *iface, UINT offset, UINT size, + BYTE **data, DWORD flags) { + IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface); HRESULT hr; TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n", iface, offset, size, data, flags); wined3d_mutex_lock(); - hr = wined3d_buffer_map(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer, - offset, size, data, flags); + hr = wined3d_buffer_map(buffer->wineD3DIndexBuffer, offset, size, data, flags); wined3d_mutex_unlock(); return hr; @@ -461,18 +512,21 @@ static HRESULT WINAPI d3d8_indexbuffer_Lock(IDirect3DIndexBuffer8 *iface, static HRESULT WINAPI d3d8_indexbuffer_Unlock(IDirect3DIndexBuffer8 *iface) { + IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface); + TRACE("iface %p.\n", iface); wined3d_mutex_lock(); - wined3d_buffer_unmap(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer); + wined3d_buffer_unmap(buffer->wineD3DIndexBuffer); wined3d_mutex_unlock(); return D3D_OK; } -static HRESULT WINAPI d3d8_indexbuffer_GetDesc(IDirect3DIndexBuffer8 *iface, D3DINDEXBUFFER_DESC *desc) +static HRESULT WINAPI d3d8_indexbuffer_GetDesc(IDirect3DIndexBuffer8 *iface, + D3DINDEXBUFFER_DESC *desc) { - IDirect3DIndexBuffer8Impl *buffer = (IDirect3DIndexBuffer8Impl *)iface; + IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface); struct wined3d_resource_desc wined3d_desc; struct wined3d_resource *wined3d_resource; @@ -485,7 +539,7 @@ static HRESULT WINAPI d3d8_indexbuffer_GetDesc(IDirect3DIndexBuffer8 *iface, D3D desc->Format = d3dformat_from_wined3dformat(buffer->format); desc->Type = D3DRTYPE_INDEXBUFFER; - desc->Usage = wined3d_desc.usage; + desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->Size = wined3d_desc.size; @@ -528,13 +582,13 @@ HRESULT indexbuffer_init(IDirect3DIndexBuffer8Impl *buffer, IDirect3DDevice8Impl { HRESULT hr; - buffer->lpVtbl = &d3d8_indexbuffer_vtbl; + buffer->IDirect3DIndexBuffer8_iface.lpVtbl = &d3d8_indexbuffer_vtbl; buffer->ref = 1; buffer->format = wined3dformat_from_d3dformat(format); wined3d_mutex_lock(); hr = wined3d_buffer_create_ib(device->wined3d_device, size, usage & WINED3DUSAGE_MASK, - (WINED3DPOOL)pool, buffer, &d3d8_indexbuffer_wined3d_parent_ops, &buffer->wineD3DIndexBuffer); + (enum wined3d_pool)pool, buffer, &d3d8_indexbuffer_wined3d_parent_ops, &buffer->wineD3DIndexBuffer); wined3d_mutex_unlock(); if (FAILED(hr)) { @@ -547,3 +601,12 @@ HRESULT indexbuffer_init(IDirect3DIndexBuffer8Impl *buffer, IDirect3DDevice8Impl return D3D_OK; } + +IDirect3DIndexBuffer8Impl *unsafe_impl_from_IDirect3DIndexBuffer8(IDirect3DIndexBuffer8 *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &d3d8_indexbuffer_vtbl); + + return impl_from_IDirect3DIndexBuffer8(iface); +} diff --git a/reactos/dll/directx/wine/d3d8/cubetexture.c b/reactos/dll/directx/wine/d3d8/cubetexture.c index 5915c54e730..f092f35bfa6 100644 --- a/reactos/dll/directx/wine/d3d8/cubetexture.c +++ b/reactos/dll/directx/wine/d3d8/cubetexture.c @@ -97,7 +97,7 @@ static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetDevice(IDirect3DCubeTexture8 TRACE("iface %p, device %p.\n", iface, device); - *device = (IDirect3DDevice8 *)This->parentDevice; + *device = This->parentDevice; IDirect3DDevice8_AddRef(*device); TRACE("Returning device %p.\n", *device); @@ -109,13 +109,15 @@ static HRESULT WINAPI IDirect3DCubeTexture8Impl_SetPrivateData(IDirect3DCubeText REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) { IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", iface, debugstr_guid(refguid), pData, SizeOfData, Flags); wined3d_mutex_lock(); - hr = wined3d_texture_set_private_data(This->wined3d_texture, refguid, pData, SizeOfData, Flags); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags); wined3d_mutex_unlock(); return hr; @@ -125,13 +127,15 @@ static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetPrivateData(IDirect3DCubeText REFGUID refguid, void *pData, DWORD *pSizeOfData) { IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %p.\n", iface, debugstr_guid(refguid), pData, pSizeOfData); wined3d_mutex_lock(); - hr = wined3d_texture_get_private_data(This->wined3d_texture, refguid, pData, pSizeOfData); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData); wined3d_mutex_unlock(); return hr; @@ -141,12 +145,14 @@ static HRESULT WINAPI IDirect3DCubeTexture8Impl_FreePrivateData(IDirect3DCubeTex REFGUID refguid) { IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid)); wined3d_mutex_lock(); - hr = wined3d_texture_free_private_data(This->wined3d_texture, refguid); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_free_private_data(resource, refguid); wined3d_mutex_unlock(); return hr; @@ -194,16 +200,9 @@ static void WINAPI IDirect3DCubeTexture8Impl_PreLoad(IDirect3DCubeTexture8 *ifac static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture8Impl_GetType(IDirect3DCubeTexture8 *iface) { - IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface); - D3DRESOURCETYPE type; - TRACE("iface %p.\n", iface); - wined3d_mutex_lock(); - type = wined3d_texture_get_type(This->wined3d_texture); - wined3d_mutex_unlock(); - - return type; + return D3DRTYPE_CUBETEXTURE; } /* IDirect3DCubeTexture8 IDirect3DBaseTexture8 Interface follow: */ @@ -269,7 +268,7 @@ static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetLevelDesc(IDirect3DCubeTextur wined3d_resource_get_desc(sub_resource, &wined3d_desc); desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format); desc->Type = wined3d_desc.resource_type; - desc->Usage = wined3d_desc.usage; + desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->Size = wined3d_desc.size; desc->MultiSampleType = wined3d_desc.multisample_type; @@ -364,14 +363,14 @@ static HRESULT WINAPI IDirect3DCubeTexture8Impl_AddDirtyRect(IDirect3DCubeTextur hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, NULL); else { - WINED3DBOX dirty_region; + struct wined3d_box dirty_region; - dirty_region.Left = dirty_rect->left; - dirty_region.Top = dirty_rect->top; - dirty_region.Right = dirty_rect->right; - dirty_region.Bottom = dirty_rect->bottom; - dirty_region.Front = 0; - dirty_region.Back = 1; + dirty_region.left = dirty_rect->left; + dirty_region.top = dirty_rect->top; + dirty_region.right = dirty_rect->right; + dirty_region.bottom = dirty_rect->bottom; + dirty_region.front = 0; + dirty_region.back = 1; hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, &dirty_region); } wined3d_mutex_unlock(); diff --git a/reactos/dll/directx/wine/d3d8/d3d8_main.c b/reactos/dll/directx/wine/d3d8/d3d8_main.c index 7a25a93c928..7e7da43807a 100644 --- a/reactos/dll/directx/wine/d3d8/d3d8_main.c +++ b/reactos/dll/directx/wine/d3d8/d3d8_main.c @@ -45,7 +45,7 @@ IDirect3D8* WINAPI DECLSPEC_HOTPATCH Direct3DCreate8(UINT SDKVersion) { object->IDirect3D8_iface.lpVtbl = &Direct3D8_Vtbl; object->ref = 1; - object->WineD3D = wined3d_create(8, &object->IDirect3D8_iface); + object->WineD3D = wined3d_create(8, WINED3D_LEGACY_DEPTH_BIAS, &object->IDirect3D8_iface); TRACE("Created Direct3D object @ %p, WineObj @ %p\n", object, object->WineD3D); diff --git a/reactos/dll/directx/wine/d3d8/d3d8_private.h b/reactos/dll/directx/wine/d3d8/d3d8_private.h index 914dec58357..c47d05a5fc7 100644 --- a/reactos/dll/directx/wine/d3d8/d3d8_private.h +++ b/reactos/dll/directx/wine/d3d8/d3d8_private.h @@ -177,7 +177,8 @@ struct IDirect3DDevice8Impl IDirect3DDevice8 IDirect3DDevice8_iface; struct wined3d_device_parent device_parent; LONG ref; - struct wined3d_device *wined3d_device; + struct wined3d_device *wined3d_device; + IDirect3D8 *d3d_parent; struct d3d8_handle_table handle_table; /* FVF management */ @@ -189,7 +190,7 @@ struct IDirect3DDevice8Impl BOOL lost; }; -HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT adapter, +HRESULT device_init(IDirect3DDevice8Impl *device, IDirect3D8Impl *parent, struct wined3d *wined3d, UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters) DECLSPEC_HIDDEN; /* ---------------- */ @@ -209,7 +210,7 @@ struct IDirect3DVolume8Impl }; HRESULT volume_init(IDirect3DVolume8Impl *volume, IDirect3DDevice8Impl *device, UINT width, UINT height, - UINT depth, DWORD usage, enum wined3d_format_id format, WINED3DPOOL pool) DECLSPEC_HIDDEN; + UINT depth, DWORD usage, enum wined3d_format_id format, enum wined3d_pool pool) DECLSPEC_HIDDEN; /* ------------------- */ /* IDirect3DSwapChain8 */ @@ -239,9 +240,8 @@ HRESULT swapchain_init(IDirect3DSwapChain8Impl *swapchain, IDirect3DDevice8Impl */ struct IDirect3DSurface8Impl { - /* IUnknown fields */ - const IDirect3DSurface8Vtbl *lpVtbl; - LONG ref; + IDirect3DSurface8 IDirect3DSurface8_iface; + LONG ref; struct wined3d_surface *wined3d_surface; IDirect3DDevice8 *parentDevice; @@ -255,6 +255,7 @@ struct IDirect3DSurface8Impl HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *device, UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level, DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality) DECLSPEC_HIDDEN; +IDirect3DSurface8Impl *unsafe_impl_from_IDirect3DSurface8(IDirect3DSurface8 *iface) DECLSPEC_HIDDEN; /* ---------------------- */ /* IDirect3DVertexBuffer8 */ @@ -265,10 +266,8 @@ HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *devic */ struct IDirect3DVertexBuffer8Impl { - /* IUnknown fields */ - const IDirect3DVertexBuffer8Vtbl *lpVtbl; - LONG ref; - + IDirect3DVertexBuffer8 IDirect3DVertexBuffer8_iface; + LONG ref; struct wined3d_buffer *wineD3DVertexBuffer; IDirect3DDevice8 *parentDevice; DWORD fvf; @@ -276,6 +275,7 @@ struct IDirect3DVertexBuffer8Impl HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Impl *device, UINT size, DWORD usage, DWORD fvf, D3DPOOL pool) DECLSPEC_HIDDEN; +IDirect3DVertexBuffer8Impl *unsafe_impl_from_IDirect3DVertexBuffer8(IDirect3DVertexBuffer8 *iface) DECLSPEC_HIDDEN; /* --------------------- */ /* IDirect3DIndexBuffer8 */ @@ -286,10 +286,8 @@ HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Im */ struct IDirect3DIndexBuffer8Impl { - /* IUnknown fields */ - const IDirect3DIndexBuffer8Vtbl *lpVtbl; - LONG ref; - + IDirect3DIndexBuffer8 IDirect3DIndexBuffer8_iface; + LONG ref; struct wined3d_buffer *wineD3DIndexBuffer; IDirect3DDevice8 *parentDevice; enum wined3d_format_id format; @@ -297,6 +295,7 @@ struct IDirect3DIndexBuffer8Impl HRESULT indexbuffer_init(IDirect3DIndexBuffer8Impl *buffer, IDirect3DDevice8Impl *device, UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN; +IDirect3DIndexBuffer8Impl *unsafe_impl_from_IDirect3DIndexBuffer8(IDirect3DIndexBuffer8 *iface) DECLSPEC_HIDDEN; /* --------------------- */ /* IDirect3DBaseTexture8 */ diff --git a/reactos/dll/directx/wine/d3d8/device.c b/reactos/dll/directx/wine/d3d8/device.c index aa85c61c398..91942e1ce0b 100644 --- a/reactos/dll/directx/wine/d3d8/device.c +++ b/reactos/dll/directx/wine/d3d8/device.c @@ -301,6 +301,7 @@ static ULONG WINAPI IDirect3DDevice8Impl_Release(IDirect3DDevice8 *iface) if (ref == 0) { unsigned i; + IDirect3D8 *parent = This->d3d_parent; TRACE("Releasing wined3d device %p.\n", This->wined3d_device); @@ -320,6 +321,8 @@ static ULONG WINAPI IDirect3DDevice8Impl_Release(IDirect3DDevice8 *iface) HeapFree(GetProcessHeap(), 0, This); wined3d_mutex_unlock(); + + IDirect3D8_Release(parent); } return ref; } @@ -358,23 +361,20 @@ static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(IDirect3D DWORD Bytes) { IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface); - HRESULT hr; TRACE("iface %p, byte_count %u.\n", iface, Bytes); - FIXME("Byte count ignored.\n"); + if (Bytes) FIXME("Byte count ignored.\n"); wined3d_mutex_lock(); - hr = wined3d_device_evict_managed_resources(This->wined3d_device); + wined3d_device_evict_managed_resources(This->wined3d_device); wined3d_mutex_unlock(); - return hr; + return D3D_OK; } static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(IDirect3DDevice8 *iface, IDirect3D8 **ppD3D8) { IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface); - struct wined3d *wined3d; - HRESULT hr; TRACE("iface %p, d3d8 %p.\n", iface, ppD3D8); @@ -382,24 +382,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(IDirect3DDevice8 *iface, return D3DERR_INVALIDCALL; } - wined3d_mutex_lock(); - hr = wined3d_device_get_wined3d(This->wined3d_device, &wined3d); - if (SUCCEEDED(hr) && wined3d) - { - *ppD3D8 = wined3d_get_parent(wined3d); - IDirect3D8_AddRef(*ppD3D8); - wined3d_decref(wined3d); - } - else - { - FIXME("Call to IWineD3DDevice_GetDirect3D failed\n"); - *ppD3D8 = NULL; - } - wined3d_mutex_unlock(); - - TRACE("(%p) returning %p\n",This , *ppD3D8); - - return hr; + return IDirect3D8_QueryInterface(This->d3d_parent, &IID_IDirect3D8, (void **)ppD3D8); } static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(IDirect3DDevice8 *iface, D3DCAPS8 *pCaps) @@ -439,7 +422,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(IDirect3DDevice8 *ifac TRACE("iface %p, mode %p.\n", iface, pMode); wined3d_mutex_lock(); - hr = wined3d_device_get_display_mode(This->wined3d_device, 0, (WINED3DDISPLAYMODE *)pMode); + hr = wined3d_device_get_display_mode(This->wined3d_device, 0, (struct wined3d_display_mode *)pMode); wined3d_mutex_unlock(); if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format); @@ -457,7 +440,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(IDirect3DDevice wined3d_mutex_lock(); hr = wined3d_device_get_creation_parameters(This->wined3d_device, - (WINED3DDEVICE_CREATION_PARAMETERS *)pParameters); + (struct wined3d_device_creation_parameters *)pParameters); wined3d_mutex_unlock(); return hr; @@ -467,7 +450,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(IDirect3DDevice8 UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8 *pCursorBitmap) { IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface); - IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap; + IDirect3DSurface8Impl *pSurface = unsafe_impl_from_IDirect3DSurface8(pCursorBitmap); HRESULT hr; TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n", @@ -544,21 +527,19 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(IDirect3DDe return D3D_OK; } -static HRESULT WINAPI reset_enum_callback(struct wined3d_resource *resource, void *data) +static HRESULT CDECL reset_enum_callback(struct wined3d_resource *resource) { struct wined3d_resource_desc desc; - BOOL *resources_ok = data; wined3d_resource_get_desc(resource, &desc); - if (desc.pool == WINED3DPOOL_DEFAULT) + if (desc.pool == WINED3D_POOL_DEFAULT) { IDirect3DSurface8 *surface; - if (desc.resource_type != WINED3DRTYPE_SURFACE) + if (desc.resource_type != WINED3D_RTYPE_SURFACE) { WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource); - *resources_ok = FALSE; - return S_FALSE; + return D3DERR_DEVICELOST; } surface = wined3d_resource_get_parent(resource); @@ -567,68 +548,46 @@ static HRESULT WINAPI reset_enum_callback(struct wined3d_resource *resource, voi if (IDirect3DSurface8_Release(surface)) { WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface, resource); - *resources_ok = FALSE; - return S_FALSE; + return D3DERR_DEVICELOST; } WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface, resource); } - return S_OK; + return D3D_OK; } static HRESULT WINAPI IDirect3DDevice8Impl_Reset(IDirect3DDevice8 *iface, D3DPRESENT_PARAMETERS *pPresentationParameters) { IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface); - WINED3DPRESENT_PARAMETERS localParameters; - BOOL resources_ok = TRUE; + struct wined3d_swapchain_desc swapchain_desc; HRESULT hr; - UINT i; TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters); wined3d_mutex_lock(); - wined3d_device_set_index_buffer(This->wined3d_device, NULL, WINED3DFMT_UNKNOWN); - for (i = 0; i < 16; ++i) - { - wined3d_device_set_stream_source(This->wined3d_device, i, NULL, 0, 0); - } - for (i = 0; i < 16; ++i) - { - wined3d_device_set_texture(This->wined3d_device, i, NULL); - } - wined3d_device_enum_resources(This->wined3d_device, reset_enum_callback, &resources_ok); - if (!resources_ok) - { - WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset.\n"); - This->lost = TRUE; - wined3d_mutex_unlock(); + swapchain_desc.backbuffer_width = pPresentationParameters->BackBufferWidth; + swapchain_desc.backbuffer_height = pPresentationParameters->BackBufferHeight; + swapchain_desc.backbuffer_format = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat); + swapchain_desc.backbuffer_count = pPresentationParameters->BackBufferCount; + swapchain_desc.multisample_type = pPresentationParameters->MultiSampleType; + swapchain_desc.multisample_quality = 0; /* d3d9 only */ + swapchain_desc.swap_effect = pPresentationParameters->SwapEffect; + swapchain_desc.device_window = pPresentationParameters->hDeviceWindow; + swapchain_desc.windowed = pPresentationParameters->Windowed; + swapchain_desc.enable_auto_depth_stencil = pPresentationParameters->EnableAutoDepthStencil; + swapchain_desc.auto_depth_stencil_format = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat); + swapchain_desc.flags = pPresentationParameters->Flags; + swapchain_desc.refresh_rate = pPresentationParameters->FullScreen_RefreshRateInHz; + swapchain_desc.swap_interval = pPresentationParameters->FullScreen_PresentationInterval; + swapchain_desc.auto_restore_display_mode = TRUE; - return D3DERR_DEVICELOST; - } - - localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth; - localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight; - localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat); - localParameters.BackBufferCount = pPresentationParameters->BackBufferCount; - localParameters.MultiSampleType = pPresentationParameters->MultiSampleType; - localParameters.MultiSampleQuality = 0; /* d3d9 only */ - localParameters.SwapEffect = pPresentationParameters->SwapEffect; - localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow; - localParameters.Windowed = pPresentationParameters->Windowed; - localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil; - localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat); - localParameters.Flags = pPresentationParameters->Flags; - localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz; - localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval; - localParameters.AutoRestoreDisplayMode = TRUE; - - hr = wined3d_device_reset(This->wined3d_device, &localParameters); + hr = wined3d_device_reset(This->wined3d_device, &swapchain_desc, reset_enum_callback); if (SUCCEEDED(hr)) { - hr = wined3d_device_set_render_state(This->wined3d_device, WINED3DRS_POINTSIZE_MIN, 0); + hr = wined3d_device_set_render_state(This->wined3d_device, WINED3D_RS_POINTSIZE_MIN, 0); This->lost = FALSE; } else @@ -637,20 +596,6 @@ static HRESULT WINAPI IDirect3DDevice8Impl_Reset(IDirect3DDevice8 *iface, } wined3d_mutex_unlock(); - pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth; - pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight; - pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat); - pPresentationParameters->BackBufferCount = localParameters.BackBufferCount; - pPresentationParameters->MultiSampleType = localParameters.MultiSampleType; - pPresentationParameters->SwapEffect = localParameters.SwapEffect; - pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow; - pPresentationParameters->Windowed = localParameters.Windowed; - pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil; - pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat); - pPresentationParameters->Flags = localParameters.Flags; - pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz; - pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval; - return hr; } @@ -682,7 +627,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(IDirect3DDevice8 *iface wined3d_mutex_lock(); hr = wined3d_device_get_back_buffer(This->wined3d_device, 0, - BackBuffer, (WINED3DBACKBUFFER_TYPE)Type, &wined3d_surface); + BackBuffer, (enum wined3d_backbuffer_type)Type, &wined3d_surface); if (SUCCEEDED(hr) && wined3d_surface && ppBackBuffer) { *ppBackBuffer = wined3d_surface_get_parent(wined3d_surface); @@ -703,7 +648,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(IDirect3DDevice8 *ifa TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus); wined3d_mutex_lock(); - hr = wined3d_device_get_raster_status(This->wined3d_device, 0, (WINED3DRASTER_STATUS *)pRasterStatus); + hr = wined3d_device_get_raster_status(This->wined3d_device, 0, (struct wined3d_raster_status *)pRasterStatus); wined3d_mutex_unlock(); return hr; @@ -716,9 +661,9 @@ static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(IDirect3DDevice8 *iface, DW TRACE("iface %p, flags %#x, ramp %p.\n", iface, Flags, pRamp); - /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */ + /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */ wined3d_mutex_lock(); - wined3d_device_set_gamma_ramp(This->wined3d_device, 0, Flags, (const WINED3DGAMMARAMP *)pRamp); + wined3d_device_set_gamma_ramp(This->wined3d_device, 0, Flags, (const struct wined3d_gamma_ramp *)pRamp); wined3d_mutex_unlock(); } @@ -728,9 +673,9 @@ static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(IDirect3DDevice8 *iface, D3 TRACE("iface %p, ramp %p.\n", iface, pRamp); - /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */ + /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */ wined3d_mutex_lock(); - wined3d_device_get_gamma_ramp(This->wined3d_device, 0, (WINED3DGAMMARAMP *)pRamp); + wined3d_device_get_gamma_ramp(This->wined3d_device, 0, (struct wined3d_gamma_ramp *)pRamp); wined3d_mutex_unlock(); } @@ -855,7 +800,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(IDirect3DDevice8 * } TRACE("Created vertex buffer %p.\n", object); - *buffer = (IDirect3DVertexBuffer8 *)object; + *buffer = &object->IDirect3DVertexBuffer8_iface; return D3D_OK; } @@ -886,7 +831,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8 *i } TRACE("Created index buffer %p.\n", object); - *buffer = (IDirect3DIndexBuffer8 *)object; + *buffer = &object->IDirect3DIndexBuffer8_iface; return D3D_OK; } @@ -921,7 +866,7 @@ static HRESULT IDirect3DDevice8Impl_CreateSurface(IDirect3DDevice8Impl *device, } TRACE("Created surface %p.\n", object); - *ppSurface = (IDirect3DSurface8 *)object; + *ppSurface = &object->IDirect3DSurface8_iface; return D3D_OK; } @@ -981,22 +926,26 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(IDirect3DDevice8 *iface, IDirect3DSurface8 *pSourceSurface, const RECT *pSourceRects, UINT cRects, IDirect3DSurface8 *pDestinationSurface, const POINT *pDestPoints) { - IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface; - IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface; + IDirect3DSurface8Impl *Source = unsafe_impl_from_IDirect3DSurface8(pSourceSurface); + IDirect3DSurface8Impl *Dest = unsafe_impl_from_IDirect3DSurface8(pDestinationSurface); enum wined3d_format_id srcFormat, destFormat; struct wined3d_resource_desc wined3d_desc; struct wined3d_resource *wined3d_resource; + UINT src_w, src_h; + HRESULT hr; TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n", iface, pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints); - /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the - * destination texture is in WINED3DPOOL_DEFAULT. */ + /* Check that the source texture is in WINED3D_POOL_SYSTEM_MEM and the + * destination texture is in WINED3D_POOL_DEFAULT. */ wined3d_mutex_lock(); wined3d_resource = wined3d_surface_get_resource(Source->wined3d_surface); wined3d_resource_get_desc(wined3d_resource, &wined3d_desc); srcFormat = wined3d_desc.format; + src_w = wined3d_desc.width; + src_h = wined3d_desc.height; wined3d_resource = wined3d_surface_get_resource(Dest->wined3d_surface); wined3d_resource_get_desc(wined3d_resource, &wined3d_desc); @@ -1013,14 +962,21 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(IDirect3DDevice8 *iface, else if (WINED3DFMT_UNKNOWN == destFormat) { TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface); - wined3d_surface_set_format(Dest->wined3d_surface, srcFormat); + if (FAILED(hr = wined3d_surface_update_desc(Dest->wined3d_surface, wined3d_desc.width, wined3d_desc.height, + srcFormat, wined3d_desc.multisample_type, wined3d_desc.multisample_quality))) + { + WARN("Failed to update surface desc, hr %#x.\n", hr); + wined3d_mutex_unlock(); + return hr; + } } /* Quick if complete copy ... */ if (!cRects && !pSourceRects && !pDestPoints) { - wined3d_surface_bltfast(Dest->wined3d_surface, 0, 0, - Source->wined3d_surface, NULL, WINEDDBLTFAST_NOCOLORKEY); + RECT rect = {0, 0, src_w, src_h}; + wined3d_surface_blt(Dest->wined3d_surface, &rect, + Source->wined3d_surface, &rect, 0, NULL, WINED3D_TEXF_POINT); } else { @@ -1030,16 +986,25 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(IDirect3DDevice8 *iface, { for (i = 0; i < cRects; ++i) { - wined3d_surface_bltfast(Dest->wined3d_surface, pDestPoints[i].x, pDestPoints[i].y, - Source->wined3d_surface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY); + UINT w = pSourceRects[i].right - pSourceRects[i].left; + UINT h = pSourceRects[i].bottom - pSourceRects[i].top; + RECT dst_rect = {pDestPoints[i].x, pDestPoints[i].y, + pDestPoints[i].x + w, pDestPoints[i].y + h}; + + wined3d_surface_blt(Dest->wined3d_surface, &dst_rect, + Source->wined3d_surface, &pSourceRects[i], 0, NULL, WINED3D_TEXF_POINT); } } else { for (i = 0; i < cRects; ++i) { - wined3d_surface_bltfast(Dest->wined3d_surface, 0, 0, - Source->wined3d_surface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY); + UINT w = pSourceRects[i].right - pSourceRects[i].left; + UINT h = pSourceRects[i].bottom - pSourceRects[i].top; + RECT dst_rect = {0, 0, w, h}; + + wined3d_surface_blt(Dest->wined3d_surface, &dst_rect, + Source->wined3d_surface, &pSourceRects[i], 0, NULL, WINED3D_TEXF_POINT); } } } @@ -1069,7 +1034,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(IDirect3DDevice8 *ifac IDirect3DSurface8 *pDestSurface) { IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface); - IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface; + IDirect3DSurface8Impl *destSurface = unsafe_impl_from_IDirect3DSurface8(pDestSurface); HRESULT hr; TRACE("iface %p, dst_surface %p.\n", iface, pDestSurface); @@ -1090,8 +1055,8 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(IDirect3DDevice8 *ifa IDirect3DSurface8 *pRenderTarget, IDirect3DSurface8 *pNewZStencil) { IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface); - IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget; - IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil; + IDirect3DSurface8Impl *pSurface = unsafe_impl_from_IDirect3DSurface8(pRenderTarget); + IDirect3DSurface8Impl *pZSurface = unsafe_impl_from_IDirect3DSurface8(pNewZStencil); struct wined3d_surface *original_ds = NULL; HRESULT hr; @@ -1103,25 +1068,26 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(IDirect3DDevice8 *ifa { struct wined3d_resource_desc ds_desc, rt_desc; struct wined3d_resource *wined3d_resource; - IDirect3DSurface8 *orig_rt = NULL; + struct wined3d_surface *original_rt = NULL; /* If no render target is passed in check the size against the current RT */ if (!pRenderTarget) { - hr = IDirect3DDevice8_GetRenderTarget(iface, &orig_rt); - if (FAILED(hr)) + hr = wined3d_device_get_render_target(This->wined3d_device, 0, &original_rt); + if (FAILED(hr) || !original_rt) { wined3d_mutex_unlock(); return hr; } - pSurface = (IDirect3DSurface8Impl *)orig_rt; + wined3d_resource = wined3d_surface_get_resource(original_rt); + wined3d_surface_decref(original_rt); } + else + wined3d_resource = wined3d_surface_get_resource(pSurface->wined3d_surface); + wined3d_resource_get_desc(wined3d_resource, &rt_desc); wined3d_resource = wined3d_surface_get_resource(pZSurface->wined3d_surface); wined3d_resource_get_desc(wined3d_resource, &ds_desc); - wined3d_resource = wined3d_surface_get_resource(pSurface->wined3d_surface); - wined3d_resource_get_desc(wined3d_resource, &rt_desc); - if (orig_rt) IDirect3DSurface8_Release(orig_rt); if (ds_desc.width < rt_desc.width || ds_desc.height < rt_desc.height) { @@ -1241,17 +1207,24 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice8Impl_EndScene(IDirect3DD return hr; } -static HRESULT WINAPI IDirect3DDevice8Impl_Clear(IDirect3DDevice8 *iface, DWORD Count, - const D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) +static HRESULT WINAPI IDirect3DDevice8Impl_Clear(IDirect3DDevice8 *iface, DWORD rect_count, + const D3DRECT *rects, DWORD flags, D3DCOLOR color, float z, DWORD stencil) { + const struct wined3d_color c = + { + ((color >> 16) & 0xff) / 255.0f, + ((color >> 8) & 0xff) / 255.0f, + (color & 0xff) / 255.0f, + ((color >> 24) & 0xff) / 255.0f, + }; IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface); HRESULT hr; TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n", - iface, Count, pRects, Flags, Color, Z, Stencil); + iface, rect_count, rects, flags, color, z, stencil); wined3d_mutex_lock(); - hr = wined3d_device_clear(This->wined3d_device, Count, (const RECT *)pRects, Flags, Color, Z, Stencil); + hr = wined3d_device_clear(This->wined3d_device, rect_count, (const RECT *)rects, flags, &c, z, stencil); wined3d_mutex_unlock(); return hr; @@ -1265,9 +1238,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(IDirect3DDevice8 *iface, TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix); - /* Note: D3DMATRIX is compatible with WINED3DMATRIX */ + /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */ wined3d_mutex_lock(); - hr = wined3d_device_set_transform(This->wined3d_device, State, (const WINED3DMATRIX *)lpMatrix); + hr = wined3d_device_set_transform(This->wined3d_device, State, (const struct wined3d_matrix *)lpMatrix); wined3d_mutex_unlock(); return hr; @@ -1281,9 +1254,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(IDirect3DDevice8 *iface, TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix); - /* Note: D3DMATRIX is compatible with WINED3DMATRIX */ + /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */ wined3d_mutex_lock(); - hr = wined3d_device_get_transform(This->wined3d_device, State, (WINED3DMATRIX *)pMatrix); + hr = wined3d_device_get_transform(This->wined3d_device, State, (struct wined3d_matrix *)pMatrix); wined3d_mutex_unlock(); return hr; @@ -1297,9 +1270,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(IDirect3DDevice8 *i TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix); - /* Note: D3DMATRIX is compatible with WINED3DMATRIX */ + /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */ wined3d_mutex_lock(); - hr = wined3d_device_multiply_transform(This->wined3d_device, State, (const WINED3DMATRIX *)pMatrix); + hr = wined3d_device_multiply_transform(This->wined3d_device, State, (const struct wined3d_matrix *)pMatrix); wined3d_mutex_unlock(); return hr; @@ -1313,9 +1286,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(IDirect3DDevice8 *iface, TRACE("iface %p, viewport %p.\n", iface, pViewport); - /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */ + /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */ wined3d_mutex_lock(); - hr = wined3d_device_set_viewport(This->wined3d_device, (const WINED3DVIEWPORT *)pViewport); + hr = wined3d_device_set_viewport(This->wined3d_device, (const struct wined3d_viewport *)pViewport); wined3d_mutex_unlock(); return hr; @@ -1329,9 +1302,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(IDirect3DDevice8 *iface, TRACE("iface %p, viewport %p.\n", iface, pViewport); - /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */ + /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */ wined3d_mutex_lock(); - hr = wined3d_device_get_viewport(This->wined3d_device, (WINED3DVIEWPORT *)pViewport); + hr = wined3d_device_get_viewport(This->wined3d_device, (struct wined3d_viewport *)pViewport); wined3d_mutex_unlock(); return hr; @@ -1345,9 +1318,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(IDirect3DDevice8 *iface, TRACE("iface %p, material %p.\n", iface, pMaterial); - /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */ + /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */ wined3d_mutex_lock(); - hr = wined3d_device_set_material(This->wined3d_device, (const WINED3DMATERIAL *)pMaterial); + hr = wined3d_device_set_material(This->wined3d_device, (const struct wined3d_material *)pMaterial); wined3d_mutex_unlock(); return hr; @@ -1361,9 +1334,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(IDirect3DDevice8 *iface, TRACE("iface %p, material %p.\n", iface, pMaterial); - /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */ + /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */ wined3d_mutex_lock(); - hr = wined3d_device_get_material(This->wined3d_device, (WINED3DMATERIAL *)pMaterial); + hr = wined3d_device_get_material(This->wined3d_device, (struct wined3d_material *)pMaterial); wined3d_mutex_unlock(); return hr; @@ -1377,9 +1350,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(IDirect3DDevice8 *iface, DWO TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight); - /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */ + /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */ wined3d_mutex_lock(); - hr = wined3d_device_set_light(This->wined3d_device, Index, (const WINED3DLIGHT *)pLight); + hr = wined3d_device_set_light(This->wined3d_device, Index, (const struct wined3d_light *)pLight); wined3d_mutex_unlock(); return hr; @@ -1393,9 +1366,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(IDirect3DDevice8 *iface, DWO TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight); - /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */ + /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */ wined3d_mutex_lock(); - hr = wined3d_device_get_light(This->wined3d_device, Index, (WINED3DLIGHT *)pLight); + hr = wined3d_device_get_light(This->wined3d_device, Index, (struct wined3d_light *)pLight); wined3d_mutex_unlock(); return hr; @@ -1461,22 +1434,11 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(IDirect3DDevice8 *iface, return hr; } -/* This factor is the result of a trial-and-error search. Both ZBIAS and DEPTHBIAS require - * guesswork by design. d3d9 apps usually use a DEPTHBIAS of -0.00002(Mass Effect 2, WoW). - * d3d8 apps(Final Fantasy XI) set ZBIAS to 15 and still expect the depth test to sort - * objects properly. */ -static const float zbias_factor = -0.000005f; - static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(IDirect3DDevice8 *iface, D3DRENDERSTATETYPE State, DWORD Value) { IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface); HRESULT hr; - union - { - DWORD d; - float f; - } wined3d_value; TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value); @@ -1484,8 +1446,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(IDirect3DDevice8 *ifac switch (State) { case D3DRS_ZBIAS: - wined3d_value.f = Value * zbias_factor; - hr = wined3d_device_set_render_state(This->wined3d_device, WINED3DRS_DEPTHBIAS, wined3d_value.d); + hr = wined3d_device_set_render_state(This->wined3d_device, WINED3D_RS_DEPTHBIAS, Value); break; default: @@ -1501,11 +1462,6 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(IDirect3DDevice8 *ifac { IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface); HRESULT hr; - union - { - DWORD d; - float f; - } wined3d_value; TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue); @@ -1513,8 +1469,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(IDirect3DDevice8 *ifac switch (State) { case D3DRS_ZBIAS: - hr = wined3d_device_get_render_state(This->wined3d_device, WINED3DRS_DEPTHBIAS, &wined3d_value.d); - if (SUCCEEDED(hr)) *pValue = (DWORD)(wined3d_value.f / zbias_factor); + hr = wined3d_device_get_render_state(This->wined3d_device, WINED3D_RS_DEPTHBIAS, pValue); break; default: @@ -1667,7 +1622,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *if } wined3d_mutex_lock(); - hr = wined3d_stateblock_create(This->wined3d_device, (WINED3DSTATEBLOCKTYPE)Type, &stateblock); + hr = wined3d_stateblock_create(This->wined3d_device, (enum wined3d_stateblock_type)Type, &stateblock); if (FAILED(hr)) { wined3d_mutex_unlock(); @@ -1700,10 +1655,10 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(IDirect3DDevice8 *iface HRESULT hr; TRACE("iface %p, clip_status %p.\n", iface, pClipStatus); -/* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */ + /* FIXME: Verify that D3DCLIPSTATUS8 ~= struct wined3d_clip_status. */ wined3d_mutex_lock(); - hr = wined3d_device_set_clip_status(This->wined3d_device, (const WINED3DCLIPSTATUS *)pClipStatus); + hr = wined3d_device_set_clip_status(This->wined3d_device, (const struct wined3d_clip_status *)pClipStatus); wined3d_mutex_unlock(); return hr; @@ -1718,7 +1673,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(IDirect3DDevice8 *iface TRACE("iface %p, clip_status %p.\n", iface, pClipStatus); wined3d_mutex_lock(); - hr = wined3d_device_get_clip_status(This->wined3d_device, (WINED3DCLIPSTATUS *)pClipStatus); + hr = wined3d_device_get_clip_status(This->wined3d_device, (struct wined3d_clip_status *)pClipStatus); wined3d_mutex_unlock(); return hr; @@ -1781,39 +1736,39 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(IDirect3DDevice8 *iface, D static const struct tss_lookup { BOOL sampler_state; - DWORD state; + enum wined3d_texture_stage_state state; } tss_lookup[] = { - {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */ - {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */ - {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */ - {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */ - {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */ - {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */ - {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */ - {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */ - {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */ - {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */ - {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */ - {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */ - {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */ - {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */ - {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */ - {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */ - {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */ - {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */ - {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */ - {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */ - {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */ - {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */ - {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */ - {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */ - {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */ - {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */ - {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */ - {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */ - {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */ + {FALSE, WINED3D_TSS_INVALID}, /* 0, unused */ + {FALSE, WINED3D_TSS_COLOR_OP}, /* 1, D3DTSS_COLOROP */ + {FALSE, WINED3D_TSS_COLOR_ARG1}, /* 2, D3DTSS_COLORARG1 */ + {FALSE, WINED3D_TSS_COLOR_ARG2}, /* 3, D3DTSS_COLORARG2 */ + {FALSE, WINED3D_TSS_ALPHA_OP}, /* 4, D3DTSS_ALPHAOP */ + {FALSE, WINED3D_TSS_ALPHA_ARG1}, /* 5, D3DTSS_ALPHAARG1 */ + {FALSE, WINED3D_TSS_ALPHA_ARG2}, /* 6, D3DTSS_ALPHAARG2 */ + {FALSE, WINED3D_TSS_BUMPENV_MAT00}, /* 7, D3DTSS_BUMPENVMAT00 */ + {FALSE, WINED3D_TSS_BUMPENV_MAT01}, /* 8, D3DTSS_BUMPENVMAT01 */ + {FALSE, WINED3D_TSS_BUMPENV_MAT10}, /* 9, D3DTSS_BUMPENVMAT10 */ + {FALSE, WINED3D_TSS_BUMPENV_MAT11}, /* 10, D3DTSS_BUMPENVMAT11 */ + {FALSE, WINED3D_TSS_TEXCOORD_INDEX}, /* 11, D3DTSS_TEXCOORDINDEX */ + {FALSE, WINED3D_TSS_INVALID}, /* 12, unused */ + {TRUE, WINED3D_SAMP_ADDRESS_U}, /* 13, D3DTSS_ADDRESSU */ + {TRUE, WINED3D_SAMP_ADDRESS_V}, /* 14, D3DTSS_ADDRESSV */ + {TRUE, WINED3D_SAMP_BORDER_COLOR}, /* 15, D3DTSS_BORDERCOLOR */ + {TRUE, WINED3D_SAMP_MAG_FILTER}, /* 16, D3DTSS_MAGFILTER */ + {TRUE, WINED3D_SAMP_MIN_FILTER}, /* 17, D3DTSS_MINFILTER */ + {TRUE, WINED3D_SAMP_MIP_FILTER}, /* 18, D3DTSS_MIPFILTER */ + {TRUE, WINED3D_SAMP_MIPMAP_LOD_BIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */ + {TRUE, WINED3D_SAMP_MAX_MIP_LEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */ + {TRUE, WINED3D_SAMP_MAX_ANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */ + {FALSE, WINED3D_TSS_BUMPENV_LSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */ + {FALSE, WINED3D_TSS_BUMPENV_LOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */ + {FALSE, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */ + {TRUE, WINED3D_SAMP_ADDRESS_W}, /* 25, D3DTSS_ADDRESSW */ + {FALSE, WINED3D_TSS_COLOR_ARG0}, /* 26, D3DTSS_COLORARG0 */ + {FALSE, WINED3D_TSS_ALPHA_ARG0}, /* 27, D3DTSS_ALPHAARG0 */ + {FALSE, WINED3D_TSS_RESULT_ARG}, /* 28, D3DTSS_RESULTARG */ }; static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(IDirect3DDevice8 *iface, @@ -1896,61 +1851,36 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(IDirect3DDevice8 *iface, static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(IDirect3DDevice8 *iface, UINT PaletteNumber, const PALETTEENTRY *pEntries) { - IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface); - HRESULT hr; + FIXME("iface %p, palette_idx %u, entries %p unimplemented\n", iface, PaletteNumber, pEntries); - TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries); + /* GPUs stopped supporting palettized textures with the Shader Model 1 generation. Wined3d + * does not have a d3d8/9-style palette API */ - wined3d_mutex_lock(); - hr = wined3d_device_set_palette_entries(This->wined3d_device, PaletteNumber, pEntries); - wined3d_mutex_unlock(); - - return hr; + return D3DERR_INVALIDCALL; } static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(IDirect3DDevice8 *iface, UINT PaletteNumber, PALETTEENTRY *pEntries) { - IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface); - HRESULT hr; + FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface, PaletteNumber, pEntries); - TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries); - - wined3d_mutex_lock(); - hr = wined3d_device_get_palette_entries(This->wined3d_device, PaletteNumber, pEntries); - wined3d_mutex_unlock(); - - return hr; + return D3DERR_INVALIDCALL; } static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(IDirect3DDevice8 *iface, UINT PaletteNumber) { - IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface); - HRESULT hr; + FIXME("iface %p, palette_idx %u unimplemented.\n", iface, PaletteNumber); - TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber); - - wined3d_mutex_lock(); - hr = wined3d_device_set_current_texture_palette(This->wined3d_device, PaletteNumber); - wined3d_mutex_unlock(); - - return hr; + return D3DERR_INVALIDCALL; } static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(IDirect3DDevice8 *iface, UINT *PaletteNumber) { - IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface); - HRESULT hr; + FIXME("iface %p, palette_idx %p unimplemented.\n", iface, PaletteNumber); - TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber); - - wined3d_mutex_lock(); - hr = wined3d_device_get_current_texture_palette(This->wined3d_device, PaletteNumber); - wined3d_mutex_unlock(); - - return hr; + return D3DERR_INVALIDCALL; } static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface, @@ -2038,8 +1968,8 @@ static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(IDirect3DDevice8 *ifa DWORD Flags) { IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface); + IDirect3DVertexBuffer8Impl *dest = unsafe_impl_from_IDirect3DVertexBuffer8(pDestBuffer); HRESULT hr; - IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer; TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n", iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, Flags); @@ -2400,8 +2330,8 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(IDirect3DDevice8 *iface, IDirect3DIndexBuffer8 *pIndexData, UINT baseVertexIndex) { IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface); + IDirect3DIndexBuffer8Impl *ib = unsafe_impl_from_IDirect3DIndexBuffer8(pIndexData); HRESULT hr; - IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData; TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface, pIndexData, baseVertexIndex); @@ -2675,7 +2605,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(IDirect3DDevice8 *iface wined3d_mutex_lock(); hr = wined3d_device_draw_rect_patch(This->wined3d_device, Handle, - pNumSegs, (const WINED3DRECTPATCH_INFO *)pRectPatchInfo); + pNumSegs, (const struct wined3d_rect_patch_info *)pRectPatchInfo); wined3d_mutex_unlock(); return hr; @@ -2692,7 +2622,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(IDirect3DDevice8 *iface, wined3d_mutex_lock(); hr = wined3d_device_draw_tri_patch(This->wined3d_device, Handle, - pNumSegs, (const WINED3DTRIPATCH_INFO *)pTriPatchInfo); + pNumSegs, (const struct wined3d_tri_patch_info *)pTriPatchInfo); wined3d_mutex_unlock(); return hr; @@ -2716,6 +2646,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(IDirect3DDevice8 *ifa UINT StreamNumber, IDirect3DVertexBuffer8 *pStreamData, UINT Stride) { IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface); + IDirect3DVertexBuffer8Impl *streamdata = unsafe_impl_from_IDirect3DVertexBuffer8(pStreamData); HRESULT hr; TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n", @@ -2723,8 +2654,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(IDirect3DDevice8 *ifa wined3d_mutex_lock(); hr = wined3d_device_set_stream_source(This->wined3d_device, StreamNumber, - pStreamData ? ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer : NULL, - 0/* Offset in bytes */, Stride); + streamdata ? streamdata->wineD3DVertexBuffer : NULL, 0/* Offset in bytes */, Stride); wined3d_mutex_unlock(); return hr; @@ -2875,9 +2805,14 @@ static void CDECL device_parent_wined3d_device_created(struct wined3d_device_par TRACE("device_parent %p, device %p\n", device_parent, device); } +static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent) +{ + TRACE("device_parent %p.\n", device_parent); +} + static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent *device_parent, void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage, - WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, struct wined3d_surface **surface) + enum wined3d_pool pool, UINT level, enum wined3d_cubemap_face face, struct wined3d_surface **surface) { IDirect3DDevice8Impl *device = device_from_device_parent(device_parent); IDirect3DSurface8Impl *d3d_surface; @@ -2889,7 +2824,8 @@ static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent * device_parent, container_parent, width, height, format, usage, pool, level, face, surface); - if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE; + if (pool == WINED3D_POOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) + lockable = FALSE; hr = IDirect3DDevice8Impl_CreateSurface(device, width, height, d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level, @@ -2907,7 +2843,7 @@ static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent * IUnknown_Release(d3d_surface->parentDevice); d3d_surface->parentDevice = NULL; - IDirect3DSurface8_Release((IDirect3DSurface8 *)d3d_surface); + IDirect3DSurface8_Release(&d3d_surface->IDirect3DSurface8_iface); d3d_surface->forwardReference = container_parent; return hr; @@ -2915,7 +2851,7 @@ static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent * static HRESULT CDECL device_parent_create_rendertarget(struct wined3d_device_parent *device_parent, void *container_parent, UINT width, UINT height, enum wined3d_format_id format, - WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable, + enum wined3d_multisample_type multisample_type, DWORD multisample_quality, BOOL lockable, struct wined3d_surface **surface) { IDirect3DDevice8Impl *device = device_from_device_parent(device_parent); @@ -2940,13 +2876,13 @@ static HRESULT CDECL device_parent_create_rendertarget(struct wined3d_device_par d3d_surface->container = (IUnknown *)&device->IDirect3DDevice8_iface; /* Implicit surfaces are created with an refcount of 0 */ - IUnknown_Release((IUnknown *)d3d_surface); + IDirect3DSurface8_Release(&d3d_surface->IDirect3DSurface8_iface); return hr; } static HRESULT CDECL device_parent_create_depth_stencil(struct wined3d_device_parent *device_parent, - UINT width, UINT height, enum wined3d_format_id format, WINED3DMULTISAMPLE_TYPE multisample_type, + UINT width, UINT height, enum wined3d_format_id format, enum wined3d_multisample_type multisample_type, DWORD multisample_quality, BOOL discard, struct wined3d_surface **surface) { IDirect3DDevice8Impl *device = device_from_device_parent(device_parent); @@ -2970,14 +2906,14 @@ static HRESULT CDECL device_parent_create_depth_stencil(struct wined3d_device_pa d3d_surface->container = (IUnknown *)&device->IDirect3DDevice8_iface; /* Implicit surfaces are created with an refcount of 0 */ - IUnknown_Release((IUnknown *)d3d_surface); + IDirect3DSurface8_Release(&d3d_surface->IDirect3DSurface8_iface); return hr; } static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *device_parent, void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format, - WINED3DPOOL pool, DWORD usage, struct wined3d_volume **volume) + enum wined3d_pool pool, DWORD usage, struct wined3d_volume **volume) { IDirect3DDevice8Impl *device = device_from_device_parent(device_parent); IDirect3DVolume8Impl *object; @@ -3018,29 +2954,29 @@ static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *d } static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent, - WINED3DPRESENT_PARAMETERS *present_parameters, struct wined3d_swapchain **swapchain) + struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain) { IDirect3DDevice8Impl *device = device_from_device_parent(device_parent); D3DPRESENT_PARAMETERS local_parameters; IDirect3DSwapChain8 *d3d_swapchain; HRESULT hr; - TRACE("device_parent %p, present_parameters %p, swapchain %p.\n", device_parent, present_parameters, swapchain); + TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain); /* Copy the presentation parameters */ - local_parameters.BackBufferWidth = present_parameters->BackBufferWidth; - local_parameters.BackBufferHeight = present_parameters->BackBufferHeight; - local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat); - local_parameters.BackBufferCount = present_parameters->BackBufferCount; - local_parameters.MultiSampleType = present_parameters->MultiSampleType; - local_parameters.SwapEffect = present_parameters->SwapEffect; - local_parameters.hDeviceWindow = present_parameters->hDeviceWindow; - local_parameters.Windowed = present_parameters->Windowed; - local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil; - local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat); - local_parameters.Flags = present_parameters->Flags; - local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz; - local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval; + local_parameters.BackBufferWidth = desc->backbuffer_width; + local_parameters.BackBufferHeight = desc->backbuffer_height; + local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(desc->backbuffer_format); + local_parameters.BackBufferCount = desc->backbuffer_count; + local_parameters.MultiSampleType = desc->multisample_type; + local_parameters.SwapEffect = desc->swap_effect; + local_parameters.hDeviceWindow = desc->device_window; + local_parameters.Windowed = desc->windowed; + local_parameters.EnableAutoDepthStencil = desc->enable_auto_depth_stencil; + local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(desc->auto_depth_stencil_format); + local_parameters.Flags = desc->flags; + local_parameters.FullScreen_RefreshRateInHz = desc->refresh_rate; + local_parameters.FullScreen_PresentationInterval = desc->swap_interval; hr = IDirect3DDevice8_CreateAdditionalSwapChain(&device->IDirect3DDevice8_iface, &local_parameters, &d3d_swapchain); @@ -3056,19 +2992,19 @@ static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent IDirect3DSwapChain8_Release(d3d_swapchain); /* Copy back the presentation parameters */ - present_parameters->BackBufferWidth = local_parameters.BackBufferWidth; - present_parameters->BackBufferHeight = local_parameters.BackBufferHeight; - present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat); - present_parameters->BackBufferCount = local_parameters.BackBufferCount; - present_parameters->MultiSampleType = local_parameters.MultiSampleType; - present_parameters->SwapEffect = local_parameters.SwapEffect; - present_parameters->hDeviceWindow = local_parameters.hDeviceWindow; - present_parameters->Windowed = local_parameters.Windowed; - present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil; - present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat); - present_parameters->Flags = local_parameters.Flags; - present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz; - present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval; + desc->backbuffer_width = local_parameters.BackBufferWidth; + desc->backbuffer_height = local_parameters.BackBufferHeight; + desc->backbuffer_format = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat); + desc->backbuffer_count = local_parameters.BackBufferCount; + desc->multisample_type = local_parameters.MultiSampleType; + desc->swap_effect = local_parameters.SwapEffect; + desc->device_window = local_parameters.hDeviceWindow; + desc->windowed = local_parameters.Windowed; + desc->enable_auto_depth_stencil = local_parameters.EnableAutoDepthStencil; + desc->auto_depth_stencil_format = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat); + desc->flags = local_parameters.Flags; + desc->refresh_rate = local_parameters.FullScreen_RefreshRateInHz; + desc->swap_interval = local_parameters.FullScreen_PresentationInterval; return hr; } @@ -3076,6 +3012,7 @@ static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent static const struct wined3d_device_parent_ops d3d8_wined3d_device_parent_ops = { device_parent_wined3d_device_created, + device_parent_mode_changed, device_parent_create_surface, device_parent_create_rendertarget, device_parent_create_depth_stencil, @@ -3090,15 +3027,20 @@ static void setup_fpu(void) __asm__ volatile ("fnstcw %0" : "=m" (cw)); cw = (cw & ~0xf3f) | 0x3f; __asm__ volatile ("fldcw %0" : : "m" (cw)); +#elif defined(__i386__) && defined(_MSC_VER) + WORD cw; + __asm fnstcw cw; + cw = (cw & ~0xf3f) | 0x3f; + __asm fldcw cw; #else FIXME("FPU setup not implemented for this platform.\n"); #endif } -HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT adapter, +HRESULT device_init(IDirect3DDevice8Impl *device, IDirect3D8Impl *parent, struct wined3d *wined3d, UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters) { - WINED3DPRESENT_PARAMETERS wined3d_parameters; + struct wined3d_swapchain_desc swapchain_desc; HRESULT hr; device->IDirect3DDevice8_iface.lpVtbl = &Direct3DDevice8_Vtbl; @@ -3116,7 +3058,7 @@ HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu(); wined3d_mutex_lock(); - hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags, + hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags, 4, &device->device_parent, &device->wined3d_device); if (FAILED(hr)) { @@ -3151,23 +3093,23 @@ HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT if (flags & D3DCREATE_MULTITHREADED) wined3d_device_set_multithreaded(device->wined3d_device); - wined3d_parameters.BackBufferWidth = parameters->BackBufferWidth; - wined3d_parameters.BackBufferHeight = parameters->BackBufferHeight; - wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(parameters->BackBufferFormat); - wined3d_parameters.BackBufferCount = parameters->BackBufferCount; - wined3d_parameters.MultiSampleType = parameters->MultiSampleType; - wined3d_parameters.MultiSampleQuality = 0; /* d3d9 only */ - wined3d_parameters.SwapEffect = parameters->SwapEffect; - wined3d_parameters.hDeviceWindow = parameters->hDeviceWindow; - wined3d_parameters.Windowed = parameters->Windowed; - wined3d_parameters.EnableAutoDepthStencil = parameters->EnableAutoDepthStencil; - wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(parameters->AutoDepthStencilFormat); - wined3d_parameters.Flags = parameters->Flags; - wined3d_parameters.FullScreen_RefreshRateInHz = parameters->FullScreen_RefreshRateInHz; - wined3d_parameters.PresentationInterval = parameters->FullScreen_PresentationInterval; - wined3d_parameters.AutoRestoreDisplayMode = TRUE; + swapchain_desc.backbuffer_width = parameters->BackBufferWidth; + swapchain_desc.backbuffer_height = parameters->BackBufferHeight; + swapchain_desc.backbuffer_format = wined3dformat_from_d3dformat(parameters->BackBufferFormat); + swapchain_desc.backbuffer_count = parameters->BackBufferCount; + swapchain_desc.multisample_type = parameters->MultiSampleType; + swapchain_desc.multisample_quality = 0; /* d3d9 only */ + swapchain_desc.swap_effect = parameters->SwapEffect; + swapchain_desc.device_window = parameters->hDeviceWindow; + swapchain_desc.windowed = parameters->Windowed; + swapchain_desc.enable_auto_depth_stencil = parameters->EnableAutoDepthStencil; + swapchain_desc.auto_depth_stencil_format = wined3dformat_from_d3dformat(parameters->AutoDepthStencilFormat); + swapchain_desc.flags = parameters->Flags; + swapchain_desc.refresh_rate = parameters->FullScreen_RefreshRateInHz; + swapchain_desc.swap_interval = parameters->FullScreen_PresentationInterval; + swapchain_desc.auto_restore_display_mode = TRUE; - hr = wined3d_device_init_3d(device->wined3d_device, &wined3d_parameters); + hr = wined3d_device_init_3d(device->wined3d_device, &swapchain_desc); if (FAILED(hr)) { WARN("Failed to initialize 3D, hr %#x.\n", hr); @@ -3178,7 +3120,7 @@ HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT return hr; } - hr = wined3d_device_set_render_state(device->wined3d_device, WINED3DRS_POINTSIZE_MIN, 0); + hr = wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_POINTSIZE_MIN, 0); wined3d_mutex_unlock(); if (FAILED(hr)) { @@ -3186,29 +3128,32 @@ HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT goto err; } - parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth; - parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight; - parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat); - parameters->BackBufferCount = wined3d_parameters.BackBufferCount; - parameters->MultiSampleType = wined3d_parameters.MultiSampleType; - parameters->SwapEffect = wined3d_parameters.SwapEffect; - parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow; - parameters->Windowed = wined3d_parameters.Windowed; - parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil; - parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat); - parameters->Flags = wined3d_parameters.Flags; - parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz; - parameters->FullScreen_PresentationInterval = wined3d_parameters.PresentationInterval; + parameters->BackBufferWidth = swapchain_desc.backbuffer_width; + parameters->BackBufferHeight = swapchain_desc.backbuffer_height; + parameters->BackBufferFormat = d3dformat_from_wined3dformat(swapchain_desc.backbuffer_format); + parameters->BackBufferCount = swapchain_desc.backbuffer_count; + parameters->MultiSampleType = swapchain_desc.multisample_type; + parameters->SwapEffect = swapchain_desc.swap_effect; + parameters->hDeviceWindow = swapchain_desc.device_window; + parameters->Windowed = swapchain_desc.windowed; + parameters->EnableAutoDepthStencil = swapchain_desc.enable_auto_depth_stencil; + parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(swapchain_desc.auto_depth_stencil_format); + parameters->Flags = swapchain_desc.flags; + parameters->FullScreen_RefreshRateInHz = swapchain_desc.refresh_rate; + parameters->FullScreen_PresentationInterval = swapchain_desc.swap_interval; device->declArraySize = 16; device->decls = HeapAlloc(GetProcessHeap(), 0, device->declArraySize * sizeof(*device->decls)); if (!device->decls) { - ERR("Failed to allocate FVF vertex delcaration map memory.\n"); + ERR("Failed to allocate FVF vertex declaration map memory.\n"); hr = E_OUTOFMEMORY; goto err; } + device->d3d_parent = &parent->IDirect3D8_iface; + IDirect3D8_AddRef(device->d3d_parent); + return D3D_OK; err: diff --git a/reactos/dll/directx/wine/d3d8/directx.c b/reactos/dll/directx/wine/d3d8/directx.c index 249399e8452..0bb3b01c886 100644 --- a/reactos/dll/directx/wine/d3d8/directx.c +++ b/reactos/dll/directx/wine/d3d8/directx.c @@ -123,7 +123,7 @@ static HRESULT WINAPI IDirect3D8Impl_GetAdapterIdentifier(LPDIRECT3D8 iface, UIN DWORD Flags, D3DADAPTER_IDENTIFIER8 *pIdentifier) { IDirect3D8Impl *This = impl_from_IDirect3D8(iface); - WINED3DADAPTER_IDENTIFIER adapter_id; + struct wined3d_adapter_identifier adapter_id; HRESULT hr; TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n", @@ -175,7 +175,8 @@ static HRESULT WINAPI IDirect3D8Impl_EnumAdapterModes(LPDIRECT3D8 iface, UINT Ad iface, Adapter, Mode, pMode); wined3d_mutex_lock(); - hr = wined3d_enum_adapter_modes(This->WineD3D, Adapter, WINED3DFMT_UNKNOWN, Mode, (WINED3DDISPLAYMODE *)pMode); + hr = wined3d_enum_adapter_modes(This->WineD3D, Adapter, WINED3DFMT_UNKNOWN, + Mode, (struct wined3d_display_mode *)pMode); wined3d_mutex_unlock(); if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format); @@ -193,7 +194,7 @@ static HRESULT WINAPI IDirect3D8Impl_GetAdapterDisplayMode(LPDIRECT3D8 iface, UI iface, Adapter, pMode); wined3d_mutex_lock(); - hr = wined3d_get_adapter_display_mode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *)pMode); + hr = wined3d_get_adapter_display_mode(This->WineD3D, Adapter, (struct wined3d_display_mode *)pMode); wined3d_mutex_unlock(); if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format); @@ -223,34 +224,26 @@ static HRESULT WINAPI IDirect3D8Impl_CheckDeviceFormat(LPDIRECT3D8 iface, UINT A D3DFORMAT CheckFormat) { IDirect3D8Impl *This = impl_from_IDirect3D8(iface); + enum wined3d_resource_type wined3d_rtype; HRESULT hr; - WINED3DRESOURCETYPE WineD3DRType; TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n", iface, Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat); - if(CheckFormat == D3DFMT_R8G8B8) - { - /* See comment in dlls/d3d9/directx.c, IDirect3D9Impl_CheckDeviceFormat for details */ - WARN("D3DFMT_R8G8B8 is not available on windows, returning D3DERR_NOTAVAILABLE\n"); - return D3DERR_NOTAVAILABLE; - } - - switch(RType) { case D3DRTYPE_VERTEXBUFFER: case D3DRTYPE_INDEXBUFFER: - WineD3DRType = WINED3DRTYPE_BUFFER; + wined3d_rtype = WINED3D_RTYPE_BUFFER; break; default: - WineD3DRType = RType; + wined3d_rtype = RType; break; } wined3d_mutex_lock(); hr = wined3d_check_device_format(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat), - Usage, WineD3DRType, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL); + Usage, wined3d_rtype, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL); wined3d_mutex_unlock(); return hr; @@ -268,7 +261,8 @@ static HRESULT WINAPI IDirect3D8Impl_CheckDeviceMultiSampleType(IDirect3D8 *ifac wined3d_mutex_lock(); hr = wined3d_check_device_multisample_type(This->WineD3D, Adapter, DeviceType, - wined3dformat_from_d3dformat(SurfaceFormat), Windowed, (WINED3DMULTISAMPLE_TYPE)MultiSampleType, NULL); + wined3dformat_from_d3dformat(SurfaceFormat), Windowed, + (enum wined3d_multisample_type)MultiSampleType, NULL); wined3d_mutex_unlock(); return hr; @@ -296,12 +290,14 @@ static HRESULT WINAPI IDirect3D8Impl_CheckDepthStencilMatch(IDirect3D8 *iface, U void fixup_caps(WINED3DCAPS *caps) { /* D3D8 doesn't support SM 2.0 or higher, so clamp to 1.x */ - if (caps->PixelShaderVersion > D3DPS_VERSION(1,4)) { + if (caps->PixelShaderVersion) caps->PixelShaderVersion = D3DPS_VERSION(1,4); - } - if (caps->VertexShaderVersion > D3DVS_VERSION(1,1)) { + else + caps->PixelShaderVersion = D3DPS_VERSION(0,0); + if (caps->VertexShaderVersion) caps->VertexShaderVersion = D3DVS_VERSION(1,1); - } + else + caps->VertexShaderVersion = D3DVS_VERSION(0,0); caps->MaxVertexShaderConst = min(D3D8_MAX_VERTEX_SHADER_CONSTANTF, caps->MaxVertexShaderConst); caps->StencilCaps &= ~WINED3DSTENCILCAPS_TWOSIDED; @@ -368,7 +364,7 @@ static HRESULT WINAPI IDirect3D8Impl_CreateDevice(IDirect3D8 *iface, UINT adapte return E_OUTOFMEMORY; } - hr = device_init(object, This->WineD3D, adapter, device_type, focus_window, flags, parameters); + hr = device_init(object, This, This->WineD3D, adapter, device_type, focus_window, flags, parameters); if (FAILED(hr)) { WARN("Failed to initialize device, hr %#x.\n", hr); diff --git a/reactos/dll/directx/wine/d3d8/shader.c b/reactos/dll/directx/wine/d3d8/shader.c index e04c2a2960f..e7a0389bb0e 100644 --- a/reactos/dll/directx/wine/d3d8/shader.c +++ b/reactos/dll/directx/wine/d3d8/shader.c @@ -177,7 +177,7 @@ HRESULT vertexshader_init(IDirect3DVertexShader8Impl *shader, IDirect3DDevice8Im wined3d_mutex_lock(); hr = wined3d_shader_create_vs(device->wined3d_device, byte_code, NULL /* output signature */, - shader, &d3d8_vertexshader_wined3d_parent_ops, &shader->wined3d_shader); + shader, &d3d8_vertexshader_wined3d_parent_ops, &shader->wined3d_shader, 1); wined3d_mutex_unlock(); if (FAILED(hr)) { @@ -278,7 +278,7 @@ HRESULT pixelshader_init(IDirect3DPixelShader8Impl *shader, IDirect3DDevice8Impl wined3d_mutex_lock(); hr = wined3d_shader_create_ps(device->wined3d_device, byte_code, NULL, shader, - &d3d8_pixelshader_wined3d_parent_ops, &shader->wined3d_shader); + &d3d8_pixelshader_wined3d_parent_ops, &shader->wined3d_shader, 1); wined3d_mutex_unlock(); if (FAILED(hr)) { diff --git a/reactos/dll/directx/wine/d3d8/surface.c b/reactos/dll/directx/wine/d3d8/surface.c index 8a07244e604..bfeae339b45 100644 --- a/reactos/dll/directx/wine/d3d8/surface.c +++ b/reactos/dll/directx/wine/d3d8/surface.c @@ -19,13 +19,21 @@ */ #include "config.h" +#include #include "d3d8_private.h" WINE_DEFAULT_DEBUG_CHANNEL(d3d8); +static inline IDirect3DSurface8Impl *impl_from_IDirect3DSurface8(IDirect3DSurface8 *iface) +{ + return CONTAINING_RECORD(iface, IDirect3DSurface8Impl, IDirect3DSurface8_iface); +} + /* IDirect3DSurface8 IUnknown parts follow: */ -static HRESULT WINAPI IDirect3DSurface8Impl_QueryInterface(LPDIRECT3DSURFACE8 iface, REFIID riid, LPVOID *ppobj) { - IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface; +static HRESULT WINAPI IDirect3DSurface8Impl_QueryInterface(IDirect3DSurface8 *iface, REFIID riid, + void **ppobj) +{ + IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj); @@ -42,8 +50,9 @@ static HRESULT WINAPI IDirect3DSurface8Impl_QueryInterface(LPDIRECT3DSURFACE8 if return E_NOINTERFACE; } -static ULONG WINAPI IDirect3DSurface8Impl_AddRef(LPDIRECT3DSURFACE8 iface) { - IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface; +static ULONG WINAPI IDirect3DSurface8Impl_AddRef(IDirect3DSurface8 *iface) +{ + IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); TRACE("iface %p.\n", iface); @@ -69,8 +78,9 @@ static ULONG WINAPI IDirect3DSurface8Impl_AddRef(LPDIRECT3DSURFACE8 iface) { } } -static ULONG WINAPI IDirect3DSurface8Impl_Release(LPDIRECT3DSURFACE8 iface) { - IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface; +static ULONG WINAPI IDirect3DSurface8Impl_Release(IDirect3DSurface8 *iface) +{ + IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); TRACE("iface %p.\n", iface); @@ -100,9 +110,10 @@ static ULONG WINAPI IDirect3DSurface8Impl_Release(LPDIRECT3DSURFACE8 iface) { } /* IDirect3DSurface8 IDirect3DResource8 Interface follow: */ -static HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(IDirect3DSurface8 *iface, IDirect3DDevice8 **device) +static HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(IDirect3DSurface8 *iface, + IDirect3DDevice8 **device) { - IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface; + IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); TRACE("iface %p, device %p.\n", iface, device); @@ -123,7 +134,7 @@ static HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(IDirect3DSurface8 *iface, return hr; } - *device = (IDirect3DDevice8 *)This->parentDevice; + *device = This->parentDevice; IDirect3DDevice8_AddRef(*device); TRACE("Returning device %p.\n", *device); @@ -131,50 +142,63 @@ static HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(IDirect3DSurface8 *iface, return D3D_OK; } -static HRESULT WINAPI IDirect3DSurface8Impl_SetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) { - IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface; +static HRESULT WINAPI IDirect3DSurface8Impl_SetPrivateData(IDirect3DSurface8 *iface, REFGUID guid, + const void *data, DWORD data_size, DWORD flags) +{ + IDirect3DSurface8Impl *surface = impl_from_IDirect3DSurface8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", - iface, debugstr_guid(refguid), pData, SizeOfData, Flags); + iface, debugstr_guid(guid), data, data_size, flags); wined3d_mutex_lock(); - hr = wined3d_surface_set_private_data(This->wined3d_surface, refguid, pData, SizeOfData, Flags); + resource = wined3d_surface_get_resource(surface->wined3d_surface); + hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags); wined3d_mutex_unlock(); return hr; } -static HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) { - IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface; +static HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(IDirect3DSurface8 *iface, REFGUID guid, + void *data, DWORD *data_size) +{ + IDirect3DSurface8Impl *surface = impl_from_IDirect3DSurface8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %p.\n", - iface, debugstr_guid(refguid), pData, pSizeOfData); + iface, debugstr_guid(guid), data, data_size); wined3d_mutex_lock(); - hr = wined3d_surface_get_private_data(This->wined3d_surface, refguid, pData, pSizeOfData); + resource = wined3d_surface_get_resource(surface->wined3d_surface); + hr = wined3d_resource_get_private_data(resource, guid, data, data_size); wined3d_mutex_unlock(); return hr; } -static HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid) { - IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface; +static HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(IDirect3DSurface8 *iface, REFGUID guid) +{ + IDirect3DSurface8Impl *surface = impl_from_IDirect3DSurface8(iface); + struct wined3d_resource *resource; HRESULT hr; - TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid)); + TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid)); wined3d_mutex_lock(); - hr = wined3d_surface_free_private_data(This->wined3d_surface, refguid); + resource = wined3d_surface_get_resource(surface->wined3d_surface); + hr = wined3d_resource_free_private_data(resource, guid); wined3d_mutex_unlock(); return hr; } /* IDirect3DSurface8 Interface follow: */ -static HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 iface, REFIID riid, void **ppContainer) { - IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface; +static HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(IDirect3DSurface8 *iface, REFIID riid, + void **ppContainer) +{ + IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); HRESULT res; TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), ppContainer); @@ -189,7 +213,7 @@ static HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 ifac static HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(IDirect3DSurface8 *iface, D3DSURFACE_DESC *desc) { - IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface; + IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); struct wined3d_resource_desc wined3d_desc; struct wined3d_resource *wined3d_resource; @@ -202,7 +226,7 @@ static HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(IDirect3DSurface8 *iface, D3 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format); desc->Type = wined3d_desc.resource_type; - desc->Usage = wined3d_desc.usage; + desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->Size = wined3d_desc.size; desc->MultiSampleType = wined3d_desc.multisample_type; @@ -212,8 +236,10 @@ static HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(IDirect3DSurface8 *iface, D3 return D3D_OK; } -static HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, DWORD Flags) { - IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface; +static HRESULT WINAPI IDirect3DSurface8Impl_LockRect(IDirect3DSurface8 *iface, + D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags) +{ + IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); HRESULT hr; TRACE("iface %p, locked_rect %p, rect %p, flags %#x.\n", iface, pLockedRect, pRect, Flags); @@ -236,14 +262,15 @@ static HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D } } - hr = wined3d_surface_map(This->wined3d_surface, (WINED3DLOCKED_RECT *)pLockedRect, pRect, Flags); + hr = wined3d_surface_map(This->wined3d_surface, (struct wined3d_mapped_rect *)pLockedRect, pRect, Flags); wined3d_mutex_unlock(); return hr; } -static HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface) { - IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface; +static HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(IDirect3DSurface8 *iface) +{ + IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); HRESULT hr; TRACE("iface %p.\n", iface); @@ -291,9 +318,10 @@ HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *devic UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level, DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality) { + DWORD flags = 0; HRESULT hr; - surface->lpVtbl = &Direct3DSurface8_Vtbl; + surface->IDirect3DSurface8_iface.lpVtbl = &Direct3DSurface8_Vtbl; surface->ref = 1; /* FIXME: Check MAX bounds of MultisampleQuality. */ @@ -303,10 +331,15 @@ HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *devic multisample_quality = 0; } + if (lockable) + flags |= WINED3D_SURFACE_MAPPABLE; + if (discard) + flags |= WINED3D_SURFACE_DISCARD; + wined3d_mutex_lock(); hr = wined3d_surface_create(device->wined3d_device, width, height, wined3dformat_from_d3dformat(format), - lockable, discard, level, usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, multisample_type, - multisample_quality, SURFACE_OPENGL, surface, &d3d8_surface_wined3d_parent_ops, &surface->wined3d_surface); + level, usage & WINED3DUSAGE_MASK, (enum wined3d_pool)pool, multisample_type, multisample_quality, + SURFACE_OPENGL, flags, surface, &d3d8_surface_wined3d_parent_ops, &surface->wined3d_surface); wined3d_mutex_unlock(); if (FAILED(hr)) { @@ -319,3 +352,12 @@ HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *devic return D3D_OK; } + +IDirect3DSurface8Impl *unsafe_impl_from_IDirect3DSurface8(IDirect3DSurface8 *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &Direct3DSurface8_Vtbl); + + return impl_from_IDirect3DSurface8(iface); +} diff --git a/reactos/dll/directx/wine/d3d8/swapchain.c b/reactos/dll/directx/wine/d3d8/swapchain.c index 866335fcdc8..5ed5c6095a6 100644 --- a/reactos/dll/directx/wine/d3d8/swapchain.c +++ b/reactos/dll/directx/wine/d3d8/swapchain.c @@ -117,7 +117,7 @@ static HRESULT WINAPI IDirect3DSwapChain8Impl_GetBackBuffer(IDirect3DSwapChain8 wined3d_mutex_lock(); hr = wined3d_swapchain_get_back_buffer(This->wined3d_swapchain, - iBackBuffer, (WINED3DBACKBUFFER_TYPE)Type, &wined3d_surface); + iBackBuffer, (enum wined3d_backbuffer_type)Type, &wined3d_surface); if (SUCCEEDED(hr) && wined3d_surface) { *ppBackBuffer = wined3d_surface_get_parent(wined3d_surface); @@ -151,47 +151,47 @@ static const struct wined3d_parent_ops d3d8_swapchain_wined3d_parent_ops = HRESULT swapchain_init(IDirect3DSwapChain8Impl *swapchain, IDirect3DDevice8Impl *device, D3DPRESENT_PARAMETERS *present_parameters) { - WINED3DPRESENT_PARAMETERS wined3d_parameters; + struct wined3d_swapchain_desc desc; HRESULT hr; swapchain->ref = 1; swapchain->IDirect3DSwapChain8_iface.lpVtbl = &Direct3DSwapChain8_Vtbl; - wined3d_parameters.BackBufferWidth = present_parameters->BackBufferWidth; - wined3d_parameters.BackBufferHeight = present_parameters->BackBufferHeight; - wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat); - wined3d_parameters.BackBufferCount = max(1, present_parameters->BackBufferCount); - wined3d_parameters.MultiSampleType = present_parameters->MultiSampleType; - wined3d_parameters.MultiSampleQuality = 0; /* d3d9 only */ - wined3d_parameters.SwapEffect = present_parameters->SwapEffect; - wined3d_parameters.hDeviceWindow = present_parameters->hDeviceWindow; - wined3d_parameters.Windowed = present_parameters->Windowed; - wined3d_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil; - wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat); - wined3d_parameters.Flags = present_parameters->Flags; - wined3d_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz; - wined3d_parameters.PresentationInterval = present_parameters->FullScreen_PresentationInterval; - wined3d_parameters.AutoRestoreDisplayMode = TRUE; + desc.backbuffer_width = present_parameters->BackBufferWidth; + desc.backbuffer_height = present_parameters->BackBufferHeight; + desc.backbuffer_format = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat); + desc.backbuffer_count = max(1, present_parameters->BackBufferCount); + desc.multisample_type = present_parameters->MultiSampleType; + desc.multisample_quality = 0; /* d3d9 only */ + desc.swap_effect = present_parameters->SwapEffect; + desc.device_window = present_parameters->hDeviceWindow; + desc.windowed = present_parameters->Windowed; + desc.enable_auto_depth_stencil = present_parameters->EnableAutoDepthStencil; + desc.auto_depth_stencil_format = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat); + desc.flags = present_parameters->Flags; + desc.refresh_rate = present_parameters->FullScreen_RefreshRateInHz; + desc.swap_interval = present_parameters->FullScreen_PresentationInterval; + desc.auto_restore_display_mode = TRUE; wined3d_mutex_lock(); - hr = wined3d_swapchain_create(device->wined3d_device, &wined3d_parameters, + hr = wined3d_swapchain_create(device->wined3d_device, &desc, SURFACE_OPENGL, swapchain, &d3d8_swapchain_wined3d_parent_ops, &swapchain->wined3d_swapchain); wined3d_mutex_unlock(); - present_parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth; - present_parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight; - present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat); - present_parameters->BackBufferCount = wined3d_parameters.BackBufferCount; - present_parameters->MultiSampleType = wined3d_parameters.MultiSampleType; - present_parameters->SwapEffect = wined3d_parameters.SwapEffect; - present_parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow; - present_parameters->Windowed = wined3d_parameters.Windowed; - present_parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil; - present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat); - present_parameters->Flags = wined3d_parameters.Flags; - present_parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz; - present_parameters->FullScreen_PresentationInterval = wined3d_parameters.PresentationInterval; + present_parameters->BackBufferWidth = desc.backbuffer_width; + present_parameters->BackBufferHeight = desc.backbuffer_height; + present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(desc.backbuffer_format); + present_parameters->BackBufferCount = desc.backbuffer_count; + present_parameters->MultiSampleType = desc.multisample_type; + present_parameters->SwapEffect = desc.swap_effect; + present_parameters->hDeviceWindow = desc.device_window; + present_parameters->Windowed = desc.windowed; + present_parameters->EnableAutoDepthStencil = desc.enable_auto_depth_stencil; + present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(desc.auto_depth_stencil_format); + present_parameters->Flags = desc.flags; + present_parameters->FullScreen_RefreshRateInHz = desc.refresh_rate; + present_parameters->FullScreen_PresentationInterval = desc.swap_interval; if (FAILED(hr)) { diff --git a/reactos/dll/directx/wine/d3d8/texture.c b/reactos/dll/directx/wine/d3d8/texture.c index 1b9db9d2303..f3f2b20815e 100644 --- a/reactos/dll/directx/wine/d3d8/texture.c +++ b/reactos/dll/directx/wine/d3d8/texture.c @@ -96,7 +96,7 @@ static HRESULT WINAPI IDirect3DTexture8Impl_GetDevice(IDirect3DTexture8 *iface, TRACE("iface %p, device %p.\n", iface, device); - *device = (IDirect3DDevice8 *)This->parentDevice; + *device = This->parentDevice; IDirect3DDevice8_AddRef(*device); TRACE("Returning device %p.\n", *device); @@ -108,13 +108,15 @@ static HRESULT WINAPI IDirect3DTexture8Impl_SetPrivateData(IDirect3DTexture8 *if REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) { IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", iface, debugstr_guid(refguid), pData, SizeOfData, Flags); wined3d_mutex_lock(); - hr = wined3d_texture_set_private_data(This->wined3d_texture, refguid, pData, SizeOfData, Flags); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags); wined3d_mutex_unlock(); return hr; @@ -124,13 +126,15 @@ static HRESULT WINAPI IDirect3DTexture8Impl_GetPrivateData(IDirect3DTexture8 *if REFGUID refguid, void *pData, DWORD *pSizeOfData) { IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %p.\n", iface, debugstr_guid(refguid), pData, pSizeOfData); wined3d_mutex_lock(); - hr = wined3d_texture_get_private_data(This->wined3d_texture, refguid, pData, pSizeOfData); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData); wined3d_mutex_unlock(); return hr; @@ -140,12 +144,14 @@ static HRESULT WINAPI IDirect3DTexture8Impl_FreePrivateData(IDirect3DTexture8 *i REFGUID refguid) { IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid)); wined3d_mutex_lock(); - hr = wined3d_texture_free_private_data(This->wined3d_texture, refguid); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_free_private_data(resource, refguid); wined3d_mutex_unlock(); return hr; @@ -192,16 +198,9 @@ static void WINAPI IDirect3DTexture8Impl_PreLoad(IDirect3DTexture8 *iface) static D3DRESOURCETYPE WINAPI IDirect3DTexture8Impl_GetType(IDirect3DTexture8 *iface) { - IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface); - D3DRESOURCETYPE type; - TRACE("iface %p.\n", iface); - wined3d_mutex_lock(); - type = wined3d_texture_get_type(This->wined3d_texture); - wined3d_mutex_unlock(); - - return type; + return D3DRTYPE_TEXTURE; } /* IDirect3DTexture8 IDirect3DBaseTexture8 Interface follow: */ @@ -266,7 +265,7 @@ static HRESULT WINAPI IDirect3DTexture8Impl_GetLevelDesc(IDirect3DTexture8 *ifac wined3d_resource_get_desc(sub_resource, &wined3d_desc); desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format); desc->Type = wined3d_desc.resource_type; - desc->Usage = wined3d_desc.usage; + desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->Size = wined3d_desc.size; desc->MultiSampleType = wined3d_desc.multisample_type; @@ -352,14 +351,14 @@ static HRESULT WINAPI IDirect3DTexture8Impl_AddDirtyRect(IDirect3DTexture8 *ifac hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, NULL); else { - WINED3DBOX dirty_region; + struct wined3d_box dirty_region; - dirty_region.Left = dirty_rect->left; - dirty_region.Top = dirty_rect->top; - dirty_region.Right = dirty_rect->right; - dirty_region.Bottom = dirty_rect->bottom; - dirty_region.Front = 0; - dirty_region.Back = 1; + dirty_region.left = dirty_rect->left; + dirty_region.top = dirty_rect->top; + dirty_region.right = dirty_rect->right; + dirty_region.bottom = dirty_rect->bottom; + dirty_region.front = 0; + dirty_region.back = 1; hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, &dirty_region); } wined3d_mutex_unlock(); diff --git a/reactos/dll/directx/wine/d3d8/vertexdeclaration.c b/reactos/dll/directx/wine/d3d8/vertexdeclaration.c index 78a59d11ad5..7ca8783a559 100644 --- a/reactos/dll/directx/wine/d3d8/vertexdeclaration.c +++ b/reactos/dll/directx/wine/d3d8/vertexdeclaration.c @@ -193,7 +193,7 @@ size_t parse_token(const DWORD* pToken) default: TRACE(" 0x%08x UNKNOWN\n", token); - /* argg error */ + /* arg error */ } return tokenlen; @@ -303,10 +303,10 @@ static const wined3d_usage_t wined3d_usage_lookup[] = { /* TODO: find out where rhw (or positionT) is for declaration8 */ static UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3d8_elements_size, - WINED3DVERTEXELEMENT **wined3d_elements) + struct wined3d_vertex_element **wined3d_elements) { + struct wined3d_vertex_element *element; const DWORD *token = d3d8_elements; - WINED3DVERTEXELEMENT *element; D3DVSD_TOKENTYPE token_type; unsigned int element_count = 0; WORD stream = 0; @@ -315,7 +315,7 @@ static UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3 TRACE("d3d8_elements %p, wined3d_elements %p\n", d3d8_elements, wined3d_elements); /* 128 should be enough for anyone... */ - *wined3d_elements = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 128 * sizeof(WINED3DVERTEXELEMENT)); + *wined3d_elements = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 128 * sizeof(**wined3d_elements)); while (D3DVSD_END() != *token) { token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT); @@ -380,7 +380,7 @@ static const struct wined3d_parent_ops d3d8_vertexdeclaration_wined3d_parent_ops HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration, IDirect3DDevice8Impl *device, const DWORD *elements, DWORD shader_handle) { - WINED3DVERTEXELEMENT *wined3d_elements; + struct wined3d_vertex_element *wined3d_elements; UINT wined3d_element_count; HRESULT hr; diff --git a/reactos/dll/directx/wine/d3d8/volume.c b/reactos/dll/directx/wine/d3d8/volume.c index 2726880aa83..0e009ee51bd 100644 --- a/reactos/dll/directx/wine/d3d8/volume.c +++ b/reactos/dll/directx/wine/d3d8/volume.c @@ -126,13 +126,15 @@ static HRESULT WINAPI IDirect3DVolume8Impl_SetPrivateData(IDirect3DVolume8 *ifac const void *pData, DWORD SizeOfData, DWORD Flags) { IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", iface, debugstr_guid(refguid), pData, SizeOfData, Flags); wined3d_mutex_lock(); - hr = wined3d_volume_set_private_data(This->wined3d_volume, refguid, pData, SizeOfData, Flags); + resource = wined3d_volume_get_resource(This->wined3d_volume); + hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags); wined3d_mutex_unlock(); return hr; @@ -142,13 +144,15 @@ static HRESULT WINAPI IDirect3DVolume8Impl_GetPrivateData(IDirect3DVolume8 *ifac void *pData, DWORD *pSizeOfData) { IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %p.\n", iface, debugstr_guid(refguid), pData, pSizeOfData); wined3d_mutex_lock(); - hr = wined3d_volume_get_private_data(This->wined3d_volume, refguid, pData, pSizeOfData); + resource = wined3d_volume_get_resource(This->wined3d_volume); + hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData); wined3d_mutex_unlock(); return hr; @@ -157,12 +161,14 @@ static HRESULT WINAPI IDirect3DVolume8Impl_GetPrivateData(IDirect3DVolume8 *ifac static HRESULT WINAPI IDirect3DVolume8Impl_FreePrivateData(IDirect3DVolume8 *iface, REFGUID refguid) { IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid)); wined3d_mutex_lock(); - hr = wined3d_volume_free_private_data(This->wined3d_volume, refguid); + resource = wined3d_volume_get_resource(This->wined3d_volume); + hr = wined3d_resource_free_private_data(resource, refguid); wined3d_mutex_unlock(); return hr; @@ -201,7 +207,7 @@ static HRESULT WINAPI IDirect3DVolume8Impl_GetDesc(IDirect3DVolume8 *iface, D3DV desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format); desc->Type = wined3d_desc.resource_type; - desc->Usage = wined3d_desc.usage; + desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->Size = wined3d_desc.size; desc->Width = wined3d_desc.width; @@ -221,8 +227,8 @@ static HRESULT WINAPI IDirect3DVolume8Impl_LockBox(IDirect3DVolume8 *iface, iface, pLockedVolume, pBox, Flags); wined3d_mutex_lock(); - hr = wined3d_volume_map(This->wined3d_volume, (WINED3DLOCKED_BOX *)pLockedVolume, - (const WINED3DBOX *)pBox, Flags); + hr = wined3d_volume_map(This->wined3d_volume, (struct wined3d_mapped_box *)pLockedVolume, + (const struct wined3d_box *)pBox, Flags); wined3d_mutex_unlock(); return hr; @@ -270,7 +276,7 @@ static const struct wined3d_parent_ops d3d8_volume_wined3d_parent_ops = }; HRESULT volume_init(IDirect3DVolume8Impl *volume, IDirect3DDevice8Impl *device, UINT width, UINT height, - UINT depth, DWORD usage, enum wined3d_format_id format, WINED3DPOOL pool) + UINT depth, DWORD usage, enum wined3d_format_id format, enum wined3d_pool pool) { HRESULT hr; diff --git a/reactos/dll/directx/wine/d3d8/volumetexture.c b/reactos/dll/directx/wine/d3d8/volumetexture.c index 08e36807bba..a713f165e00 100644 --- a/reactos/dll/directx/wine/d3d8/volumetexture.c +++ b/reactos/dll/directx/wine/d3d8/volumetexture.c @@ -95,7 +95,7 @@ static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetDevice(IDirect3DVolumeTextu TRACE("iface %p, device %p.\n", iface, device); - *device = (IDirect3DDevice8 *)This->parentDevice; + *device = This->parentDevice; IDirect3DDevice8_AddRef(*device); TRACE("Returning device %p.\n", *device); @@ -107,13 +107,15 @@ static HRESULT WINAPI IDirect3DVolumeTexture8Impl_SetPrivateData(IDirect3DVolume REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) { IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", iface, debugstr_guid(refguid), pData, SizeOfData, Flags); wined3d_mutex_lock(); - hr = wined3d_texture_set_private_data(This->wined3d_texture, refguid, pData, SizeOfData, Flags); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags); wined3d_mutex_unlock(); return hr; @@ -123,13 +125,15 @@ static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetPrivateData(IDirect3DVolume REFGUID refguid, void *pData, DWORD *pSizeOfData) { IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %p.\n", iface, debugstr_guid(refguid), pData, pSizeOfData); wined3d_mutex_lock(); - hr = wined3d_texture_get_private_data(This->wined3d_texture, refguid, pData, pSizeOfData); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData); wined3d_mutex_unlock(); return hr; @@ -139,12 +143,14 @@ static HRESULT WINAPI IDirect3DVolumeTexture8Impl_FreePrivateData(IDirect3DVolum REFGUID refguid) { IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid)); wined3d_mutex_lock(); - hr = wined3d_texture_free_private_data(This->wined3d_texture, refguid); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_free_private_data(resource, refguid); wined3d_mutex_unlock(); return hr; @@ -192,16 +198,9 @@ static void WINAPI IDirect3DVolumeTexture8Impl_PreLoad(IDirect3DVolumeTexture8 * static D3DRESOURCETYPE WINAPI IDirect3DVolumeTexture8Impl_GetType(IDirect3DVolumeTexture8 *iface) { - IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface); - D3DRESOURCETYPE type; - TRACE("iface %p.\n", iface); - wined3d_mutex_lock(); - type = wined3d_texture_get_type(This->wined3d_texture); - wined3d_mutex_unlock(); - - return type; + return D3DRTYPE_VOLUMETEXTURE; } /* IDirect3DVolumeTexture8 IDirect3DBaseTexture8 Interface follow: */ @@ -266,7 +265,7 @@ static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetLevelDesc(IDirect3DVolumeTe wined3d_resource_get_desc(sub_resource, &wined3d_desc); desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format); desc->Type = wined3d_desc.resource_type; - desc->Usage = wined3d_desc.usage; + desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->Size = wined3d_desc.size; desc->Width = wined3d_desc.width; @@ -349,7 +348,7 @@ static HRESULT WINAPI IDirect3DVolumeTexture8Impl_AddDirtyBox(IDirect3DVolumeTex TRACE("iface %p, dirty_box %p.\n", iface, dirty_box); wined3d_mutex_lock(); - hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const WINED3DBOX *)dirty_box); + hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const struct wined3d_box *)dirty_box); wined3d_mutex_unlock(); return hr; diff --git a/reactos/dll/directx/wine/d3d9/buffer.c b/reactos/dll/directx/wine/d3d9/buffer.c index d9a5564d577..1be06a5f936 100644 --- a/reactos/dll/directx/wine/d3d9/buffer.c +++ b/reactos/dll/directx/wine/d3d9/buffer.c @@ -19,10 +19,16 @@ */ #include "config.h" +#include #include "d3d9_private.h" WINE_DEFAULT_DEBUG_CHANNEL(d3d9); +static inline IDirect3DVertexBuffer9Impl *impl_from_IDirect3DVertexBuffer9(IDirect3DVertexBuffer9 *iface) +{ + return CONTAINING_RECORD(iface, IDirect3DVertexBuffer9Impl, IDirect3DVertexBuffer9_iface); +} + static HRESULT WINAPI d3d9_vertexbuffer_QueryInterface(IDirect3DVertexBuffer9 *iface, REFIID riid, void **object) { TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); @@ -44,7 +50,7 @@ static HRESULT WINAPI d3d9_vertexbuffer_QueryInterface(IDirect3DVertexBuffer9 *i static ULONG WINAPI d3d9_vertexbuffer_AddRef(IDirect3DVertexBuffer9 *iface) { - IDirect3DVertexBuffer9Impl *buffer = (IDirect3DVertexBuffer9Impl *)iface; + IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface); ULONG refcount = InterlockedIncrement(&buffer->ref); TRACE("%p increasing refcount to %u.\n", iface, refcount); @@ -62,7 +68,7 @@ static ULONG WINAPI d3d9_vertexbuffer_AddRef(IDirect3DVertexBuffer9 *iface) static ULONG WINAPI d3d9_vertexbuffer_Release(IDirect3DVertexBuffer9 *iface) { - IDirect3DVertexBuffer9Impl *buffer = (IDirect3DVertexBuffer9Impl *)iface; + IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface); ULONG refcount = InterlockedDecrement(&buffer->ref); TRACE("%p decreasing refcount to %u.\n", iface, refcount); @@ -82,11 +88,14 @@ static ULONG WINAPI d3d9_vertexbuffer_Release(IDirect3DVertexBuffer9 *iface) return refcount; } -static HRESULT WINAPI d3d9_vertexbuffer_GetDevice(IDirect3DVertexBuffer9 *iface, IDirect3DDevice9 **device) +static HRESULT WINAPI d3d9_vertexbuffer_GetDevice(IDirect3DVertexBuffer9 *iface, + IDirect3DDevice9 **device) { + IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface); + TRACE("iface %p, device %p.\n", iface, device); - *device = (IDirect3DDevice9 *)((IDirect3DVertexBuffer9Impl *)iface)->parentDevice; + *device = (IDirect3DDevice9 *)buffer->parentDevice; IDirect3DDevice9_AddRef(*device); TRACE("Returning device %p.\n", *device); @@ -97,14 +106,16 @@ static HRESULT WINAPI d3d9_vertexbuffer_GetDevice(IDirect3DVertexBuffer9 *iface, static HRESULT WINAPI d3d9_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer9 *iface, REFGUID guid, const void *data, DWORD data_size, DWORD flags) { + IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", iface, debugstr_guid(guid), data, data_size, flags); wined3d_mutex_lock(); - hr = wined3d_buffer_set_private_data(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer, - guid, data, data_size, flags); + resource = wined3d_buffer_get_resource(buffer->wineD3DVertexBuffer); + hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags); wined3d_mutex_unlock(); return hr; @@ -113,14 +124,16 @@ static HRESULT WINAPI d3d9_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer9 *i static HRESULT WINAPI d3d9_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer9 *iface, REFGUID guid, void *data, DWORD *data_size) { + IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %p.\n", iface, debugstr_guid(guid), data, data_size); wined3d_mutex_lock(); - hr = wined3d_buffer_get_private_data(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer, - guid, data, data_size); + resource = wined3d_buffer_get_resource(buffer->wineD3DVertexBuffer); + hr = wined3d_resource_get_private_data(resource, guid, data, data_size); wined3d_mutex_unlock(); return hr; @@ -128,12 +141,15 @@ static HRESULT WINAPI d3d9_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer9 *i static HRESULT WINAPI d3d9_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer9 *iface, REFGUID guid) { + IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid)); wined3d_mutex_lock(); - hr = wined3d_buffer_free_private_data(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer, guid); + resource = wined3d_buffer_get_resource(buffer->wineD3DVertexBuffer); + hr = wined3d_resource_free_private_data(resource, guid); wined3d_mutex_unlock(); return hr; @@ -141,12 +157,13 @@ static HRESULT WINAPI d3d9_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer9 * static DWORD WINAPI d3d9_vertexbuffer_SetPriority(IDirect3DVertexBuffer9 *iface, DWORD priority) { + IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface); DWORD previous; TRACE("iface %p, priority %u.\n", iface, priority); wined3d_mutex_lock(); - previous = wined3d_buffer_set_priority(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer, priority); + previous = wined3d_buffer_set_priority(buffer->wineD3DVertexBuffer, priority); wined3d_mutex_unlock(); return previous; @@ -154,12 +171,13 @@ static DWORD WINAPI d3d9_vertexbuffer_SetPriority(IDirect3DVertexBuffer9 *iface, static DWORD WINAPI d3d9_vertexbuffer_GetPriority(IDirect3DVertexBuffer9 *iface) { + IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface); DWORD priority; TRACE("iface %p.\n", iface); wined3d_mutex_lock(); - priority = wined3d_buffer_get_priority(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer); + priority = wined3d_buffer_get_priority(buffer->wineD3DVertexBuffer); wined3d_mutex_unlock(); return priority; @@ -167,10 +185,12 @@ static DWORD WINAPI d3d9_vertexbuffer_GetPriority(IDirect3DVertexBuffer9 *iface) static void WINAPI d3d9_vertexbuffer_PreLoad(IDirect3DVertexBuffer9 *iface) { + IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface); + TRACE("iface %p.\n", iface); wined3d_mutex_lock(); - wined3d_buffer_preload(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer); + wined3d_buffer_preload(buffer->wineD3DVertexBuffer); wined3d_mutex_unlock(); } @@ -181,17 +201,17 @@ static D3DRESOURCETYPE WINAPI d3d9_vertexbuffer_GetType(IDirect3DVertexBuffer9 * return D3DRTYPE_VERTEXBUFFER; } -static HRESULT WINAPI d3d9_vertexbuffer_Lock(IDirect3DVertexBuffer9 *iface, - UINT offset, UINT size, void **data, DWORD flags) +static HRESULT WINAPI d3d9_vertexbuffer_Lock(IDirect3DVertexBuffer9 *iface, UINT offset, UINT size, + void **data, DWORD flags) { + IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface); HRESULT hr; TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n", iface, offset, size, data, flags); wined3d_mutex_lock(); - hr = wined3d_buffer_map(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer, - offset, size, (BYTE **)data, flags); + hr = wined3d_buffer_map(buffer->wineD3DVertexBuffer, offset, size, (BYTE **)data, flags); wined3d_mutex_unlock(); return hr; @@ -199,18 +219,21 @@ static HRESULT WINAPI d3d9_vertexbuffer_Lock(IDirect3DVertexBuffer9 *iface, static HRESULT WINAPI d3d9_vertexbuffer_Unlock(IDirect3DVertexBuffer9 *iface) { + IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface); + TRACE("iface %p.\n", iface); wined3d_mutex_lock(); - wined3d_buffer_unmap(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer); + wined3d_buffer_unmap(buffer->wineD3DVertexBuffer); wined3d_mutex_unlock(); return D3D_OK; } -static HRESULT WINAPI d3d9_vertexbuffer_GetDesc(IDirect3DVertexBuffer9 *iface, D3DVERTEXBUFFER_DESC *desc) +static HRESULT WINAPI d3d9_vertexbuffer_GetDesc(IDirect3DVertexBuffer9 *iface, + D3DVERTEXBUFFER_DESC *desc) { - IDirect3DVertexBuffer9Impl *buffer = (IDirect3DVertexBuffer9Impl *)iface; + IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface); struct wined3d_resource_desc wined3d_desc; struct wined3d_resource *wined3d_resource; @@ -222,7 +245,7 @@ static HRESULT WINAPI d3d9_vertexbuffer_GetDesc(IDirect3DVertexBuffer9 *iface, D wined3d_mutex_unlock(); desc->Format = D3DFMT_VERTEXDATA; - desc->Usage = wined3d_desc.usage; + desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->Size = wined3d_desc.size; desc->Type = D3DRTYPE_VERTEXBUFFER; @@ -267,13 +290,13 @@ HRESULT vertexbuffer_init(IDirect3DVertexBuffer9Impl *buffer, IDirect3DDevice9Im { HRESULT hr; - buffer->lpVtbl = &d3d9_vertexbuffer_vtbl; + buffer->IDirect3DVertexBuffer9_iface.lpVtbl = &d3d9_vertexbuffer_vtbl; buffer->ref = 1; buffer->fvf = fvf; wined3d_mutex_lock(); hr = wined3d_buffer_create_vb(device->wined3d_device, size, usage & WINED3DUSAGE_MASK, - (WINED3DPOOL)pool, buffer, &d3d9_vertexbuffer_wined3d_parent_ops, &buffer->wineD3DVertexBuffer); + (enum wined3d_pool)pool, buffer, &d3d9_vertexbuffer_wined3d_parent_ops, &buffer->wineD3DVertexBuffer); wined3d_mutex_unlock(); if (FAILED(hr)) { @@ -287,6 +310,20 @@ HRESULT vertexbuffer_init(IDirect3DVertexBuffer9Impl *buffer, IDirect3DDevice9Im return D3D_OK; } +IDirect3DVertexBuffer9Impl *unsafe_impl_from_IDirect3DVertexBuffer9(IDirect3DVertexBuffer9 *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &d3d9_vertexbuffer_vtbl); + + return impl_from_IDirect3DVertexBuffer9(iface); +} + +static inline IDirect3DIndexBuffer9Impl *impl_from_IDirect3DIndexBuffer9(IDirect3DIndexBuffer9 *iface) +{ + return CONTAINING_RECORD(iface, IDirect3DIndexBuffer9Impl, IDirect3DIndexBuffer9_iface); +} + static HRESULT WINAPI d3d9_indexbuffer_QueryInterface(IDirect3DIndexBuffer9 *iface, REFIID riid, void **object) { TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); @@ -308,7 +345,7 @@ static HRESULT WINAPI d3d9_indexbuffer_QueryInterface(IDirect3DIndexBuffer9 *ifa static ULONG WINAPI d3d9_indexbuffer_AddRef(IDirect3DIndexBuffer9 *iface) { - IDirect3DIndexBuffer9Impl *buffer = (IDirect3DIndexBuffer9Impl *)iface; + IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface); ULONG refcount = InterlockedIncrement(&buffer->ref); TRACE("%p increasing refcount to %u.\n", iface, refcount); @@ -326,7 +363,7 @@ static ULONG WINAPI d3d9_indexbuffer_AddRef(IDirect3DIndexBuffer9 *iface) static ULONG WINAPI d3d9_indexbuffer_Release(IDirect3DIndexBuffer9 *iface) { - IDirect3DIndexBuffer9Impl *buffer = (IDirect3DIndexBuffer9Impl *)iface; + IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface); ULONG refcount = InterlockedDecrement(&buffer->ref); TRACE("%p decreasing refcount to %u.\n", iface, refcount); @@ -346,11 +383,14 @@ static ULONG WINAPI d3d9_indexbuffer_Release(IDirect3DIndexBuffer9 *iface) return refcount; } -static HRESULT WINAPI d3d9_indexbuffer_GetDevice(IDirect3DIndexBuffer9 *iface, IDirect3DDevice9 **device) +static HRESULT WINAPI d3d9_indexbuffer_GetDevice(IDirect3DIndexBuffer9 *iface, + IDirect3DDevice9 **device) { + IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface); + TRACE("iface %p, device %p.\n", iface, device); - *device = (IDirect3DDevice9 *)((IDirect3DIndexBuffer9Impl *)iface)->parentDevice; + *device = (IDirect3DDevice9 *)buffer->parentDevice; IDirect3DDevice9_AddRef(*device); TRACE("Returning device %p.\n", *device); @@ -361,14 +401,16 @@ static HRESULT WINAPI d3d9_indexbuffer_GetDevice(IDirect3DIndexBuffer9 *iface, I static HRESULT WINAPI d3d9_indexbuffer_SetPrivateData(IDirect3DIndexBuffer9 *iface, REFGUID guid, const void *data, DWORD data_size, DWORD flags) { + IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", iface, debugstr_guid(guid), data, data_size, flags); wined3d_mutex_lock(); - hr = wined3d_buffer_set_private_data(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer, - guid, data, data_size, flags); + resource = wined3d_buffer_get_resource(buffer->wineD3DIndexBuffer); + hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags); wined3d_mutex_unlock(); return hr; @@ -377,14 +419,16 @@ static HRESULT WINAPI d3d9_indexbuffer_SetPrivateData(IDirect3DIndexBuffer9 *ifa static HRESULT WINAPI d3d9_indexbuffer_GetPrivateData(IDirect3DIndexBuffer9 *iface, REFGUID guid, void *data, DWORD *data_size) { + IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %p.\n", iface, debugstr_guid(guid), data, data_size); wined3d_mutex_lock(); - hr = wined3d_buffer_get_private_data(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer, - guid, data, data_size); + resource = wined3d_buffer_get_resource(buffer->wineD3DIndexBuffer); + hr = wined3d_resource_get_private_data(resource, guid, data, data_size); wined3d_mutex_unlock(); return hr; @@ -392,12 +436,15 @@ static HRESULT WINAPI d3d9_indexbuffer_GetPrivateData(IDirect3DIndexBuffer9 *ifa static HRESULT WINAPI d3d9_indexbuffer_FreePrivateData(IDirect3DIndexBuffer9 *iface, REFGUID guid) { + IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid)); wined3d_mutex_lock(); - hr = wined3d_buffer_free_private_data(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer, guid); + resource = wined3d_buffer_get_resource(buffer->wineD3DIndexBuffer); + hr = wined3d_resource_free_private_data(resource, guid); wined3d_mutex_unlock(); return hr; @@ -405,12 +452,13 @@ static HRESULT WINAPI d3d9_indexbuffer_FreePrivateData(IDirect3DIndexBuffer9 *if static DWORD WINAPI d3d9_indexbuffer_SetPriority(IDirect3DIndexBuffer9 *iface, DWORD priority) { + IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface); DWORD previous; TRACE("iface %p, priority %u.\n", iface, priority); wined3d_mutex_lock(); - previous = wined3d_buffer_set_priority(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer, priority); + previous = wined3d_buffer_set_priority(buffer->wineD3DIndexBuffer, priority); wined3d_mutex_unlock(); return previous; @@ -418,12 +466,13 @@ static DWORD WINAPI d3d9_indexbuffer_SetPriority(IDirect3DIndexBuffer9 *iface, D static DWORD WINAPI d3d9_indexbuffer_GetPriority(IDirect3DIndexBuffer9 *iface) { + IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface); DWORD priority; TRACE("iface %p.\n", iface); wined3d_mutex_lock(); - priority = wined3d_buffer_get_priority(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer); + priority = wined3d_buffer_get_priority(buffer->wineD3DIndexBuffer); wined3d_mutex_unlock(); return priority; @@ -431,10 +480,12 @@ static DWORD WINAPI d3d9_indexbuffer_GetPriority(IDirect3DIndexBuffer9 *iface) static void WINAPI d3d9_indexbuffer_PreLoad(IDirect3DIndexBuffer9 *iface) { + IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface); + TRACE("iface %p.\n", iface); wined3d_mutex_lock(); - wined3d_buffer_preload(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer); + wined3d_buffer_preload(buffer->wineD3DIndexBuffer); wined3d_mutex_unlock(); } @@ -448,14 +499,14 @@ static D3DRESOURCETYPE WINAPI d3d9_indexbuffer_GetType(IDirect3DIndexBuffer9 *if static HRESULT WINAPI d3d9_indexbuffer_Lock(IDirect3DIndexBuffer9 *iface, UINT offset, UINT size, void **data, DWORD flags) { + IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface); HRESULT hr; TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n", iface, offset, size, data, flags); wined3d_mutex_lock(); - hr = wined3d_buffer_map(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer, - offset, size, (BYTE **)data, flags); + hr = wined3d_buffer_map(buffer->wineD3DIndexBuffer, offset, size, (BYTE **)data, flags); wined3d_mutex_unlock(); return hr; @@ -463,18 +514,21 @@ static HRESULT WINAPI d3d9_indexbuffer_Lock(IDirect3DIndexBuffer9 *iface, static HRESULT WINAPI d3d9_indexbuffer_Unlock(IDirect3DIndexBuffer9 *iface) { + IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface); + TRACE("iface %p.\n", iface); wined3d_mutex_lock(); - wined3d_buffer_unmap(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer); + wined3d_buffer_unmap(buffer->wineD3DIndexBuffer); wined3d_mutex_unlock(); return D3D_OK; } -static HRESULT WINAPI d3d9_indexbuffer_GetDesc(IDirect3DIndexBuffer9 *iface, D3DINDEXBUFFER_DESC *desc) +static HRESULT WINAPI d3d9_indexbuffer_GetDesc(IDirect3DIndexBuffer9 *iface, + D3DINDEXBUFFER_DESC *desc) { - IDirect3DIndexBuffer9Impl *buffer = (IDirect3DIndexBuffer9Impl *)iface; + IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface); struct wined3d_resource_desc wined3d_desc; struct wined3d_resource *wined3d_resource; @@ -486,7 +540,7 @@ static HRESULT WINAPI d3d9_indexbuffer_GetDesc(IDirect3DIndexBuffer9 *iface, D3D wined3d_mutex_unlock(); desc->Format = d3dformat_from_wined3dformat(buffer->format); - desc->Usage = wined3d_desc.usage; + desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->Size = wined3d_desc.size; desc->Type = D3DRTYPE_INDEXBUFFER; @@ -530,13 +584,13 @@ HRESULT indexbuffer_init(IDirect3DIndexBuffer9Impl *buffer, IDirect3DDevice9Impl { HRESULT hr; - buffer->lpVtbl = &d3d9_indexbuffer_vtbl; + buffer->IDirect3DIndexBuffer9_iface.lpVtbl = &d3d9_indexbuffer_vtbl; buffer->ref = 1; buffer->format = wined3dformat_from_d3dformat(format); wined3d_mutex_lock(); hr = wined3d_buffer_create_ib(device->wined3d_device, size, usage & WINED3DUSAGE_MASK, - (WINED3DPOOL)pool, buffer, &d3d9_indexbuffer_wined3d_parent_ops, &buffer->wineD3DIndexBuffer); + (enum wined3d_pool)pool, buffer, &d3d9_indexbuffer_wined3d_parent_ops, &buffer->wineD3DIndexBuffer); wined3d_mutex_unlock(); if (FAILED(hr)) { @@ -549,3 +603,12 @@ HRESULT indexbuffer_init(IDirect3DIndexBuffer9Impl *buffer, IDirect3DDevice9Impl return D3D_OK; } + +IDirect3DIndexBuffer9Impl *unsafe_impl_from_IDirect3DIndexBuffer9(IDirect3DIndexBuffer9 *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &d3d9_indexbuffer_vtbl); + + return impl_from_IDirect3DIndexBuffer9(iface); +} diff --git a/reactos/dll/directx/wine/d3d9/cubetexture.c b/reactos/dll/directx/wine/d3d9/cubetexture.c index 1f5e27b8033..349f79082e8 100644 --- a/reactos/dll/directx/wine/d3d9/cubetexture.c +++ b/reactos/dll/directx/wine/d3d9/cubetexture.c @@ -112,13 +112,15 @@ static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetPrivateData(IDirect3DCubeText REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) { IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", iface, debugstr_guid(refguid), pData, SizeOfData, Flags); wined3d_mutex_lock(); - hr = wined3d_texture_set_private_data(This->wined3d_texture, refguid, pData, SizeOfData, Flags); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags); wined3d_mutex_unlock(); return hr; @@ -128,13 +130,15 @@ static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetPrivateData(IDirect3DCubeText REFGUID refguid, void *pData, DWORD *pSizeOfData) { IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %p.\n", iface, debugstr_guid(refguid), pData, pSizeOfData); wined3d_mutex_lock(); - hr = wined3d_texture_get_private_data(This->wined3d_texture, refguid, pData, pSizeOfData); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData); wined3d_mutex_unlock(); return hr; @@ -144,12 +148,14 @@ static HRESULT WINAPI IDirect3DCubeTexture9Impl_FreePrivateData(IDirect3DCubeTex REFGUID refguid) { IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid)); wined3d_mutex_lock(); - hr = wined3d_texture_free_private_data(This->wined3d_texture, refguid); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_free_private_data(resource, refguid); wined3d_mutex_unlock(); return hr; @@ -197,16 +203,9 @@ static void WINAPI IDirect3DCubeTexture9Impl_PreLoad(IDirect3DCubeTexture9 *ifac static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture9Impl_GetType(IDirect3DCubeTexture9 *iface) { - IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface); - D3DRESOURCETYPE ret; - TRACE("iface %p.\n", iface); - wined3d_mutex_lock(); - ret = wined3d_texture_get_type(This->wined3d_texture); - wined3d_mutex_unlock(); - - return ret; + return D3DRTYPE_CUBETEXTURE; } /* IDirect3DCubeTexture9 IDirect3DBaseTexture9 Interface follow: */ @@ -261,7 +260,7 @@ static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetAutoGenFilterType(IDirect3DCu TRACE("iface %p, filter_type %#x.\n", iface, FilterType); wined3d_mutex_lock(); - hr = wined3d_texture_set_autogen_filter_type(This->wined3d_texture, (WINED3DTEXTUREFILTERTYPE)FilterType); + hr = wined3d_texture_set_autogen_filter_type(This->wined3d_texture, (enum wined3d_texture_filter_type)FilterType); wined3d_mutex_unlock(); return hr; @@ -312,7 +311,7 @@ static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetLevelDesc(IDirect3DCubeTextur wined3d_resource_get_desc(sub_resource, &wined3d_desc); desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format); desc->Type = wined3d_desc.resource_type; - desc->Usage = wined3d_desc.usage; + desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->MultiSampleType = wined3d_desc.multisample_type; desc->MultiSampleQuality = wined3d_desc.multisample_quality; @@ -407,14 +406,14 @@ static HRESULT WINAPI IDirect3DCubeTexture9Impl_AddDirtyRect(IDirect3DCubeTextu hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, NULL); else { - WINED3DBOX dirty_region; + struct wined3d_box dirty_region; - dirty_region.Left = dirty_rect->left; - dirty_region.Top = dirty_rect->top; - dirty_region.Right = dirty_rect->right; - dirty_region.Bottom = dirty_rect->bottom; - dirty_region.Front = 0; - dirty_region.Back = 1; + dirty_region.left = dirty_rect->left; + dirty_region.top = dirty_rect->top; + dirty_region.right = dirty_rect->right; + dirty_region.bottom = dirty_rect->bottom; + dirty_region.front = 0; + dirty_region.back = 1; hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, &dirty_region); } wined3d_mutex_unlock(); diff --git a/reactos/dll/directx/wine/d3d9/d3d9_main.c b/reactos/dll/directx/wine/d3d9/d3d9_main.c index 0d3ecec99d4..abb98f30581 100644 --- a/reactos/dll/directx/wine/d3d9/d3d9_main.c +++ b/reactos/dll/directx/wine/d3d9/d3d9_main.c @@ -40,7 +40,7 @@ IDirect3D9* WINAPI DECLSPEC_HOTPATCH Direct3DCreate9(UINT SDKVersion) { object->ref = 1; wined3d_mutex_lock(); - object->WineD3D = wined3d_create(9, object); + object->WineD3D = wined3d_create(9, 0, object); wined3d_mutex_unlock(); TRACE("SDKVersion = %x, Created Direct3D object @ %p, WineObj @ %p\n", SDKVersion, object, object->WineD3D); diff --git a/reactos/dll/directx/wine/d3d9/d3d9_private.h b/reactos/dll/directx/wine/d3d9/d3d9_private.h index 23e7f00353e..9feda661faa 100644 --- a/reactos/dll/directx/wine/d3d9/d3d9_private.h +++ b/reactos/dll/directx/wine/d3d9/d3d9_private.h @@ -111,16 +111,15 @@ enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format) DECLSPEC_H _pD3D9Caps->DeclTypes = _pWineCaps->DeclTypes; \ _pD3D9Caps->NumSimultaneousRTs = _pWineCaps->NumSimultaneousRTs; \ _pD3D9Caps->StretchRectFilterCaps = _pWineCaps->StretchRectFilterCaps; \ - _pD3D9Caps->VS20Caps.Caps = _pWineCaps->VS20Caps.Caps; \ - _pD3D9Caps->VS20Caps.DynamicFlowControlDepth = _pWineCaps->VS20Caps.DynamicFlowControlDepth; \ - _pD3D9Caps->VS20Caps.NumTemps = _pWineCaps->VS20Caps.NumTemps; \ - _pD3D9Caps->VS20Caps.NumTemps = _pWineCaps->VS20Caps.NumTemps; \ - _pD3D9Caps->VS20Caps.StaticFlowControlDepth = _pWineCaps->VS20Caps.StaticFlowControlDepth; \ - _pD3D9Caps->PS20Caps.Caps = _pWineCaps->PS20Caps.Caps; \ - _pD3D9Caps->PS20Caps.DynamicFlowControlDepth = _pWineCaps->PS20Caps.DynamicFlowControlDepth; \ - _pD3D9Caps->PS20Caps.NumTemps = _pWineCaps->PS20Caps.NumTemps; \ - _pD3D9Caps->PS20Caps.StaticFlowControlDepth = _pWineCaps->PS20Caps.StaticFlowControlDepth; \ - _pD3D9Caps->PS20Caps.NumInstructionSlots = _pWineCaps->PS20Caps.NumInstructionSlots; \ + _pD3D9Caps->VS20Caps.Caps = _pWineCaps->VS20Caps.caps; \ + _pD3D9Caps->VS20Caps.DynamicFlowControlDepth = _pWineCaps->VS20Caps.dynamic_flow_control_depth; \ + _pD3D9Caps->VS20Caps.NumTemps = _pWineCaps->VS20Caps.temp_count; \ + _pD3D9Caps->VS20Caps.StaticFlowControlDepth = _pWineCaps->VS20Caps.static_flow_control_depth; \ + _pD3D9Caps->PS20Caps.Caps = _pWineCaps->PS20Caps.caps; \ + _pD3D9Caps->PS20Caps.DynamicFlowControlDepth = _pWineCaps->PS20Caps.dynamic_flow_control_depth; \ + _pD3D9Caps->PS20Caps.NumTemps = _pWineCaps->PS20Caps.temp_count; \ + _pD3D9Caps->PS20Caps.StaticFlowControlDepth = _pWineCaps->PS20Caps.static_flow_control_depth; \ + _pD3D9Caps->PS20Caps.NumInstructionSlots = _pWineCaps->PS20Caps.instruction_slot_count; \ _pD3D9Caps->VertexTextureFilterCaps = _pWineCaps->VertexTextureFilterCaps; \ _pD3D9Caps->MaxVShaderInstructionsExecuted = _pWineCaps->MaxVShaderInstructionsExecuted; \ _pD3D9Caps->MaxPShaderInstructionsExecuted = _pWineCaps->MaxPShaderInstructionsExecuted; \ @@ -166,6 +165,7 @@ typedef struct IDirect3DDevice9Impl struct wined3d_device_parent device_parent; LONG ref; struct wined3d_device *wined3d_device; + IDirect3D9Ex *d3d_parent; /* Avoids recursion with nested ReleaseRef to 0 */ BOOL inDestruction; @@ -175,7 +175,7 @@ typedef struct IDirect3DDevice9Impl BOOL notreset; } IDirect3DDevice9Impl; -HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT adapter, D3DDEVTYPE device_type, +HRESULT device_init(IDirect3DDevice9Impl *device, IDirect3D9Impl *parent, struct wined3d *wined3d, UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode) DECLSPEC_HIDDEN; /***************************************************************************** @@ -192,7 +192,7 @@ typedef struct IDirect3DVolume9Impl } IDirect3DVolume9Impl; HRESULT volume_init(IDirect3DVolume9Impl *volume, IDirect3DDevice9Impl *device, UINT width, UINT height, - UINT depth, DWORD usage, enum wined3d_format_id format, WINED3DPOOL pool) DECLSPEC_HIDDEN; + UINT depth, DWORD usage, enum wined3d_format_id format, enum wined3d_pool pool) DECLSPEC_HIDDEN; /* ------------------- */ /* IDirect3DSwapChain9 */ @@ -222,9 +222,8 @@ HRESULT swapchain_init(IDirect3DSwapChain9Impl *swapchain, IDirect3DDevice9Impl */ typedef struct IDirect3DSurface9Impl { - /* IUnknown fields */ - const IDirect3DSurface9Vtbl *lpVtbl; - LONG ref; + IDirect3DSurface9 IDirect3DSurface9_iface; + LONG ref; struct wined3d_surface *wined3d_surface; IDirect3DDevice9Ex *parentDevice; @@ -240,6 +239,7 @@ typedef struct IDirect3DSurface9Impl HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *device, UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level, DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality) DECLSPEC_HIDDEN; +IDirect3DSurface9Impl *unsafe_impl_from_IDirect3DSurface9(IDirect3DSurface9 *iface) DECLSPEC_HIDDEN; /* ---------------------- */ /* IDirect3DVertexBuffer9 */ @@ -250,10 +250,8 @@ HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *devic */ typedef struct IDirect3DVertexBuffer9Impl { - /* IUnknown fields */ - const IDirect3DVertexBuffer9Vtbl *lpVtbl; - LONG ref; - + IDirect3DVertexBuffer9 IDirect3DVertexBuffer9_iface; + LONG ref; struct wined3d_buffer *wineD3DVertexBuffer; IDirect3DDevice9Ex *parentDevice; DWORD fvf; @@ -261,6 +259,7 @@ typedef struct IDirect3DVertexBuffer9Impl HRESULT vertexbuffer_init(IDirect3DVertexBuffer9Impl *buffer, IDirect3DDevice9Impl *device, UINT size, UINT usage, DWORD fvf, D3DPOOL pool) DECLSPEC_HIDDEN; +IDirect3DVertexBuffer9Impl *unsafe_impl_from_IDirect3DVertexBuffer9(IDirect3DVertexBuffer9 *iface) DECLSPEC_HIDDEN; /* --------------------- */ /* IDirect3DIndexBuffer9 */ @@ -271,10 +270,8 @@ HRESULT vertexbuffer_init(IDirect3DVertexBuffer9Impl *buffer, IDirect3DDevice9Im */ typedef struct IDirect3DIndexBuffer9Impl { - /* IUnknown fields */ - const IDirect3DIndexBuffer9Vtbl *lpVtbl; - LONG ref; - + IDirect3DIndexBuffer9 IDirect3DIndexBuffer9_iface; + LONG ref; struct wined3d_buffer *wineD3DIndexBuffer; IDirect3DDevice9Ex *parentDevice; enum wined3d_format_id format; @@ -282,6 +279,7 @@ typedef struct IDirect3DIndexBuffer9Impl HRESULT indexbuffer_init(IDirect3DIndexBuffer9Impl *buffer, IDirect3DDevice9Impl *device, UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN; +IDirect3DIndexBuffer9Impl *unsafe_impl_from_IDirect3DIndexBuffer9(IDirect3DIndexBuffer9 *iface) DECLSPEC_HIDDEN; /* --------------------- */ /* IDirect3DBaseTexture9 */ @@ -407,8 +405,7 @@ HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration9Impl *declaration, * IDirect3DVertexShader implementation structure */ typedef struct IDirect3DVertexShader9Impl { - /* IUnknown fields */ - const IDirect3DVertexShader9Vtbl *lpVtbl; + IDirect3DVertexShader9 IDirect3DVertexShader9_iface; LONG ref; struct wined3d_shader *wined3d_shader; IDirect3DDevice9Ex *parentDevice; @@ -416,6 +413,7 @@ typedef struct IDirect3DVertexShader9Impl { HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader, IDirect3DDevice9Impl *device, const DWORD *byte_code) DECLSPEC_HIDDEN; +IDirect3DVertexShader9Impl *unsafe_impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface) DECLSPEC_HIDDEN; #define D3D9_MAX_VERTEX_SHADER_CONSTANTF 256 #define D3D9_MAX_SIMULTANEOUS_RENDERTARGETS 4 @@ -428,15 +426,15 @@ HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader, * IDirect3DPixelShader implementation structure */ typedef struct IDirect3DPixelShader9Impl { - /* IUnknown fields */ - const IDirect3DPixelShader9Vtbl *lpVtbl; - LONG ref; + IDirect3DPixelShader9 IDirect3DPixelShader9_iface; + LONG ref; struct wined3d_shader *wined3d_shader; IDirect3DDevice9Ex *parentDevice; } IDirect3DPixelShader9Impl; HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader, IDirect3DDevice9Impl *device, const DWORD *byte_code) DECLSPEC_HIDDEN; +IDirect3DPixelShader9Impl *unsafe_impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface) DECLSPEC_HIDDEN; /* --------------- */ /* IDirect3DQuery9 */ diff --git a/reactos/dll/directx/wine/d3d9/device.c b/reactos/dll/directx/wine/d3d9/device.c index 2af2c82460a..631ba5a9af5 100644 --- a/reactos/dll/directx/wine/d3d9/device.c +++ b/reactos/dll/directx/wine/d3d9/device.c @@ -265,6 +265,8 @@ static ULONG WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Release(IDirect3DDevi wined3d_device_decref(This->wined3d_device); wined3d_mutex_unlock(); + IDirect3D9_Release(This->d3d_parent); + HeapFree(GetProcessHeap(), 0, This); } return ref; @@ -302,23 +304,20 @@ static UINT WINAPI IDirect3DDevice9Impl_GetAvailableTextureMem(IDirect3DDevice9E static HRESULT WINAPI IDirect3DDevice9Impl_EvictManagedResources(IDirect3DDevice9Ex *iface) { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); - HRESULT hr; TRACE("iface %p.\n", iface); wined3d_mutex_lock(); - hr = wined3d_device_evict_managed_resources(This->wined3d_device); + wined3d_device_evict_managed_resources(This->wined3d_device); wined3d_mutex_unlock(); - return hr; + return D3D_OK; } static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(IDirect3DDevice9Ex *iface, IDirect3D9 **ppD3D9) { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); - struct wined3d *wined3d; - HRESULT hr = D3D_OK; TRACE("iface %p, d3d9 %p.\n", iface, ppD3D9); @@ -326,23 +325,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(IDirect3DDevice9Ex *iface return D3DERR_INVALIDCALL; } - wined3d_mutex_lock(); - hr = wined3d_device_get_wined3d(This->wined3d_device, &wined3d); - if (hr == D3D_OK && wined3d) - { - *ppD3D9 = wined3d_get_parent(wined3d); - IDirect3D9_AddRef(*ppD3D9); - wined3d_decref(wined3d); - } - else - { - FIXME("Call to IWineD3DDevice_GetDirect3D failed\n"); - *ppD3D9 = NULL; - } - TRACE("(%p) returning %p\n", This, *ppD3D9); - wined3d_mutex_unlock(); - - return hr; + return IDirect3D9Ex_QueryInterface(This->d3d_parent, &IID_IDirect3D9, (void **)ppD3D9); } static HRESULT WINAPI IDirect3DDevice9Impl_GetDeviceCaps(IDirect3DDevice9Ex *iface, D3DCAPS9 *pCaps) @@ -388,7 +371,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetDisplayMode(IDirect3DDevice9Ex *if TRACE("iface %p, swapchain %u, mode %p.\n", iface, iSwapChain, pMode); wined3d_mutex_lock(); - hr = wined3d_device_get_display_mode(This->wined3d_device, iSwapChain, (WINED3DDISPLAYMODE *)pMode); + hr = wined3d_device_get_display_mode(This->wined3d_device, iSwapChain, (struct wined3d_display_mode *)pMode); wined3d_mutex_unlock(); if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format); @@ -406,7 +389,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetCreationParameters(IDirect3DDevice wined3d_mutex_lock(); hr = wined3d_device_get_creation_parameters(This->wined3d_device, - (WINED3DDEVICE_CREATION_PARAMETERS *)pParameters); + (struct wined3d_device_creation_parameters *)pParameters); wined3d_mutex_unlock(); return hr; @@ -416,7 +399,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetCursorProperties(IDirect3DDevice9E UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9 *pCursorBitmap) { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); - IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pCursorBitmap; + IDirect3DSurface9Impl *pSurface = unsafe_impl_from_IDirect3DSurface9(pCursorBitmap); HRESULT hr; TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n", @@ -532,21 +515,19 @@ static UINT WINAPI IDirect3DDevice9Impl_GetNumberOfSwapChains(IDirect3DDevice9Ex return count; } -static HRESULT WINAPI reset_enum_callback(struct wined3d_resource *resource, void *data) +static HRESULT CDECL reset_enum_callback(struct wined3d_resource *resource) { struct wined3d_resource_desc desc; - BOOL *resources_ok = data; wined3d_resource_get_desc(resource, &desc); - if (desc.pool == WINED3DPOOL_DEFAULT) + if (desc.pool == WINED3D_POOL_DEFAULT) { IDirect3DSurface9 *surface; - if (desc.resource_type != WINED3DRTYPE_SURFACE) + if (desc.resource_type != WINED3D_RTYPE_SURFACE) { WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource); - *resources_ok = FALSE; - return S_FALSE; + return D3DERR_INVALIDCALL; } surface = wined3d_resource_get_parent(resource); @@ -555,24 +536,21 @@ static HRESULT WINAPI reset_enum_callback(struct wined3d_resource *resource, voi if (IDirect3DSurface9_Release(surface)) { WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface, resource); - *resources_ok = FALSE; - return S_FALSE; + return D3DERR_INVALIDCALL; } WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface, resource); } - return S_OK; + return D3D_OK; } static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Reset(IDirect3DDevice9Ex *iface, D3DPRESENT_PARAMETERS *pPresentationParameters) { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); - WINED3DPRESENT_PARAMETERS localParameters; + struct wined3d_swapchain_desc swapchain_desc; HRESULT hr; - BOOL resources_ok = TRUE; - UINT i; TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters); @@ -585,63 +563,28 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Reset(IDirect3DDevi * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls */ wined3d_mutex_lock(); - wined3d_device_set_index_buffer(This->wined3d_device, NULL, WINED3DFMT_UNKNOWN); - for (i = 0; i < 16; ++i) - { - wined3d_device_set_stream_source(This->wined3d_device, i, NULL, 0, 0); - } - for (i = 0; i < 16; ++i) - { - wined3d_device_set_texture(This->wined3d_device, i, NULL); - } - wined3d_device_enum_resources(This->wined3d_device, reset_enum_callback, &resources_ok); - if (!resources_ok) - { - WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n"); + swapchain_desc.backbuffer_width = pPresentationParameters->BackBufferWidth; + swapchain_desc.backbuffer_height = pPresentationParameters->BackBufferHeight; + swapchain_desc.backbuffer_format = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat); + swapchain_desc.backbuffer_count = pPresentationParameters->BackBufferCount; + swapchain_desc.multisample_type = pPresentationParameters->MultiSampleType; + swapchain_desc.multisample_quality = pPresentationParameters->MultiSampleQuality; + swapchain_desc.swap_effect = pPresentationParameters->SwapEffect; + swapchain_desc.device_window = pPresentationParameters->hDeviceWindow; + swapchain_desc.windowed = pPresentationParameters->Windowed; + swapchain_desc.enable_auto_depth_stencil = pPresentationParameters->EnableAutoDepthStencil; + swapchain_desc.auto_depth_stencil_format = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat); + swapchain_desc.flags = pPresentationParameters->Flags; + swapchain_desc.refresh_rate = pPresentationParameters->FullScreen_RefreshRateInHz; + swapchain_desc.swap_interval = pPresentationParameters->PresentationInterval; + swapchain_desc.auto_restore_display_mode = TRUE; + + hr = wined3d_device_reset(This->wined3d_device, &swapchain_desc, reset_enum_callback); + if (FAILED(hr)) This->notreset = TRUE; - wined3d_mutex_unlock(); - - return D3DERR_INVALIDCALL; - } - - localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth; - localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight; - localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat); - localParameters.BackBufferCount = pPresentationParameters->BackBufferCount; - localParameters.MultiSampleType = pPresentationParameters->MultiSampleType; - localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality; - localParameters.SwapEffect = pPresentationParameters->SwapEffect; - localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow; - localParameters.Windowed = pPresentationParameters->Windowed; - localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil; - localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat); - localParameters.Flags = pPresentationParameters->Flags; - localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz; - localParameters.PresentationInterval = pPresentationParameters->PresentationInterval; - localParameters.AutoRestoreDisplayMode = TRUE; - - hr = wined3d_device_reset(This->wined3d_device, &localParameters); - if(FAILED(hr)) { - This->notreset = TRUE; - - pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth; - pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight; - pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat); - pPresentationParameters->BackBufferCount = localParameters.BackBufferCount; - pPresentationParameters->MultiSampleType = localParameters.MultiSampleType; - pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality; - pPresentationParameters->SwapEffect = localParameters.SwapEffect; - pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow; - pPresentationParameters->Windowed = localParameters.Windowed; - pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil; - pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat); - pPresentationParameters->Flags = localParameters.Flags; - pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz; - pPresentationParameters->PresentationInterval = localParameters.PresentationInterval; - } else { + else This->notreset = FALSE; - } wined3d_mutex_unlock(); @@ -677,7 +620,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetBackBuffer(IDirect3DDevice9Ex *ifa wined3d_mutex_lock(); hr = wined3d_device_get_back_buffer(This->wined3d_device, iSwapChain, - BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &wined3d_surface); + BackBuffer, (enum wined3d_backbuffer_type)Type, &wined3d_surface); if (SUCCEEDED(hr) && wined3d_surface && ppBackBuffer) { *ppBackBuffer = wined3d_surface_get_parent(wined3d_surface); @@ -697,7 +640,8 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetRasterStatus(IDirect3DDevice9Ex *i TRACE("iface %p, swapchain %u, raster_status %p.\n", iface, iSwapChain, pRasterStatus); wined3d_mutex_lock(); - hr = wined3d_device_get_raster_status(This->wined3d_device, iSwapChain, (WINED3DRASTER_STATUS *)pRasterStatus); + hr = wined3d_device_get_raster_status(This->wined3d_device, + iSwapChain, (struct wined3d_raster_status *)pRasterStatus); wined3d_mutex_unlock(); return hr; @@ -725,9 +669,9 @@ static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(IDirect3DDevice9Ex *iface, TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface, iSwapChain, Flags, pRamp); - /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */ + /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */ wined3d_mutex_lock(); - wined3d_device_set_gamma_ramp(This->wined3d_device, iSwapChain, Flags, (const WINED3DGAMMARAMP *)pRamp); + wined3d_device_set_gamma_ramp(This->wined3d_device, iSwapChain, Flags, (const struct wined3d_gamma_ramp *)pRamp); wined3d_mutex_unlock(); } @@ -738,9 +682,9 @@ static void WINAPI IDirect3DDevice9Impl_GetGammaRamp(IDirect3DDevice9Ex *iface, TRACE("iface %p, swapchain %u, ramp %p.\n", iface, iSwapChain, pRamp); - /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */ + /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */ wined3d_mutex_lock(); - wined3d_device_get_gamma_ramp(This->wined3d_device, iSwapChain, (WINED3DGAMMARAMP *)pRamp); + wined3d_device_get_gamma_ramp(This->wined3d_device, iSwapChain, (struct wined3d_gamma_ramp *)pRamp); wined3d_mutex_unlock(); } @@ -750,11 +694,24 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex *ifa { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); IDirect3DTexture9Impl *object; + BOOL set_mem = FALSE; HRESULT hr; TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n", iface, width, height, levels, usage, format, pool, texture, shared_handle); + if (shared_handle) + { + if (pool == D3DPOOL_SYSTEMMEM) + { + if (levels != 1) + return D3DERR_INVALIDCALL; + set_mem = TRUE; + } + else + FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle); + } + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); if (!object) { @@ -770,6 +727,16 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex *ifa return hr; } + if (set_mem) + { + struct wined3d_resource *resource; + IDirect3DSurface9Impl *surface; + + resource = wined3d_texture_get_sub_resource(object->wined3d_texture, 0); + surface = wined3d_resource_get_parent(resource); + wined3d_surface_set_mem(surface->wined3d_surface, *shared_handle); + } + TRACE("Created texture %p.\n", object); *texture = &object->IDirect3DTexture9_iface; @@ -789,6 +756,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateVolumeTexture(IDirect3DDevice9E TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n", usage, format, pool, texture, shared_handle); + if (shared_handle) + FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle); + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); if (!object) { @@ -821,6 +791,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateCubeTexture(IDirect3DDevice9Ex TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n", iface, edge_length, levels, usage, format, pool, texture, shared_handle); + if (shared_handle) + FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle); + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); if (!object) { @@ -853,6 +826,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(IDirect3DDevice9Ex TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n", iface, size, usage, fvf, pool, buffer, shared_handle); + if (shared_handle) + FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle); + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); if (!object) { @@ -869,7 +845,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(IDirect3DDevice9Ex } TRACE("Created vertex buffer %p.\n", object); - *buffer = (IDirect3DVertexBuffer9 *)object; + *buffer = &object->IDirect3DVertexBuffer9_iface; return D3D_OK; } @@ -885,6 +861,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n", iface, size, usage, format, pool, buffer, shared_handle); + if (shared_handle) + FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle); + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); if (!object) { @@ -901,7 +880,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex } TRACE("Created index buffer %p.\n", object); - *buffer = (IDirect3DIndexBuffer9 *)object; + *buffer = &object->IDirect3DIndexBuffer9_iface; return D3D_OK; } @@ -936,14 +915,14 @@ static HRESULT IDirect3DDevice9Impl_CreateSurface(IDirect3DDevice9Impl *device, } TRACE("Created surface %p.\n", object); - *ppSurface = (IDirect3DSurface9 *)object; + *ppSurface = &object->IDirect3DSurface9_iface; return D3D_OK; } static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex *iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, - BOOL Lockable, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle) + BOOL Lockable, IDirect3DSurface9 **ppSurface, HANDLE *shared_handle) { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); HRESULT hr; @@ -951,7 +930,10 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n" "lockable %#x, surface %p, shared_handle %p.\n", iface, Width, Height, Format, MultiSample, MultisampleQuality, - Lockable, ppSurface, pSharedHandle); + Lockable, ppSurface, shared_handle); + + if (shared_handle) + FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle); hr = IDirect3DDevice9Impl_CreateSurface(This, Width, Height, Format, Lockable, FALSE /* Discard */, 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, @@ -963,7 +945,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(IDirect3DDevice9Ex *iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9 **ppSurface, - HANDLE *pSharedHandle) + HANDLE *shared_handle) { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); HRESULT hr; @@ -971,7 +953,10 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(IDirect3DDe TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n" "discard %#x, surface %p, shared_handle %p.\n", iface, Width, Height, Format, MultiSample, MultisampleQuality, - Discard, ppSurface, pSharedHandle); + Discard, ppSurface, shared_handle); + + if (shared_handle) + FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle); hr = IDirect3DDevice9Impl_CreateSurface(This, Width, Height, Format, TRUE /* Lockable */, Discard, 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, @@ -986,15 +971,16 @@ static HRESULT WINAPI IDirect3DDevice9Impl_UpdateSurface(IDirect3DDevice9Ex *ifa IDirect3DSurface9 *pDestinationSurface, const POINT *pDestPoint) { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); + IDirect3DSurface9Impl *src = unsafe_impl_from_IDirect3DSurface9(pSourceSurface); + IDirect3DSurface9Impl *dst = unsafe_impl_from_IDirect3DSurface9(pDestinationSurface); HRESULT hr; TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n", iface, pSourceSurface, pSourceRect, pDestinationSurface, pDestPoint); wined3d_mutex_lock(); - hr = wined3d_device_update_surface(This->wined3d_device, - ((IDirect3DSurface9Impl *)pSourceSurface)->wined3d_surface, pSourceRect, - ((IDirect3DSurface9Impl *)pDestinationSurface)->wined3d_surface, pDestPoint); + hr = wined3d_device_update_surface(This->wined3d_device, src->wined3d_surface, pSourceRect, + dst->wined3d_surface, pDestPoint); wined3d_mutex_unlock(); return hr; @@ -1020,15 +1006,14 @@ static HRESULT WINAPI IDirect3DDevice9Impl_UpdateTexture(IDirect3DDevice9Ex *ifa static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(IDirect3DDevice9Ex *iface, IDirect3DSurface9 *pRenderTarget, IDirect3DSurface9 *pDestSurface) { - IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget; - IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface; + IDirect3DSurface9Impl *renderTarget = unsafe_impl_from_IDirect3DSurface9(pRenderTarget); + IDirect3DSurface9Impl *destSurface = unsafe_impl_from_IDirect3DSurface9(pDestSurface); HRESULT hr; TRACE("iface %p, render_target %p, dst_surface %p.\n", iface, pRenderTarget, pDestSurface); wined3d_mutex_lock(); - hr = wined3d_surface_bltfast(destSurface->wined3d_surface, 0, 0, - renderTarget->wined3d_surface, NULL, WINEDDBLTFAST_NOCOLORKEY); + hr = wined3d_surface_get_render_target_data(destSurface->wined3d_surface, renderTarget->wined3d_surface); wined3d_mutex_unlock(); return hr; @@ -1038,7 +1023,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(IDirect3DDevice9Ex UINT iSwapChain, IDirect3DSurface9 *pDestSurface) { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); - IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface; + IDirect3DSurface9Impl *destSurface = unsafe_impl_from_IDirect3DSurface9(pDestSurface); HRESULT hr; TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface, iSwapChain, pDestSurface); @@ -1053,8 +1038,8 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(IDirect3DDevice9Ex static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(IDirect3DDevice9Ex *iface, IDirect3DSurface9 *pSourceSurface, const RECT *pSourceRect, IDirect3DSurface9 *pDestSurface, const RECT *pDestRect, D3DTEXTUREFILTERTYPE Filter) { - IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface; - IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface; + IDirect3DSurface9Impl *src = unsafe_impl_from_IDirect3DSurface9(pSourceSurface); + IDirect3DSurface9Impl *dst = unsafe_impl_from_IDirect3DSurface9(pDestSurface); HRESULT hr; TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n", @@ -1062,6 +1047,8 @@ static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(IDirect3DDevice9Ex *iface wined3d_mutex_lock(); hr = wined3d_surface_blt(dst->wined3d_surface, pDestRect, src->wined3d_surface, pSourceRect, 0, NULL, Filter); + if (hr == WINEDDERR_INVALIDRECT) + hr = D3DERR_INVALIDCALL; wined3d_mutex_unlock(); return hr; @@ -1070,7 +1057,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(IDirect3DDevice9Ex *iface static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(IDirect3DDevice9Ex *iface, IDirect3DSurface9 *pSurface, const RECT *pRect, D3DCOLOR color) { - const WINED3DCOLORVALUE c = + const struct wined3d_color c = { ((color >> 16) & 0xff) / 255.0f, ((color >> 8) & 0xff) / 255.0f, @@ -1078,7 +1065,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(IDirect3DDevice9Ex *iface, ((color >> 24) & 0xff) / 255.0f, }; IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); - IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface; + IDirect3DSurface9Impl *surface = unsafe_impl_from_IDirect3DSurface9(pSurface); struct wined3d_resource *wined3d_resource; struct wined3d_resource_desc desc; HRESULT hr; @@ -1092,7 +1079,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(IDirect3DDevice9Ex *iface, /* This method is only allowed with surfaces that are render targets, or * offscreen plain surfaces in D3DPOOL_DEFAULT. */ - if (!(desc.usage & WINED3DUSAGE_RENDERTARGET) && desc.pool != WINED3DPOOL_DEFAULT) + if (!(desc.usage & WINED3DUSAGE_RENDERTARGET) && desc.pool != WINED3D_POOL_DEFAULT) { wined3d_mutex_unlock(); WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n"); @@ -1109,15 +1096,19 @@ static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(IDirect3DDevice9Ex *iface, static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(IDirect3DDevice9Ex *iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, - HANDLE *pSharedHandle) + HANDLE *shared_handle) { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); HRESULT hr; TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n", - iface, Width, Height, Format, Pool, ppSurface, pSharedHandle); + iface, Width, Height, Format, Pool, ppSurface, shared_handle); - if(Pool == D3DPOOL_MANAGED ){ + if (shared_handle) + FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle); + + if (Pool == D3DPOOL_MANAGED) + { FIXME("Attempting to create a managed offscreen plain surface\n"); return D3DERR_INVALIDCALL; } @@ -1130,7 +1121,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(IDirect */ hr = IDirect3DDevice9Impl_CreateSurface(This, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */, 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, - (WINED3DPOOL)Pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */); + Pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */); return hr; } @@ -1140,7 +1131,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(IDirect3DDevice9Ex *i DWORD RenderTargetIndex, IDirect3DSurface9 *pRenderTarget) { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); - IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget; + IDirect3DSurface9Impl *pSurface = unsafe_impl_from_IDirect3DSurface9(pRenderTarget); HRESULT hr; TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, pRenderTarget); @@ -1179,24 +1170,19 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(IDirect3DDevice9Ex *i } wined3d_mutex_lock(); - hr = wined3d_device_get_render_target(This->wined3d_device, RenderTargetIndex, &wined3d_surface); - - if (FAILED(hr)) - { - FIXME("Call to IWineD3DDevice_GetRenderTarget failed, hr %#x\n", hr); - } - else if (!wined3d_surface) - { - *ppRenderTarget = NULL; - } - else + if (SUCCEEDED(hr)) { *ppRenderTarget = wined3d_surface_get_parent(wined3d_surface); IDirect3DSurface9_AddRef(*ppRenderTarget); wined3d_surface_decref(wined3d_surface); } - + else + { + if (hr != WINED3DERR_NOTFOUND) + WARN("Failed to get render target %u, hr %#x.\n", RenderTargetIndex, hr); + *ppRenderTarget = NULL; + } wined3d_mutex_unlock(); return hr; @@ -1206,13 +1192,11 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(IDirect3DDevic IDirect3DSurface9 *pZStencilSurface) { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); - IDirect3DSurface9Impl *pSurface; + IDirect3DSurface9Impl *pSurface = unsafe_impl_from_IDirect3DSurface9(pZStencilSurface); HRESULT hr; TRACE("iface %p, depth_stencil %p.\n", iface, pZStencilSurface); - pSurface = (IDirect3DSurface9Impl*)pZStencilSurface; - wined3d_mutex_lock(); hr = wined3d_device_set_depth_stencil(This->wined3d_device, pSurface ? pSurface->wined3d_surface : NULL); wined3d_mutex_unlock(); @@ -1280,18 +1264,24 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_EndScene(IDirect3DD return hr; } -static HRESULT WINAPI IDirect3DDevice9Impl_Clear(IDirect3DDevice9Ex *iface, DWORD Count, - const D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) +static HRESULT WINAPI IDirect3DDevice9Impl_Clear(IDirect3DDevice9Ex *iface, DWORD rect_count, + const D3DRECT *rects, DWORD flags, D3DCOLOR color, float z, DWORD stencil) { + const struct wined3d_color c = + { + ((color >> 16) & 0xff) / 255.0f, + ((color >> 8) & 0xff) / 255.0f, + (color & 0xff) / 255.0f, + ((color >> 24) & 0xff) / 255.0f, + }; IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); HRESULT hr; TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n", - iface, Count, pRects, Flags, Color, Z, Stencil); + iface, rect_count, rects, flags, color, z, stencil); - /* Note: D3DRECT is compatible with WINED3DRECT */ wined3d_mutex_lock(); - hr = wined3d_device_clear(This->wined3d_device, Count, (const RECT *)pRects, Flags, Color, Z, Stencil); + hr = wined3d_device_clear(This->wined3d_device, rect_count, (const RECT *)rects, flags, &c, z, stencil); wined3d_mutex_unlock(); return hr; @@ -1305,9 +1295,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(IDirect3DDevice9Ex *ifac TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix); - /* Note: D3DMATRIX is compatible with WINED3DMATRIX */ + /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */ wined3d_mutex_lock(); - hr = wined3d_device_set_transform(This->wined3d_device, State, (const WINED3DMATRIX *)lpMatrix); + hr = wined3d_device_set_transform(This->wined3d_device, State, (const struct wined3d_matrix *)lpMatrix); wined3d_mutex_unlock(); return hr; @@ -1321,9 +1311,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(IDirect3DDevice9Ex *ifac TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix); - /* Note: D3DMATRIX is compatible with WINED3DMATRIX */ + /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */ wined3d_mutex_lock(); - hr = wined3d_device_get_transform(This->wined3d_device, State, (WINED3DMATRIX *)pMatrix); + hr = wined3d_device_get_transform(This->wined3d_device, State, (struct wined3d_matrix *)pMatrix); wined3d_mutex_unlock(); return hr; @@ -1337,9 +1327,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(IDirect3DDevice9Ex TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix); - /* Note: D3DMATRIX is compatible with WINED3DMATRIX */ + /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */ wined3d_mutex_lock(); - hr = wined3d_device_multiply_transform(This->wined3d_device, State, (const WINED3DMATRIX *)pMatrix); + hr = wined3d_device_multiply_transform(This->wined3d_device, State, (const struct wined3d_matrix *)pMatrix); wined3d_mutex_unlock(); return hr; @@ -1353,9 +1343,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(IDirect3DDevice9Ex *iface TRACE("iface %p, viewport %p.\n", iface, pViewport); - /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */ + /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */ wined3d_mutex_lock(); - hr = wined3d_device_set_viewport(This->wined3d_device, (const WINED3DVIEWPORT *)pViewport); + hr = wined3d_device_set_viewport(This->wined3d_device, (const struct wined3d_viewport *)pViewport); wined3d_mutex_unlock(); return hr; @@ -1369,9 +1359,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(IDirect3DDevice9Ex *iface TRACE("iface %p, viewport %p.\n", iface, pViewport); - /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */ + /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */ wined3d_mutex_lock(); - hr = wined3d_device_get_viewport(This->wined3d_device, (WINED3DVIEWPORT *)pViewport); + hr = wined3d_device_get_viewport(This->wined3d_device, (struct wined3d_viewport *)pViewport); wined3d_mutex_unlock(); return hr; @@ -1385,9 +1375,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(IDirect3DDevice9Ex *iface TRACE("iface %p, material %p.\n", iface, pMaterial); - /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */ + /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */ wined3d_mutex_lock(); - hr = wined3d_device_set_material(This->wined3d_device, (const WINED3DMATERIAL *)pMaterial); + hr = wined3d_device_set_material(This->wined3d_device, (const struct wined3d_material *)pMaterial); wined3d_mutex_unlock(); return hr; @@ -1401,9 +1391,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(IDirect3DDevice9Ex *iface TRACE("iface %p, material %p.\n", iface, pMaterial); - /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */ + /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */ wined3d_mutex_lock(); - hr = wined3d_device_get_material(This->wined3d_device, (WINED3DMATERIAL *)pMaterial); + hr = wined3d_device_get_material(This->wined3d_device, (struct wined3d_material *)pMaterial); wined3d_mutex_unlock(); return hr; @@ -1417,9 +1407,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(IDirect3DDevice9Ex *iface, D TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight); - /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */ + /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */ wined3d_mutex_lock(); - hr = wined3d_device_set_light(This->wined3d_device, Index, (const WINED3DLIGHT *)pLight); + hr = wined3d_device_set_light(This->wined3d_device, Index, (const struct wined3d_light *)pLight); wined3d_mutex_unlock(); return hr; @@ -1433,9 +1423,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(IDirect3DDevice9Ex *iface, D TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight); - /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */ + /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */ wined3d_mutex_lock(); - hr = wined3d_device_get_light(This->wined3d_device, Index, (WINED3DLIGHT *)pLight); + hr = wined3d_device_get_light(This->wined3d_device, Index, (struct wined3d_light *)pLight); wined3d_mutex_unlock(); return hr; @@ -1636,7 +1626,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(IDirect3DDevice9Ex *ifa TRACE("iface %p, clip_status %p.\n", iface, pClipStatus); wined3d_mutex_lock(); - hr = wined3d_device_set_clip_status(This->wined3d_device, (const WINED3DCLIPSTATUS *)pClipStatus); + hr = wined3d_device_set_clip_status(This->wined3d_device, (const struct wined3d_clip_status *)pClipStatus); wined3d_mutex_unlock(); return hr; @@ -1651,7 +1641,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(IDirect3DDevice9Ex *ifa TRACE("iface %p, clip_status %p.\n", iface, pClipStatus); wined3d_mutex_lock(); - hr = wined3d_device_get_clip_status(This->wined3d_device, (WINED3DCLIPSTATUS *)pClipStatus); + hr = wined3d_device_get_clip_status(This->wined3d_device, (struct wined3d_clip_status *)pClipStatus); wined3d_mutex_unlock(); return hr; @@ -1707,41 +1697,41 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(IDirect3DDevice9Ex *iface, return hr; } -static const WINED3DTEXTURESTAGESTATETYPE tss_lookup[] = +static const enum wined3d_texture_stage_state tss_lookup[] = { - WINED3DTSS_FORCE_DWORD, /* 0, unused */ - WINED3DTSS_COLOROP, /* 1, D3DTSS_COLOROP */ - WINED3DTSS_COLORARG1, /* 2, D3DTSS_COLORARG1 */ - WINED3DTSS_COLORARG2, /* 3, D3DTSS_COLORARG2 */ - WINED3DTSS_ALPHAOP, /* 4, D3DTSS_ALPHAOP */ - WINED3DTSS_ALPHAARG1, /* 5, D3DTSS_ALPHAARG1 */ - WINED3DTSS_ALPHAARG2, /* 6, D3DTSS_ALPHAARG2 */ - WINED3DTSS_BUMPENVMAT00, /* 7, D3DTSS_BUMPENVMAT00 */ - WINED3DTSS_BUMPENVMAT01, /* 8, D3DTSS_BUMPENVMAT01 */ - WINED3DTSS_BUMPENVMAT10, /* 9, D3DTSS_BUMPENVMAT10 */ - WINED3DTSS_BUMPENVMAT11, /* 10, D3DTSS_BUMPENVMAT11 */ - WINED3DTSS_TEXCOORDINDEX, /* 11, D3DTSS_TEXCOORDINDEX */ - WINED3DTSS_FORCE_DWORD, /* 12, unused */ - WINED3DTSS_FORCE_DWORD, /* 13, unused */ - WINED3DTSS_FORCE_DWORD, /* 14, unused */ - WINED3DTSS_FORCE_DWORD, /* 15, unused */ - WINED3DTSS_FORCE_DWORD, /* 16, unused */ - WINED3DTSS_FORCE_DWORD, /* 17, unused */ - WINED3DTSS_FORCE_DWORD, /* 18, unused */ - WINED3DTSS_FORCE_DWORD, /* 19, unused */ - WINED3DTSS_FORCE_DWORD, /* 20, unused */ - WINED3DTSS_FORCE_DWORD, /* 21, unused */ - WINED3DTSS_BUMPENVLSCALE, /* 22, D3DTSS_BUMPENVLSCALE */ - WINED3DTSS_BUMPENVLOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */ - WINED3DTSS_TEXTURETRANSFORMFLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */ - WINED3DTSS_FORCE_DWORD, /* 25, unused */ - WINED3DTSS_COLORARG0, /* 26, D3DTSS_COLORARG0 */ - WINED3DTSS_ALPHAARG0, /* 27, D3DTSS_ALPHAARG0 */ - WINED3DTSS_RESULTARG, /* 28, D3DTSS_RESULTARG */ - WINED3DTSS_FORCE_DWORD, /* 29, unused */ - WINED3DTSS_FORCE_DWORD, /* 30, unused */ - WINED3DTSS_FORCE_DWORD, /* 31, unused */ - WINED3DTSS_CONSTANT, /* 32, D3DTSS_CONSTANT */ + WINED3D_TSS_INVALID, /* 0, unused */ + WINED3D_TSS_COLOR_OP, /* 1, D3DTSS_COLOROP */ + WINED3D_TSS_COLOR_ARG1, /* 2, D3DTSS_COLORARG1 */ + WINED3D_TSS_COLOR_ARG2, /* 3, D3DTSS_COLORARG2 */ + WINED3D_TSS_ALPHA_OP, /* 4, D3DTSS_ALPHAOP */ + WINED3D_TSS_ALPHA_ARG1, /* 5, D3DTSS_ALPHAARG1 */ + WINED3D_TSS_ALPHA_ARG2, /* 6, D3DTSS_ALPHAARG2 */ + WINED3D_TSS_BUMPENV_MAT00, /* 7, D3DTSS_BUMPENVMAT00 */ + WINED3D_TSS_BUMPENV_MAT01, /* 8, D3DTSS_BUMPENVMAT01 */ + WINED3D_TSS_BUMPENV_MAT10, /* 9, D3DTSS_BUMPENVMAT10 */ + WINED3D_TSS_BUMPENV_MAT11, /* 10, D3DTSS_BUMPENVMAT11 */ + WINED3D_TSS_TEXCOORD_INDEX, /* 11, D3DTSS_TEXCOORDINDEX */ + WINED3D_TSS_INVALID, /* 12, unused */ + WINED3D_TSS_INVALID, /* 13, unused */ + WINED3D_TSS_INVALID, /* 14, unused */ + WINED3D_TSS_INVALID, /* 15, unused */ + WINED3D_TSS_INVALID, /* 16, unused */ + WINED3D_TSS_INVALID, /* 17, unused */ + WINED3D_TSS_INVALID, /* 18, unused */ + WINED3D_TSS_INVALID, /* 19, unused */ + WINED3D_TSS_INVALID, /* 20, unused */ + WINED3D_TSS_INVALID, /* 21, unused */ + WINED3D_TSS_BUMPENV_LSCALE, /* 22, D3DTSS_BUMPENVLSCALE */ + WINED3D_TSS_BUMPENV_LOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */ + WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */ + WINED3D_TSS_INVALID, /* 25, unused */ + WINED3D_TSS_COLOR_ARG0, /* 26, D3DTSS_COLORARG0 */ + WINED3D_TSS_ALPHA_ARG0, /* 27, D3DTSS_ALPHAARG0 */ + WINED3D_TSS_RESULT_ARG, /* 28, D3DTSS_RESULTARG */ + WINED3D_TSS_INVALID, /* 29, unused */ + WINED3D_TSS_INVALID, /* 30, unused */ + WINED3D_TSS_INVALID, /* 31, unused */ + WINED3D_TSS_CONSTANT, /* 32, D3DTSS_CONSTANT */ }; static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(IDirect3DDevice9Ex *iface, @@ -1834,61 +1824,33 @@ static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(IDirect3DDevice9Ex *if static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex *iface, UINT PaletteNumber, const PALETTEENTRY *pEntries) { - IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); - HRESULT hr; + FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface, PaletteNumber, pEntries); - TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries); - - wined3d_mutex_lock(); - hr = wined3d_device_set_palette_entries(This->wined3d_device, PaletteNumber, pEntries); - wined3d_mutex_unlock(); - - return hr; + return D3DERR_INVALIDCALL; } static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(IDirect3DDevice9Ex *iface, UINT PaletteNumber, PALETTEENTRY *pEntries) { - IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); - HRESULT hr; + FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface, PaletteNumber, pEntries); - TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries); - - wined3d_mutex_lock(); - hr = wined3d_device_get_palette_entries(This->wined3d_device, PaletteNumber, pEntries); - wined3d_mutex_unlock(); - - return hr; + return D3DERR_INVALIDCALL; } static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(IDirect3DDevice9Ex *iface, UINT PaletteNumber) { - IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); - HRESULT hr; + FIXME("iface %p, palette_idx %u unimplemented.\n", iface, PaletteNumber); - TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber); - - wined3d_mutex_lock(); - hr = wined3d_device_set_current_texture_palette(This->wined3d_device, PaletteNumber); - wined3d_mutex_unlock(); - - return hr; + return D3DERR_INVALIDCALL; } static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(IDirect3DDevice9Ex *iface, UINT *PaletteNumber) { - IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); - HRESULT hr; + FIXME("iface %p, palette_idx %p.\n", iface, PaletteNumber); - TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber); - - wined3d_mutex_lock(); - hr = wined3d_device_get_current_texture_palette(This->wined3d_device, PaletteNumber); - wined3d_mutex_unlock(); - - return hr; + return D3DERR_INVALIDCALL; } static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(IDirect3DDevice9Ex *iface, @@ -2065,9 +2027,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(IDirect3DDevice9Ex *i IDirect3DVertexDeclaration9 *pVertexDecl, DWORD Flags) { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); + IDirect3DVertexBuffer9Impl *dest = unsafe_impl_from_IDirect3DVertexBuffer9(pDestBuffer); IDirect3DVertexDeclaration9Impl *Decl = (IDirect3DVertexDeclaration9Impl *) pVertexDecl; HRESULT hr; - IDirect3DVertexBuffer9Impl *dest = (IDirect3DVertexBuffer9Impl *) pDestBuffer; TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n", iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags); @@ -2305,7 +2267,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(IDirect3DDevice9Ex } TRACE("Created vertex shader %p.\n", object); - *shader = (IDirect3DVertexShader9 *)object; + *shader = &object->IDirect3DVertexShader9_iface; return D3D_OK; } @@ -2314,13 +2276,14 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(IDirect3DDevice9Ex *i IDirect3DVertexShader9 *shader) { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); + IDirect3DVertexShader9Impl *shader_obj = unsafe_impl_from_IDirect3DVertexShader9(shader); HRESULT hr; TRACE("iface %p, shader %p.\n", iface, shader); wined3d_mutex_lock(); hr = wined3d_device_set_vertex_shader(This->wined3d_device, - shader ? ((IDirect3DVertexShader9Impl *)shader)->wined3d_shader : NULL); + shader_obj ? shader_obj->wined3d_shader : NULL); wined3d_mutex_unlock(); return hr; @@ -2461,6 +2424,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(IDirect3DDevice9Ex *i UINT StreamNumber, IDirect3DVertexBuffer9 *pStreamData, UINT OffsetInBytes, UINT Stride) { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); + IDirect3DVertexBuffer9Impl *streamdata = unsafe_impl_from_IDirect3DVertexBuffer9(pStreamData); HRESULT hr; TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n", @@ -2468,7 +2432,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(IDirect3DDevice9Ex *i wined3d_mutex_lock(); hr = wined3d_device_set_stream_source(This->wined3d_device, StreamNumber, - pStreamData ? ((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer : NULL, + streamdata ? streamdata->wineD3DVertexBuffer : NULL, OffsetInBytes, Stride); wined3d_mutex_unlock(); @@ -2544,8 +2508,8 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(IDirect3DDevice9Ex *iface, IDirect3DIndexBuffer9 *pIndexData) { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); + IDirect3DIndexBuffer9Impl *ib = unsafe_impl_from_IDirect3DIndexBuffer9(pIndexData); HRESULT hr; - IDirect3DIndexBuffer9Impl *ib = (IDirect3DIndexBuffer9Impl *) pIndexData; TRACE("iface %p, buffer %p.\n", iface, pIndexData); @@ -2614,7 +2578,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(IDirect3DDevice9Ex } TRACE("Created pixel shader %p.\n", object); - *shader = (IDirect3DPixelShader9 *)object; + *shader = &object->IDirect3DPixelShader9_iface; return D3D_OK; } @@ -2623,13 +2587,14 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(IDirect3DDevice9Ex *if IDirect3DPixelShader9 *shader) { IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); + IDirect3DPixelShader9Impl *shader_obj = unsafe_impl_from_IDirect3DPixelShader9(shader); HRESULT hr; TRACE("iface %p, shader %p.\n", iface, shader); wined3d_mutex_lock(); hr = wined3d_device_set_pixel_shader(This->wined3d_device, - shader ? ((IDirect3DPixelShader9Impl *)shader)->wined3d_shader : NULL); + shader_obj ? shader_obj->wined3d_shader : NULL); wined3d_mutex_unlock(); return hr; @@ -2765,7 +2730,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(IDirect3DDevice9Ex *ifa wined3d_mutex_lock(); hr = wined3d_device_draw_rect_patch(This->wined3d_device, Handle, - pNumSegs, (const WINED3DRECTPATCH_INFO *)pRectPatchInfo); + pNumSegs, (const struct wined3d_rect_patch_info *)pRectPatchInfo); wined3d_mutex_unlock(); return hr; @@ -2782,7 +2747,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(IDirect3DDevice9Ex *ifac wined3d_mutex_lock(); hr = wined3d_device_draw_tri_patch(This->wined3d_device, Handle, - pNumSegs, (const WINED3DTRIPATCH_INFO *)pTriPatchInfo); + pNumSegs, (const struct wined3d_tri_patch_info *)pTriPatchInfo); wined3d_mutex_unlock(); return hr; @@ -2931,6 +2896,9 @@ static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateRenderTargetEx(IDirect3DDevic iface, width, height, format, multisample_type, multisample_quality, lockable, surface, shared_handle, usage); + if (shared_handle) + FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle); + return E_NOTIMPL; } @@ -2953,6 +2921,9 @@ static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx(IDirect iface, width, height, format, multisample_type, multisample_quality, discard, surface, shared_handle, usage); + if (shared_handle) + FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle); + return E_NOTIMPL; } @@ -3124,9 +3095,14 @@ static void CDECL device_parent_wined3d_device_created(struct wined3d_device_par TRACE("device_parent %p, device %p.\n", device_parent, device); } +static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent) +{ + TRACE("device_parent %p.\n", device_parent); +} + static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent *device_parent, void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage, - WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, struct wined3d_surface **surface) + enum wined3d_pool pool, UINT level, enum wined3d_cubemap_face face, struct wined3d_surface **surface) { struct IDirect3DDevice9Impl *device = device_from_device_parent(device_parent); IDirect3DSurface9Impl *d3d_surface; @@ -3137,7 +3113,7 @@ static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent * "\tpool %#x, level %u, face %u, surface %p.\n", device_parent, container_parent, width, height, format, usage, pool, level, face, surface); - if (pool == WINED3DPOOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC)) + if (pool == WINED3D_POOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC)) lockable = FALSE; hr = IDirect3DDevice9Impl_CreateSurface(device, width, height, @@ -3156,7 +3132,7 @@ static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent * IDirect3DDevice9Ex_Release(d3d_surface->parentDevice); d3d_surface->parentDevice = NULL; - IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface); + IDirect3DSurface9_Release(&d3d_surface->IDirect3DSurface9_iface); d3d_surface->forwardReference = container_parent; return hr; @@ -3164,7 +3140,7 @@ static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent * static HRESULT CDECL device_parent_create_rendertarget(struct wined3d_device_parent *device_parent, void *container_parent, UINT width, UINT height, enum wined3d_format_id format, - WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable, + enum wined3d_multisample_type multisample_type, DWORD multisample_quality, BOOL lockable, struct wined3d_surface **surface) { struct IDirect3DDevice9Impl *device = device_from_device_parent(device_parent); @@ -3190,13 +3166,13 @@ static HRESULT CDECL device_parent_create_rendertarget(struct wined3d_device_par d3d_surface->container = container_parent; /* Implicit surfaces are created with an refcount of 0 */ - IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface); + IDirect3DSurface9_Release(&d3d_surface->IDirect3DSurface9_iface); return hr; } static HRESULT CDECL device_parent_create_depth_stencil(struct wined3d_device_parent *device_parent, - UINT width, UINT height, enum wined3d_format_id format, WINED3DMULTISAMPLE_TYPE multisample_type, + UINT width, UINT height, enum wined3d_format_id format, enum wined3d_multisample_type multisample_type, DWORD multisample_quality, BOOL discard, struct wined3d_surface **surface) { struct IDirect3DDevice9Impl *device = device_from_device_parent(device_parent); @@ -3220,14 +3196,14 @@ static HRESULT CDECL device_parent_create_depth_stencil(struct wined3d_device_pa wined3d_surface_incref(*surface); d3d_surface->container = (IUnknown *)&device->IDirect3DDevice9Ex_iface; /* Implicit surfaces are created with an refcount of 0 */ - IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface); + IDirect3DSurface9_Release(&d3d_surface->IDirect3DSurface9_iface); return hr; } static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *device_parent, void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format, - WINED3DPOOL pool, DWORD usage, struct wined3d_volume **volume) + enum wined3d_pool pool, DWORD usage, struct wined3d_volume **volume) { struct IDirect3DDevice9Impl *device = device_from_device_parent(device_parent); IDirect3DVolume9Impl *object; @@ -3268,30 +3244,30 @@ static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *d } static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent, - WINED3DPRESENT_PARAMETERS *present_parameters, struct wined3d_swapchain **swapchain) + struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain) { struct IDirect3DDevice9Impl *device = device_from_device_parent(device_parent); D3DPRESENT_PARAMETERS local_parameters; IDirect3DSwapChain9 *d3d_swapchain; HRESULT hr; - TRACE("device_parent %p, present_parameters %p, swapchain %p\n", device_parent, present_parameters, swapchain); + TRACE("device_parent %p, desc %p, swapchain %p\n", device_parent, desc, swapchain); /* Copy the presentation parameters */ - local_parameters.BackBufferWidth = present_parameters->BackBufferWidth; - local_parameters.BackBufferHeight = present_parameters->BackBufferHeight; - local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat); - local_parameters.BackBufferCount = present_parameters->BackBufferCount; - local_parameters.MultiSampleType = present_parameters->MultiSampleType; - local_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality; - local_parameters.SwapEffect = present_parameters->SwapEffect; - local_parameters.hDeviceWindow = present_parameters->hDeviceWindow; - local_parameters.Windowed = present_parameters->Windowed; - local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil; - local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat); - local_parameters.Flags = present_parameters->Flags; - local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz; - local_parameters.PresentationInterval = present_parameters->PresentationInterval; + local_parameters.BackBufferWidth = desc->backbuffer_width; + local_parameters.BackBufferHeight = desc->backbuffer_height; + local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(desc->backbuffer_format); + local_parameters.BackBufferCount = desc->backbuffer_count; + local_parameters.MultiSampleType = desc->multisample_type; + local_parameters.MultiSampleQuality = desc->multisample_quality; + local_parameters.SwapEffect = desc->swap_effect; + local_parameters.hDeviceWindow = desc->device_window; + local_parameters.Windowed = desc->windowed; + local_parameters.EnableAutoDepthStencil = desc->enable_auto_depth_stencil; + local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(desc->auto_depth_stencil_format); + local_parameters.Flags = desc->flags; + local_parameters.FullScreen_RefreshRateInHz = desc->refresh_rate; + local_parameters.PresentationInterval = desc->swap_interval; hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain(&device->IDirect3DDevice9Ex_iface, &local_parameters, &d3d_swapchain); @@ -3307,20 +3283,20 @@ static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain); /* Copy back the presentation parameters */ - present_parameters->BackBufferWidth = local_parameters.BackBufferWidth; - present_parameters->BackBufferHeight = local_parameters.BackBufferHeight; - present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat); - present_parameters->BackBufferCount = local_parameters.BackBufferCount; - present_parameters->MultiSampleType = local_parameters.MultiSampleType; - present_parameters->MultiSampleQuality = local_parameters.MultiSampleQuality; - present_parameters->SwapEffect = local_parameters.SwapEffect; - present_parameters->hDeviceWindow = local_parameters.hDeviceWindow; - present_parameters->Windowed = local_parameters.Windowed; - present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil; - present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat); - present_parameters->Flags = local_parameters.Flags; - present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz; - present_parameters->PresentationInterval = local_parameters.PresentationInterval; + desc->backbuffer_width = local_parameters.BackBufferWidth; + desc->backbuffer_height = local_parameters.BackBufferHeight; + desc->backbuffer_format = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat); + desc->backbuffer_count = local_parameters.BackBufferCount; + desc->multisample_type = local_parameters.MultiSampleType; + desc->multisample_quality = local_parameters.MultiSampleQuality; + desc->swap_effect = local_parameters.SwapEffect; + desc->device_window = local_parameters.hDeviceWindow; + desc->windowed = local_parameters.Windowed; + desc->enable_auto_depth_stencil = local_parameters.EnableAutoDepthStencil; + desc->auto_depth_stencil_format = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat); + desc->flags = local_parameters.Flags; + desc->refresh_rate = local_parameters.FullScreen_RefreshRateInHz; + desc->swap_interval = local_parameters.PresentationInterval; return hr; } @@ -3328,6 +3304,7 @@ static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent static const struct wined3d_device_parent_ops d3d9_wined3d_device_parent_ops = { device_parent_wined3d_device_created, + device_parent_mode_changed, device_parent_create_surface, device_parent_create_rendertarget, device_parent_create_depth_stencil, @@ -3342,15 +3319,21 @@ static void setup_fpu(void) __asm__ volatile ("fnstcw %0" : "=m" (cw)); cw = (cw & ~0xf3f) | 0x3f; __asm__ volatile ("fldcw %0" : : "m" (cw)); +#elif defined(__i386__) && defined(_MSC_VER) + WORD cw; + __asm fnstcw cw; + cw = (cw & ~0xf3f) | 0x3f; + __asm fldcw cw; #else FIXME("FPU setup not implemented for this platform.\n"); #endif } -HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT adapter, D3DDEVTYPE device_type, - HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode) +HRESULT device_init(IDirect3DDevice9Impl *device, IDirect3D9Impl *parent, struct wined3d *wined3d, + UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags, + D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode) { - WINED3DPRESENT_PARAMETERS *wined3d_parameters; + struct wined3d_swapchain_desc *swapchain_desc; UINT i, count = 1; HRESULT hr; @@ -3364,7 +3347,7 @@ HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu(); wined3d_mutex_lock(); - hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags, + hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags, 4, &device->device_parent, &device->wined3d_device); if (FAILED(hr)) { @@ -3407,8 +3390,8 @@ HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT } } - wined3d_parameters = HeapAlloc(GetProcessHeap(), 0, sizeof(*wined3d_parameters) * count); - if (!wined3d_parameters) + swapchain_desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain_desc) * count); + if (!swapchain_desc) { ERR("Failed to allocate wined3d parameters.\n"); wined3d_device_decref(device->wined3d_device); @@ -3418,30 +3401,30 @@ HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT for (i = 0; i < count; ++i) { - wined3d_parameters[i].BackBufferWidth = parameters[i].BackBufferWidth; - wined3d_parameters[i].BackBufferHeight = parameters[i].BackBufferHeight; - wined3d_parameters[i].BackBufferFormat = wined3dformat_from_d3dformat(parameters[i].BackBufferFormat); - wined3d_parameters[i].BackBufferCount = parameters[i].BackBufferCount; - wined3d_parameters[i].MultiSampleType = parameters[i].MultiSampleType; - wined3d_parameters[i].MultiSampleQuality = parameters[i].MultiSampleQuality; - wined3d_parameters[i].SwapEffect = parameters[i].SwapEffect; - wined3d_parameters[i].hDeviceWindow = parameters[i].hDeviceWindow; - wined3d_parameters[i].Windowed = parameters[i].Windowed; - wined3d_parameters[i].EnableAutoDepthStencil = parameters[i].EnableAutoDepthStencil; - wined3d_parameters[i].AutoDepthStencilFormat = + swapchain_desc[i].backbuffer_width = parameters[i].BackBufferWidth; + swapchain_desc[i].backbuffer_height = parameters[i].BackBufferHeight; + swapchain_desc[i].backbuffer_format = wined3dformat_from_d3dformat(parameters[i].BackBufferFormat); + swapchain_desc[i].backbuffer_count = parameters[i].BackBufferCount; + swapchain_desc[i].multisample_type = parameters[i].MultiSampleType; + swapchain_desc[i].multisample_quality = parameters[i].MultiSampleQuality; + swapchain_desc[i].swap_effect = parameters[i].SwapEffect; + swapchain_desc[i].device_window = parameters[i].hDeviceWindow; + swapchain_desc[i].windowed = parameters[i].Windowed; + swapchain_desc[i].enable_auto_depth_stencil = parameters[i].EnableAutoDepthStencil; + swapchain_desc[i].auto_depth_stencil_format = wined3dformat_from_d3dformat(parameters[i].AutoDepthStencilFormat); - wined3d_parameters[i].Flags = parameters[i].Flags; - wined3d_parameters[i].FullScreen_RefreshRateInHz = parameters[i].FullScreen_RefreshRateInHz; - wined3d_parameters[i].PresentationInterval = parameters[i].PresentationInterval; - wined3d_parameters[i].AutoRestoreDisplayMode = TRUE; + swapchain_desc[i].flags = parameters[i].Flags; + swapchain_desc[i].refresh_rate = parameters[i].FullScreen_RefreshRateInHz; + swapchain_desc[i].swap_interval = parameters[i].PresentationInterval; + swapchain_desc[i].auto_restore_display_mode = TRUE; } - hr = wined3d_device_init_3d(device->wined3d_device, wined3d_parameters); + hr = wined3d_device_init_3d(device->wined3d_device, swapchain_desc); if (FAILED(hr)) { WARN("Failed to initialize 3D, hr %#x.\n", hr); wined3d_device_release_focus_window(device->wined3d_device); - HeapFree(GetProcessHeap(), 0, wined3d_parameters); + HeapFree(GetProcessHeap(), 0, swapchain_desc); wined3d_device_decref(device->wined3d_device); wined3d_mutex_unlock(); return hr; @@ -3451,23 +3434,23 @@ HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT for (i = 0; i < count; ++i) { - parameters[i].BackBufferWidth = wined3d_parameters[i].BackBufferWidth; - parameters[i].BackBufferHeight = wined3d_parameters[i].BackBufferHeight; - parameters[i].BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters[i].BackBufferFormat); - parameters[i].BackBufferCount = wined3d_parameters[i].BackBufferCount; - parameters[i].MultiSampleType = wined3d_parameters[i].MultiSampleType; - parameters[i].MultiSampleQuality = wined3d_parameters[i].MultiSampleQuality; - parameters[i].SwapEffect = wined3d_parameters[i].SwapEffect; - parameters[i].hDeviceWindow = wined3d_parameters[i].hDeviceWindow; - parameters[i].Windowed = wined3d_parameters[i].Windowed; - parameters[i].EnableAutoDepthStencil = wined3d_parameters[i].EnableAutoDepthStencil; + parameters[i].BackBufferWidth = swapchain_desc[i].backbuffer_width; + parameters[i].BackBufferHeight = swapchain_desc[i].backbuffer_height; + parameters[i].BackBufferFormat = d3dformat_from_wined3dformat(swapchain_desc[i].backbuffer_format); + parameters[i].BackBufferCount = swapchain_desc[i].backbuffer_count; + parameters[i].MultiSampleType = swapchain_desc[i].multisample_type; + parameters[i].MultiSampleQuality = swapchain_desc[i].multisample_quality; + parameters[i].SwapEffect = swapchain_desc[i].swap_effect; + parameters[i].hDeviceWindow = swapchain_desc[i].device_window; + parameters[i].Windowed = swapchain_desc[i].windowed; + parameters[i].EnableAutoDepthStencil = swapchain_desc[i].enable_auto_depth_stencil; parameters[i].AutoDepthStencilFormat = - d3dformat_from_wined3dformat(wined3d_parameters[i].AutoDepthStencilFormat); - parameters[i].Flags = wined3d_parameters[i].Flags; - parameters[i].FullScreen_RefreshRateInHz = wined3d_parameters[i].FullScreen_RefreshRateInHz; - parameters[i].PresentationInterval = wined3d_parameters[i].PresentationInterval; + d3dformat_from_wined3dformat(swapchain_desc[i].auto_depth_stencil_format); + parameters[i].Flags = swapchain_desc[i].flags; + parameters[i].FullScreen_RefreshRateInHz = swapchain_desc[i].refresh_rate; + parameters[i].PresentationInterval = swapchain_desc[i].swap_interval; } - HeapFree(GetProcessHeap(), 0, wined3d_parameters); + HeapFree(GetProcessHeap(), 0, swapchain_desc); /* Initialize the converted declaration array. This creates a valid pointer * and when adding decls HeapReAlloc() can be used without further checking. */ @@ -3483,5 +3466,8 @@ HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT return E_OUTOFMEMORY; } + device->d3d_parent = &parent->IDirect3D9Ex_iface; + IDirect3D9_AddRef(device->d3d_parent); + return D3D_OK; } diff --git a/reactos/dll/directx/wine/d3d9/directx.c b/reactos/dll/directx/wine/d3d9/directx.c index 7a22c30223d..218676ad72b 100644 --- a/reactos/dll/directx/wine/d3d9/directx.c +++ b/reactos/dll/directx/wine/d3d9/directx.c @@ -103,25 +103,25 @@ static HRESULT WINAPI IDirect3D9Impl_RegisterSoftwareDevice(IDirect3D9Ex *ifac return hr; } -static UINT WINAPI IDirect3D9Impl_GetAdapterCount(IDirect3D9Ex *iface) +static UINT WINAPI IDirect3D9Impl_GetAdapterCount(IDirect3D9Ex *iface) { IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface); - HRESULT hr; + UINT ret; TRACE("iface %p.\n", iface); wined3d_mutex_lock(); - hr = wined3d_get_adapter_count(This->WineD3D); + ret = wined3d_get_adapter_count(This->WineD3D); wined3d_mutex_unlock(); - return hr; + return ret; } static HRESULT WINAPI IDirect3D9Impl_GetAdapterIdentifier(IDirect3D9Ex *iface, UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9 *pIdentifier) { IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface); - WINED3DADAPTER_IDENTIFIER adapter_id; + struct wined3d_adapter_identifier adapter_id; HRESULT hr; TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n", @@ -153,7 +153,7 @@ static UINT WINAPI IDirect3D9Impl_GetAdapterModeCount(IDirect3D9Ex *iface, UINT D3DFORMAT Format) { IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface); - HRESULT hr; + UINT ret; TRACE("iface %p, adapter %u, format %#x.\n", iface, Adapter, Format); @@ -163,10 +163,10 @@ static UINT WINAPI IDirect3D9Impl_GetAdapterModeCount(IDirect3D9Ex *iface, UINT } wined3d_mutex_lock(); - hr = wined3d_get_adapter_mode_count(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format)); + ret = wined3d_get_adapter_mode_count(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format)); wined3d_mutex_unlock(); - return hr; + return ret; } static HRESULT WINAPI IDirect3D9Impl_EnumAdapterModes(IDirect3D9Ex *iface, UINT Adapter, @@ -185,7 +185,7 @@ static HRESULT WINAPI IDirect3D9Impl_EnumAdapterModes(IDirect3D9Ex *iface, UINT wined3d_mutex_lock(); hr = wined3d_enum_adapter_modes(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format), - Mode, (WINED3DDISPLAYMODE *) pMode); + Mode, (struct wined3d_display_mode *)pMode); wined3d_mutex_unlock(); if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format); @@ -202,7 +202,7 @@ static HRESULT WINAPI IDirect3D9Impl_GetAdapterDisplayMode(IDirect3D9Ex *iface, TRACE("iface %p, adapter %u, mode %p.\n", iface, Adapter, pMode); wined3d_mutex_lock(); - hr = wined3d_get_adapter_display_mode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *)pMode); + hr = wined3d_get_adapter_display_mode(This->WineD3D, Adapter, (struct wined3d_display_mode *)pMode); wined3d_mutex_unlock(); if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format); @@ -232,38 +232,26 @@ static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormat(IDirect3D9Ex *iface, UINT D3DFORMAT CheckFormat) { IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface); + enum wined3d_resource_type wined3d_rtype; HRESULT hr; - WINED3DRESOURCETYPE WineD3DRType; TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n", iface, Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat); - /* This format is nothing special and it is supported perfectly. - * However, ati and nvidia driver on windows do not mark this format as - * supported (tested with the dxCapsViewer) and pretending to - * support this format uncovers a bug in Battlefield 1942 (fonts are missing) - * So do the same as Windows drivers and pretend not to support it on dx8 and 9 - */ - if(CheckFormat == D3DFMT_R8G8B8) - { - WARN("D3DFMT_R8G8B8 is not available on windows, returning D3DERR_NOTAVAILABLE\n"); - return D3DERR_NOTAVAILABLE; - } - switch(RType) { case D3DRTYPE_VERTEXBUFFER: case D3DRTYPE_INDEXBUFFER: - WineD3DRType = WINED3DRTYPE_BUFFER; + wined3d_rtype = WINED3D_RTYPE_BUFFER; break; default: - WineD3DRType = RType; + wined3d_rtype = RType; break; } wined3d_mutex_lock(); hr = wined3d_check_device_format(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat), - Usage, WineD3DRType, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL); + Usage, wined3d_rtype, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL); wined3d_mutex_unlock(); return hr; @@ -325,7 +313,8 @@ static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormatConversion(IDirect3D9Ex *i void filter_caps(D3DCAPS9* pCaps) { - + DWORD ps_minor_version[] = {0, 4, 0, 0}; + DWORD vs_minor_version[] = {0, 1, 0, 0}; DWORD textureFilterCaps = D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MINFLINEAR | D3DPTFILTERCAPS_MINFANISOTROPIC | D3DPTFILTERCAPS_MINFPYRAMIDALQUAD | D3DPTFILTERCAPS_MINFGAUSSIANQUAD| @@ -381,6 +370,22 @@ void filter_caps(D3DCAPS9* pCaps) pCaps->MaxVertexShaderConst = min(D3D9_MAX_VERTEX_SHADER_CONSTANTF, pCaps->MaxVertexShaderConst); pCaps->NumSimultaneousRTs = min(D3D9_MAX_SIMULTANEOUS_RENDERTARGETS, pCaps->NumSimultaneousRTs); + + if (pCaps->PixelShaderVersion > 3) + pCaps->PixelShaderVersion = D3DPS_VERSION(3,0); + else + { + DWORD major = pCaps->PixelShaderVersion; + pCaps->PixelShaderVersion = D3DPS_VERSION(major,ps_minor_version[major]); + } + + if (pCaps->VertexShaderVersion > 3) + pCaps->VertexShaderVersion = D3DVS_VERSION(3,0); + else + { + DWORD major = pCaps->VertexShaderVersion; + pCaps->VertexShaderVersion = D3DVS_VERSION(major,vs_minor_version[major]); + } } static HRESULT WINAPI IDirect3D9Impl_GetDeviceCaps(IDirect3D9Ex *iface, UINT Adapter, @@ -449,7 +454,7 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9Impl_CreateDevice(IDirect3D9Ex return E_OUTOFMEMORY; } - hr = device_init(object, This->WineD3D, adapter, device_type, focus_window, flags, parameters, NULL); + hr = device_init(object, This, This->WineD3D, adapter, device_type, focus_window, flags, parameters, NULL); if (FAILED(hr)) { WARN("Failed to initialize device, hr %#x.\n", hr); @@ -468,7 +473,7 @@ static UINT WINAPI IDirect3D9ExImpl_GetAdapterModeCountEx(IDirect3D9Ex *iface, { FIXME("iface %p, adapter %u, filter %p stub!\n", iface, adapter, filter); - return E_NOTIMPL; + return 0; } static HRESULT WINAPI IDirect3D9ExImpl_EnumAdapterModesEx(IDirect3D9Ex *iface, @@ -507,7 +512,7 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9ExImpl_CreateDeviceEx(IDirect3 return E_OUTOFMEMORY; } - hr = device_init(object, d3d9->WineD3D, adapter, device_type, focus_window, flags, parameters, mode); + hr = device_init(object, d3d9, d3d9->WineD3D, adapter, device_type, focus_window, flags, parameters, mode); if (FAILED(hr)) { WARN("Failed to initialize device, hr %#x.\n", hr); @@ -524,7 +529,7 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9ExImpl_CreateDeviceEx(IDirect3 static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterLUID(IDirect3D9Ex *iface, UINT adapter, LUID *luid) { IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface); - WINED3DADAPTER_IDENTIFIER adapter_id; + struct wined3d_adapter_identifier adapter_id; HRESULT hr; TRACE("iface %p, adapter %u, luid %p.\n", iface, adapter, luid); diff --git a/reactos/dll/directx/wine/d3d9/shader.c b/reactos/dll/directx/wine/d3d9/shader.c index c36600dcd60..b9de07c3d3b 100644 --- a/reactos/dll/directx/wine/d3d9/shader.c +++ b/reactos/dll/directx/wine/d3d9/shader.c @@ -18,10 +18,16 @@ */ #include "config.h" +#include #include "d3d9_private.h" WINE_DEFAULT_DEBUG_CHANNEL(d3d9); +static inline IDirect3DVertexShader9Impl *impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface) +{ + return CONTAINING_RECORD(iface, IDirect3DVertexShader9Impl, IDirect3DVertexShader9_iface); +} + static HRESULT WINAPI d3d9_vertexshader_QueryInterface(IDirect3DVertexShader9 *iface, REFIID riid, void **object) { TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); @@ -42,7 +48,7 @@ static HRESULT WINAPI d3d9_vertexshader_QueryInterface(IDirect3DVertexShader9 *i static ULONG WINAPI d3d9_vertexshader_AddRef(IDirect3DVertexShader9 *iface) { - IDirect3DVertexShader9Impl *shader = (IDirect3DVertexShader9Impl *)iface; + IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface); ULONG refcount = InterlockedIncrement(&shader->ref); TRACE("%p increasing refcount to %u.\n", iface, refcount); @@ -60,7 +66,7 @@ static ULONG WINAPI d3d9_vertexshader_AddRef(IDirect3DVertexShader9 *iface) static ULONG WINAPI d3d9_vertexshader_Release(IDirect3DVertexShader9 *iface) { - IDirect3DVertexShader9Impl *shader = (IDirect3DVertexShader9Impl *)iface; + IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface); ULONG refcount = InterlockedDecrement(&shader->ref); TRACE("%p decreasing refcount to %u.\n", iface, refcount); @@ -82,9 +88,11 @@ static ULONG WINAPI d3d9_vertexshader_Release(IDirect3DVertexShader9 *iface) static HRESULT WINAPI d3d9_vertexshader_GetDevice(IDirect3DVertexShader9 *iface, IDirect3DDevice9 **device) { + IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface); + TRACE("iface %p, device %p.\n", iface, device); - *device = (IDirect3DDevice9 *)((IDirect3DVertexShader9Impl *)iface)->parentDevice; + *device = (IDirect3DDevice9 *)shader->parentDevice; IDirect3DDevice9_AddRef(*device); TRACE("Returning device %p.\n", *device); @@ -95,12 +103,13 @@ static HRESULT WINAPI d3d9_vertexshader_GetDevice(IDirect3DVertexShader9 *iface, static HRESULT WINAPI d3d9_vertexshader_GetFunction(IDirect3DVertexShader9 *iface, void *data, UINT *data_size) { + IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface); HRESULT hr; TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size); wined3d_mutex_lock(); - hr = wined3d_shader_get_byte_code(((IDirect3DVertexShader9Impl *)iface)->wined3d_shader, data, data_size); + hr = wined3d_shader_get_byte_code(shader->wined3d_shader, data, data_size); wined3d_mutex_unlock(); return hr; @@ -132,11 +141,11 @@ HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader, IDirect3DDevice9Im HRESULT hr; shader->ref = 1; - shader->lpVtbl = &d3d9_vertexshader_vtbl; + shader->IDirect3DVertexShader9_iface.lpVtbl = &d3d9_vertexshader_vtbl; wined3d_mutex_lock(); hr = wined3d_shader_create_vs(device->wined3d_device, byte_code, NULL, - shader, &d3d9_vertexshader_wined3d_parent_ops, &shader->wined3d_shader); + shader, &d3d9_vertexshader_wined3d_parent_ops, &shader->wined3d_shader, 3); wined3d_mutex_unlock(); if (FAILED(hr)) { @@ -150,6 +159,20 @@ HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader, IDirect3DDevice9Im return D3D_OK; } +IDirect3DVertexShader9Impl *unsafe_impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &d3d9_vertexshader_vtbl); + + return impl_from_IDirect3DVertexShader9(iface); +} + +static inline IDirect3DPixelShader9Impl *impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface) +{ + return CONTAINING_RECORD(iface, IDirect3DPixelShader9Impl, IDirect3DPixelShader9_iface); +} + static HRESULT WINAPI d3d9_pixelshader_QueryInterface(IDirect3DPixelShader9 *iface, REFIID riid, void **object) { TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); @@ -170,7 +193,7 @@ static HRESULT WINAPI d3d9_pixelshader_QueryInterface(IDirect3DPixelShader9 *ifa static ULONG WINAPI d3d9_pixelshader_AddRef(IDirect3DPixelShader9 *iface) { - IDirect3DPixelShader9Impl *shader = (IDirect3DPixelShader9Impl *)iface; + IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface); ULONG refcount = InterlockedIncrement(&shader->ref); TRACE("%p increasing refcount to %u.\n", iface, refcount); @@ -188,7 +211,7 @@ static ULONG WINAPI d3d9_pixelshader_AddRef(IDirect3DPixelShader9 *iface) static ULONG WINAPI d3d9_pixelshader_Release(IDirect3DPixelShader9 *iface) { - IDirect3DPixelShader9Impl *shader = (IDirect3DPixelShader9Impl *)iface; + IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface); ULONG refcount = InterlockedDecrement(&shader->ref); TRACE("%p decreasing refcount to %u.\n", iface, refcount); @@ -208,11 +231,14 @@ static ULONG WINAPI d3d9_pixelshader_Release(IDirect3DPixelShader9 *iface) return refcount; } -static HRESULT WINAPI d3d9_pixelshader_GetDevice(IDirect3DPixelShader9 *iface, IDirect3DDevice9 **device) +static HRESULT WINAPI d3d9_pixelshader_GetDevice(IDirect3DPixelShader9 *iface, + IDirect3DDevice9 **device) { + IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface); + TRACE("iface %p, device %p.\n", iface, device); - *device = (IDirect3DDevice9 *)((IDirect3DPixelShader9Impl *)iface)->parentDevice; + *device = (IDirect3DDevice9 *)shader->parentDevice; IDirect3DDevice9_AddRef(*device); TRACE("Returning device %p.\n", *device); @@ -220,14 +246,16 @@ static HRESULT WINAPI d3d9_pixelshader_GetDevice(IDirect3DPixelShader9 *iface, I return D3D_OK; } -static HRESULT WINAPI d3d9_pixelshader_GetFunction(IDirect3DPixelShader9 *iface, void *data, UINT *data_size) +static HRESULT WINAPI d3d9_pixelshader_GetFunction(IDirect3DPixelShader9 *iface, void *data, + UINT *data_size) { + IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface); HRESULT hr; TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size); wined3d_mutex_lock(); - hr = wined3d_shader_get_byte_code(((IDirect3DPixelShader9Impl *)iface)->wined3d_shader, data, data_size); + hr = wined3d_shader_get_byte_code(shader->wined3d_shader, data, data_size); wined3d_mutex_unlock(); return hr; @@ -259,11 +287,11 @@ HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader, IDirect3DDevice9Impl HRESULT hr; shader->ref = 1; - shader->lpVtbl = &d3d9_pixelshader_vtbl; + shader->IDirect3DPixelShader9_iface.lpVtbl = &d3d9_pixelshader_vtbl; wined3d_mutex_lock(); hr = wined3d_shader_create_ps(device->wined3d_device, byte_code, NULL, shader, - &d3d9_pixelshader_wined3d_parent_ops, &shader->wined3d_shader); + &d3d9_pixelshader_wined3d_parent_ops, &shader->wined3d_shader, 3); wined3d_mutex_unlock(); if (FAILED(hr)) { @@ -276,3 +304,12 @@ HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader, IDirect3DDevice9Impl return D3D_OK; } + +IDirect3DPixelShader9Impl *unsafe_impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &d3d9_pixelshader_vtbl); + + return impl_from_IDirect3DPixelShader9(iface); +} diff --git a/reactos/dll/directx/wine/d3d9/stateblock.c b/reactos/dll/directx/wine/d3d9/stateblock.c index 06f8aedba75..6ecf596591b 100644 --- a/reactos/dll/directx/wine/d3d9/stateblock.c +++ b/reactos/dll/directx/wine/d3d9/stateblock.c @@ -150,7 +150,7 @@ HRESULT stateblock_init(IDirect3DStateBlock9Impl *stateblock, IDirect3DDevice9Im { wined3d_mutex_lock(); hr = wined3d_stateblock_create(device->wined3d_device, - (WINED3DSTATEBLOCKTYPE)type, &stateblock->wined3d_stateblock); + (enum wined3d_stateblock_type)type, &stateblock->wined3d_stateblock); wined3d_mutex_unlock(); if (FAILED(hr)) { diff --git a/reactos/dll/directx/wine/d3d9/surface.c b/reactos/dll/directx/wine/d3d9/surface.c index 1d66bde2d90..cb2546f0eeb 100644 --- a/reactos/dll/directx/wine/d3d9/surface.c +++ b/reactos/dll/directx/wine/d3d9/surface.c @@ -20,13 +20,21 @@ */ #include "config.h" +#include #include "d3d9_private.h" WINE_DEFAULT_DEBUG_CHANNEL(d3d9); +static inline IDirect3DSurface9Impl *impl_from_IDirect3DSurface9(IDirect3DSurface9 *iface) +{ + return CONTAINING_RECORD(iface, IDirect3DSurface9Impl, IDirect3DSurface9_iface); +} + /* IDirect3DSurface9 IUnknown parts follow: */ -static HRESULT WINAPI IDirect3DSurface9Impl_QueryInterface(LPDIRECT3DSURFACE9 iface, REFIID riid, LPVOID* ppobj) { - IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface; +static HRESULT WINAPI IDirect3DSurface9Impl_QueryInterface(IDirect3DSurface9 *iface, REFIID riid, + void **ppobj) +{ + IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj); @@ -43,8 +51,9 @@ static HRESULT WINAPI IDirect3DSurface9Impl_QueryInterface(LPDIRECT3DSURFACE9 if return E_NOINTERFACE; } -static ULONG WINAPI IDirect3DSurface9Impl_AddRef(LPDIRECT3DSURFACE9 iface) { - IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface; +static ULONG WINAPI IDirect3DSurface9Impl_AddRef(IDirect3DSurface9 *iface) +{ + IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); TRACE("iface %p.\n", iface); @@ -71,8 +80,9 @@ static ULONG WINAPI IDirect3DSurface9Impl_AddRef(LPDIRECT3DSURFACE9 iface) { } -static ULONG WINAPI IDirect3DSurface9Impl_Release(LPDIRECT3DSURFACE9 iface) { - IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface; +static ULONG WINAPI IDirect3DSurface9Impl_Release(IDirect3DSurface9 *iface) +{ + IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); TRACE("iface %p.\n", iface); @@ -102,9 +112,10 @@ static ULONG WINAPI IDirect3DSurface9Impl_Release(LPDIRECT3DSURFACE9 iface) { } /* IDirect3DSurface9 IDirect3DResource9 Interface follow: */ -static HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(IDirect3DSurface9 *iface, IDirect3DDevice9 **device) +static HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(IDirect3DSurface9 *iface, + IDirect3DDevice9 **device) { - IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface; + IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); TRACE("iface %p, device %p.\n", iface, device); @@ -133,49 +144,61 @@ static HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(IDirect3DSurface9 *iface, return D3D_OK; } -static HRESULT WINAPI IDirect3DSurface9Impl_SetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) { - IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface; +static HRESULT WINAPI IDirect3DSurface9Impl_SetPrivateData(IDirect3DSurface9 *iface, REFGUID guid, + const void *data, DWORD data_size, DWORD flags) +{ + IDirect3DSurface9Impl *surface = impl_from_IDirect3DSurface9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", - iface, debugstr_guid(refguid), pData, SizeOfData, Flags); + iface, debugstr_guid(guid), data, data_size, flags); wined3d_mutex_lock(); - hr = wined3d_surface_set_private_data(This->wined3d_surface, refguid, pData, SizeOfData, Flags); + resource = wined3d_surface_get_resource(surface->wined3d_surface); + hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags); wined3d_mutex_unlock(); return hr; } -static HRESULT WINAPI IDirect3DSurface9Impl_GetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) { - IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface; +static HRESULT WINAPI IDirect3DSurface9Impl_GetPrivateData(IDirect3DSurface9 *iface, REFGUID guid, + void *data, DWORD *data_size) +{ + IDirect3DSurface9Impl *surface = impl_from_IDirect3DSurface9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %p.\n", - iface, debugstr_guid(refguid), pData, pSizeOfData); + iface, debugstr_guid(guid), data, data_size); wined3d_mutex_lock(); - hr = wined3d_surface_get_private_data(This->wined3d_surface, refguid, pData, pSizeOfData); + resource = wined3d_surface_get_resource(surface->wined3d_surface); + hr = wined3d_resource_get_private_data(resource, guid, data, data_size); wined3d_mutex_unlock(); return hr; } -static HRESULT WINAPI IDirect3DSurface9Impl_FreePrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid) { - IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface; +static HRESULT WINAPI IDirect3DSurface9Impl_FreePrivateData(IDirect3DSurface9 *iface, REFGUID guid) +{ + IDirect3DSurface9Impl *surface = impl_from_IDirect3DSurface9(iface); + struct wined3d_resource *resource; HRESULT hr; - TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid)); + TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid)); wined3d_mutex_lock(); - hr = wined3d_surface_free_private_data(This->wined3d_surface, refguid); + resource = wined3d_surface_get_resource(surface->wined3d_surface); + hr = wined3d_resource_free_private_data(resource, guid); wined3d_mutex_unlock(); return hr; } -static DWORD WINAPI IDirect3DSurface9Impl_SetPriority(LPDIRECT3DSURFACE9 iface, DWORD PriorityNew) { - IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface; +static DWORD WINAPI IDirect3DSurface9Impl_SetPriority(IDirect3DSurface9 *iface, DWORD PriorityNew) +{ + IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); HRESULT hr; TRACE("iface %p, priority %u.\n", iface, PriorityNew); @@ -187,8 +210,9 @@ static DWORD WINAPI IDirect3DSurface9Impl_SetPriority(LPDIRECT3DSURFACE9 iface, return hr; } -static DWORD WINAPI IDirect3DSurface9Impl_GetPriority(LPDIRECT3DSURFACE9 iface) { - IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface; +static DWORD WINAPI IDirect3DSurface9Impl_GetPriority(IDirect3DSurface9 *iface) +{ + IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); HRESULT hr; TRACE("iface %p.\n", iface); @@ -200,8 +224,9 @@ static DWORD WINAPI IDirect3DSurface9Impl_GetPriority(LPDIRECT3DSURFACE9 iface) return hr; } -static void WINAPI IDirect3DSurface9Impl_PreLoad(LPDIRECT3DSURFACE9 iface) { - IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface; +static void WINAPI IDirect3DSurface9Impl_PreLoad(IDirect3DSurface9 *iface) +{ + IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); TRACE("iface %p.\n", iface); @@ -218,8 +243,10 @@ static D3DRESOURCETYPE WINAPI IDirect3DSurface9Impl_GetType(IDirect3DSurface9 *i } /* IDirect3DSurface9 Interface follow: */ -static HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(LPDIRECT3DSURFACE9 iface, REFIID riid, void** ppContainer) { - IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface; +static HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(IDirect3DSurface9 *iface, REFIID riid, + void **ppContainer) +{ + IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); HRESULT res; TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), ppContainer); @@ -235,7 +262,7 @@ static HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(LPDIRECT3DSURFACE9 ifac static HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(IDirect3DSurface9 *iface, D3DSURFACE_DESC *desc) { - IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface; + IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); struct wined3d_resource_desc wined3d_desc; struct wined3d_resource *wined3d_resource; @@ -248,7 +275,7 @@ static HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(IDirect3DSurface9 *iface, D3 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format); desc->Type = wined3d_desc.resource_type; - desc->Usage = wined3d_desc.usage; + desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->MultiSampleType = wined3d_desc.multisample_type; desc->MultiSampleQuality = wined3d_desc.multisample_quality; @@ -258,21 +285,24 @@ static HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(IDirect3DSurface9 *iface, D3 return D3D_OK; } -static HRESULT WINAPI IDirect3DSurface9Impl_LockRect(LPDIRECT3DSURFACE9 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) { - IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface; +static HRESULT WINAPI IDirect3DSurface9Impl_LockRect(IDirect3DSurface9 *iface, + D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags) +{ + IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); HRESULT hr; TRACE("iface %p, locked_rect %p, rect %p, flags %#x.\n", iface, pLockedRect, pRect, Flags); wined3d_mutex_lock(); - hr = wined3d_surface_map(This->wined3d_surface, (WINED3DLOCKED_RECT *)pLockedRect, pRect, Flags); + hr = wined3d_surface_map(This->wined3d_surface, (struct wined3d_mapped_rect *)pLockedRect, pRect, Flags); wined3d_mutex_unlock(); return hr; } -static HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface) { - IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface; +static HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(IDirect3DSurface9 *iface) +{ + IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); HRESULT hr; TRACE("iface %p.\n", iface); @@ -288,8 +318,9 @@ static HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface) } } -static HRESULT WINAPI IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface, HDC* phdc) { - IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface; +static HRESULT WINAPI IDirect3DSurface9Impl_GetDC(IDirect3DSurface9 *iface, HDC* phdc) +{ + IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); HRESULT hr; TRACE("iface %p, hdc %p.\n", iface, phdc); @@ -308,8 +339,9 @@ static HRESULT WINAPI IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface, HDC* return hr; } -static HRESULT WINAPI IDirect3DSurface9Impl_ReleaseDC(LPDIRECT3DSURFACE9 iface, HDC hdc) { - IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface; +static HRESULT WINAPI IDirect3DSurface9Impl_ReleaseDC(IDirect3DSurface9 *iface, HDC hdc) +{ + IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); HRESULT hr; TRACE("iface %p, hdc %p.\n", iface, hdc); @@ -363,9 +395,10 @@ HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *devic UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level, DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality) { + DWORD flags = 0; HRESULT hr; - surface->lpVtbl = &Direct3DSurface9_Vtbl; + surface->IDirect3DSurface9_iface.lpVtbl = &Direct3DSurface9_Vtbl; surface->ref = 1; switch (format) @@ -391,10 +424,15 @@ HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *devic multisample_quality = 0; } + if (lockable) + flags |= WINED3D_SURFACE_MAPPABLE; + if (discard) + flags |= WINED3D_SURFACE_DISCARD; + wined3d_mutex_lock(); hr = wined3d_surface_create(device->wined3d_device, width, height, wined3dformat_from_d3dformat(format), - lockable, discard, level, usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, multisample_type, - multisample_quality, SURFACE_OPENGL, surface, &d3d9_surface_wined3d_parent_ops, &surface->wined3d_surface); + level, usage & WINED3DUSAGE_MASK, (enum wined3d_pool)pool, multisample_type, multisample_quality, + SURFACE_OPENGL, flags, surface, &d3d9_surface_wined3d_parent_ops, &surface->wined3d_surface); wined3d_mutex_unlock(); if (FAILED(hr)) { @@ -407,3 +445,12 @@ HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *devic return D3D_OK; } + +IDirect3DSurface9Impl *unsafe_impl_from_IDirect3DSurface9(IDirect3DSurface9 *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &Direct3DSurface9_Vtbl); + + return impl_from_IDirect3DSurface9(iface); +} diff --git a/reactos/dll/directx/wine/d3d9/swapchain.c b/reactos/dll/directx/wine/d3d9/swapchain.c index 26437079970..7ad002189f2 100644 --- a/reactos/dll/directx/wine/d3d9/swapchain.c +++ b/reactos/dll/directx/wine/d3d9/swapchain.c @@ -98,15 +98,17 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DSwapChain9Impl_Present(LPDIRECT return hr; } -static HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface) { +static HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(IDirect3DSwapChain9 *iface, + IDirect3DSurface9 *pDestSurface) +{ IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface; + IDirect3DSurface9Impl *dst = unsafe_impl_from_IDirect3DSurface9(pDestSurface); HRESULT hr; TRACE("iface %p, surface %p.\n", iface, pDestSurface); wined3d_mutex_lock(); - hr = wined3d_swapchain_get_front_buffer_data(This->wined3d_swapchain, - ((IDirect3DSurface9Impl *)pDestSurface)->wined3d_surface); + hr = wined3d_swapchain_get_front_buffer_data(This->wined3d_swapchain, dst->wined3d_surface); wined3d_mutex_unlock(); return hr; @@ -124,7 +126,7 @@ static HRESULT WINAPI IDirect3DSwapChain9Impl_GetBackBuffer(IDirect3DSwapChain9 wined3d_mutex_lock(); hr = wined3d_swapchain_get_back_buffer(This->wined3d_swapchain, - iBackBuffer, (WINED3DBACKBUFFER_TYPE)Type, &wined3d_surface); + iBackBuffer, (enum wined3d_backbuffer_type)Type, &wined3d_surface); if (SUCCEEDED(hr) && wined3d_surface) { *ppBackBuffer = wined3d_surface_get_parent(wined3d_surface); @@ -144,7 +146,7 @@ static HRESULT WINAPI IDirect3DSwapChain9Impl_GetRasterStatus(LPDIRECT3DSWAPCHAI TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus); wined3d_mutex_lock(); - hr = wined3d_swapchain_get_raster_status(This->wined3d_swapchain, (WINED3DRASTER_STATUS *)pRasterStatus); + hr = wined3d_swapchain_get_raster_status(This->wined3d_swapchain, (struct wined3d_raster_status *)pRasterStatus); wined3d_mutex_unlock(); return hr; @@ -157,7 +159,7 @@ static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDisplayMode(LPDIRECT3DSWAPCHAIN TRACE("iface %p, mode %p.\n", iface, pMode); wined3d_mutex_lock(); - hr = wined3d_swapchain_get_display_mode(This->wined3d_swapchain, (WINED3DDISPLAYMODE *)pMode); + hr = wined3d_swapchain_get_display_mode(This->wined3d_swapchain, (struct wined3d_display_mode *)pMode); wined3d_mutex_unlock(); if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format); @@ -179,31 +181,33 @@ static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDevice(IDirect3DSwapChain9 *ifa return D3D_OK; } -static HRESULT WINAPI IDirect3DSwapChain9Impl_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) { +static HRESULT WINAPI IDirect3DSwapChain9Impl_GetPresentParameters(IDirect3DSwapChain9 *iface, + D3DPRESENT_PARAMETERS *pPresentationParameters) +{ IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface; - WINED3DPRESENT_PARAMETERS winePresentParameters; + struct wined3d_swapchain_desc desc; HRESULT hr; TRACE("iface %p, parameters %p.\n", iface, pPresentationParameters); wined3d_mutex_lock(); - hr = wined3d_swapchain_get_present_parameters(This->wined3d_swapchain, &winePresentParameters); + hr = wined3d_swapchain_get_desc(This->wined3d_swapchain, &desc); wined3d_mutex_unlock(); - pPresentationParameters->BackBufferWidth = winePresentParameters.BackBufferWidth; - pPresentationParameters->BackBufferHeight = winePresentParameters.BackBufferHeight; - pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(winePresentParameters.BackBufferFormat); - pPresentationParameters->BackBufferCount = winePresentParameters.BackBufferCount; - pPresentationParameters->MultiSampleType = winePresentParameters.MultiSampleType; - pPresentationParameters->MultiSampleQuality = winePresentParameters.MultiSampleQuality; - pPresentationParameters->SwapEffect = winePresentParameters.SwapEffect; - pPresentationParameters->hDeviceWindow = winePresentParameters.hDeviceWindow; - pPresentationParameters->Windowed = winePresentParameters.Windowed; - pPresentationParameters->EnableAutoDepthStencil = winePresentParameters.EnableAutoDepthStencil; - pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(winePresentParameters.AutoDepthStencilFormat); - pPresentationParameters->Flags = winePresentParameters.Flags; - pPresentationParameters->FullScreen_RefreshRateInHz = winePresentParameters.FullScreen_RefreshRateInHz; - pPresentationParameters->PresentationInterval = winePresentParameters.PresentationInterval; + pPresentationParameters->BackBufferWidth = desc.backbuffer_width; + pPresentationParameters->BackBufferHeight = desc.backbuffer_height; + pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(desc.backbuffer_format); + pPresentationParameters->BackBufferCount = desc.backbuffer_count; + pPresentationParameters->MultiSampleType = desc.multisample_type; + pPresentationParameters->MultiSampleQuality = desc.multisample_quality; + pPresentationParameters->SwapEffect = desc.swap_effect; + pPresentationParameters->hDeviceWindow = desc.device_window; + pPresentationParameters->Windowed = desc.windowed; + pPresentationParameters->EnableAutoDepthStencil = desc.enable_auto_depth_stencil; + pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(desc.auto_depth_stencil_format); + pPresentationParameters->Flags = desc.flags; + pPresentationParameters->FullScreen_RefreshRateInHz = desc.refresh_rate; + pPresentationParameters->PresentationInterval = desc.swap_interval; return hr; } @@ -236,48 +240,48 @@ static const struct wined3d_parent_ops d3d9_swapchain_wined3d_parent_ops = HRESULT swapchain_init(IDirect3DSwapChain9Impl *swapchain, IDirect3DDevice9Impl *device, D3DPRESENT_PARAMETERS *present_parameters) { - WINED3DPRESENT_PARAMETERS wined3d_parameters; + struct wined3d_swapchain_desc desc; HRESULT hr; swapchain->ref = 1; swapchain->lpVtbl = &Direct3DSwapChain9_Vtbl; - wined3d_parameters.BackBufferWidth = present_parameters->BackBufferWidth; - wined3d_parameters.BackBufferHeight = present_parameters->BackBufferHeight; - wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat); - wined3d_parameters.BackBufferCount = max(1, present_parameters->BackBufferCount); - wined3d_parameters.MultiSampleType = present_parameters->MultiSampleType; - wined3d_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality; - wined3d_parameters.SwapEffect = present_parameters->SwapEffect; - wined3d_parameters.hDeviceWindow = present_parameters->hDeviceWindow; - wined3d_parameters.Windowed = present_parameters->Windowed; - wined3d_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil; - wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat); - wined3d_parameters.Flags = present_parameters->Flags; - wined3d_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz; - wined3d_parameters.PresentationInterval = present_parameters->PresentationInterval; - wined3d_parameters.AutoRestoreDisplayMode = TRUE; + desc.backbuffer_width = present_parameters->BackBufferWidth; + desc.backbuffer_height = present_parameters->BackBufferHeight; + desc.backbuffer_format = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat); + desc.backbuffer_count = max(1, present_parameters->BackBufferCount); + desc.multisample_type = present_parameters->MultiSampleType; + desc.multisample_quality = present_parameters->MultiSampleQuality; + desc.swap_effect = present_parameters->SwapEffect; + desc.device_window = present_parameters->hDeviceWindow; + desc.windowed = present_parameters->Windowed; + desc.enable_auto_depth_stencil = present_parameters->EnableAutoDepthStencil; + desc.auto_depth_stencil_format = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat); + desc.flags = present_parameters->Flags; + desc.refresh_rate = present_parameters->FullScreen_RefreshRateInHz; + desc.swap_interval = present_parameters->PresentationInterval; + desc.auto_restore_display_mode = TRUE; wined3d_mutex_lock(); - hr = wined3d_swapchain_create(device->wined3d_device, &wined3d_parameters, + hr = wined3d_swapchain_create(device->wined3d_device, &desc, SURFACE_OPENGL, swapchain, &d3d9_swapchain_wined3d_parent_ops, &swapchain->wined3d_swapchain); wined3d_mutex_unlock(); - present_parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth; - present_parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight; - present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat); - present_parameters->BackBufferCount = wined3d_parameters.BackBufferCount; - present_parameters->MultiSampleType = wined3d_parameters.MultiSampleType; - present_parameters->MultiSampleQuality = wined3d_parameters.MultiSampleQuality; - present_parameters->SwapEffect = wined3d_parameters.SwapEffect; - present_parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow; - present_parameters->Windowed = wined3d_parameters.Windowed; - present_parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil; - present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat); - present_parameters->Flags = wined3d_parameters.Flags; - present_parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz; - present_parameters->PresentationInterval = wined3d_parameters.PresentationInterval; + present_parameters->BackBufferWidth = desc.backbuffer_width; + present_parameters->BackBufferHeight = desc.backbuffer_height; + present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(desc.backbuffer_format); + present_parameters->BackBufferCount = desc.backbuffer_count; + present_parameters->MultiSampleType = desc.multisample_type; + present_parameters->MultiSampleQuality = desc.multisample_quality; + present_parameters->SwapEffect = desc.swap_effect; + present_parameters->hDeviceWindow = desc.device_window; + present_parameters->Windowed = desc.windowed; + present_parameters->EnableAutoDepthStencil = desc.enable_auto_depth_stencil; + present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(desc.auto_depth_stencil_format); + present_parameters->Flags = desc.flags; + present_parameters->FullScreen_RefreshRateInHz = desc.refresh_rate; + present_parameters->PresentationInterval = desc.swap_interval; if (FAILED(hr)) { diff --git a/reactos/dll/directx/wine/d3d9/texture.c b/reactos/dll/directx/wine/d3d9/texture.c index d1df0f5ee7b..49a0fe697f9 100644 --- a/reactos/dll/directx/wine/d3d9/texture.c +++ b/reactos/dll/directx/wine/d3d9/texture.c @@ -108,13 +108,15 @@ static HRESULT WINAPI IDirect3DTexture9Impl_SetPrivateData(IDirect3DTexture9 *if REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) { IDirect3DTexture9Impl *This = impl_from_IDirect3DTexture9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", iface, debugstr_guid(refguid), pData, SizeOfData, Flags); wined3d_mutex_lock(); - hr = wined3d_texture_set_private_data(This->wined3d_texture, refguid, pData, SizeOfData, Flags); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags); wined3d_mutex_unlock(); return hr; @@ -124,13 +126,15 @@ static HRESULT WINAPI IDirect3DTexture9Impl_GetPrivateData(IDirect3DTexture9 *if REFGUID refguid, void *pData, DWORD *pSizeOfData) { IDirect3DTexture9Impl *This = impl_from_IDirect3DTexture9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %p.\n", iface, debugstr_guid(refguid), pData, pSizeOfData); wined3d_mutex_lock(); - hr = wined3d_texture_get_private_data(This->wined3d_texture, refguid, pData, pSizeOfData); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData); wined3d_mutex_unlock(); return hr; @@ -140,12 +144,14 @@ static HRESULT WINAPI IDirect3DTexture9Impl_FreePrivateData(IDirect3DTexture9 *i REFGUID refguid) { IDirect3DTexture9Impl *This = impl_from_IDirect3DTexture9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid)); wined3d_mutex_lock(); - hr = wined3d_texture_free_private_data(This->wined3d_texture, refguid); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_free_private_data(resource, refguid); wined3d_mutex_unlock(); return hr; @@ -192,16 +198,9 @@ static void WINAPI IDirect3DTexture9Impl_PreLoad(IDirect3DTexture9 *iface) static D3DRESOURCETYPE WINAPI IDirect3DTexture9Impl_GetType(IDirect3DTexture9 *iface) { - IDirect3DTexture9Impl *This = impl_from_IDirect3DTexture9(iface); - HRESULT ret; - TRACE("iface %p.\n", iface); - wined3d_mutex_lock(); - ret = wined3d_texture_get_type(This->wined3d_texture); - wined3d_mutex_unlock(); - - return ret; + return D3DRTYPE_TEXTURE; } /* IDirect3DTexture9 IDirect3DBaseTexture9 Interface follow: */ @@ -256,7 +255,7 @@ static HRESULT WINAPI IDirect3DTexture9Impl_SetAutoGenFilterType(IDirect3DTextur TRACE("iface %p, filter_type %#x.\n", iface, FilterType); wined3d_mutex_lock(); - hr = wined3d_texture_set_autogen_filter_type(This->wined3d_texture, (WINED3DTEXTUREFILTERTYPE)FilterType); + hr = wined3d_texture_set_autogen_filter_type(This->wined3d_texture, (enum wined3d_texture_filter_type)FilterType); wined3d_mutex_unlock(); return hr; @@ -306,7 +305,7 @@ static HRESULT WINAPI IDirect3DTexture9Impl_GetLevelDesc(IDirect3DTexture9 *ifac wined3d_resource_get_desc(sub_resource, &wined3d_desc); desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format); desc->Type = wined3d_desc.resource_type; - desc->Usage = wined3d_desc.usage; + desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->MultiSampleType = wined3d_desc.multisample_type; desc->MultiSampleQuality = wined3d_desc.multisample_quality; @@ -393,14 +392,14 @@ static HRESULT WINAPI IDirect3DTexture9Impl_AddDirtyRect(IDirect3DTexture9 *ifac hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, NULL); else { - WINED3DBOX dirty_region; + struct wined3d_box dirty_region; - dirty_region.Left = dirty_rect->left; - dirty_region.Top = dirty_rect->top; - dirty_region.Right = dirty_rect->right; - dirty_region.Bottom = dirty_rect->bottom; - dirty_region.Front = 0; - dirty_region.Back = 1; + dirty_region.left = dirty_rect->left; + dirty_region.top = dirty_rect->top; + dirty_region.right = dirty_rect->right; + dirty_region.bottom = dirty_rect->bottom; + dirty_region.front = 0; + dirty_region.back = 1; hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, &dirty_region); } wined3d_mutex_unlock(); diff --git a/reactos/dll/directx/wine/d3d9/vertexdeclaration.c b/reactos/dll/directx/wine/d3d9/vertexdeclaration.c index 62246147d3c..3b2198eb8a4 100644 --- a/reactos/dll/directx/wine/d3d9/vertexdeclaration.c +++ b/reactos/dll/directx/wine/d3d9/vertexdeclaration.c @@ -320,8 +320,8 @@ static const struct wined3d_parent_ops d3d9_vertexdeclaration_wined3d_parent_ops d3d9_vertexdeclaration_wined3d_object_destroyed, }; -static HRESULT convert_to_wined3d_declaration(const D3DVERTEXELEMENT9* d3d9_elements, - WINED3DVERTEXELEMENT **wined3d_elements, UINT *element_count) +static HRESULT convert_to_wined3d_declaration(const D3DVERTEXELEMENT9 *d3d9_elements, + struct wined3d_vertex_element **wined3d_elements, UINT *element_count) { const D3DVERTEXELEMENT9* element; UINT count = 1; @@ -337,7 +337,7 @@ static HRESULT convert_to_wined3d_declaration(const D3DVERTEXELEMENT9* d3d9_elem /* Skip the END element */ --count; - *wined3d_elements = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WINED3DVERTEXELEMENT)); + *wined3d_elements = HeapAlloc(GetProcessHeap(), 0, count * sizeof(**wined3d_elements)); if (!*wined3d_elements) { FIXME("Memory allocation failed\n"); return D3DERR_OUTOFVIDEOMEMORY; @@ -368,7 +368,7 @@ static HRESULT convert_to_wined3d_declaration(const D3DVERTEXELEMENT9* d3d9_elem HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration9Impl *declaration, IDirect3DDevice9Impl *device, const D3DVERTEXELEMENT9 *elements) { - WINED3DVERTEXELEMENT *wined3d_elements; + struct wined3d_vertex_element *wined3d_elements; UINT wined3d_element_count; UINT element_count; HRESULT hr; diff --git a/reactos/dll/directx/wine/d3d9/volume.c b/reactos/dll/directx/wine/d3d9/volume.c index ba495b644d0..58e78274570 100644 --- a/reactos/dll/directx/wine/d3d9/volume.c +++ b/reactos/dll/directx/wine/d3d9/volume.c @@ -126,13 +126,15 @@ static HRESULT WINAPI IDirect3DVolume9Impl_SetPrivateData(IDirect3DVolume9 *ifac const void *pData, DWORD SizeOfData, DWORD Flags) { IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", iface, debugstr_guid(refguid), pData, SizeOfData, Flags); wined3d_mutex_lock(); - hr = wined3d_volume_set_private_data(This->wined3d_volume, refguid, pData, SizeOfData, Flags); + resource = wined3d_volume_get_resource(This->wined3d_volume); + hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags); wined3d_mutex_unlock(); return hr; @@ -142,13 +144,15 @@ static HRESULT WINAPI IDirect3DVolume9Impl_GetPrivateData(IDirect3DVolume9 *ifac void *pData, DWORD *pSizeOfData) { IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %p.\n", iface, debugstr_guid(refguid), pData, pSizeOfData); wined3d_mutex_lock(); - hr = wined3d_volume_get_private_data(This->wined3d_volume, refguid, pData, pSizeOfData); + resource = wined3d_volume_get_resource(This->wined3d_volume); + hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData); wined3d_mutex_unlock(); return hr; @@ -157,12 +161,14 @@ static HRESULT WINAPI IDirect3DVolume9Impl_GetPrivateData(IDirect3DVolume9 *ifac static HRESULT WINAPI IDirect3DVolume9Impl_FreePrivateData(IDirect3DVolume9 *iface, REFGUID refguid) { IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid)); wined3d_mutex_lock(); - hr = wined3d_volume_free_private_data(This->wined3d_volume, refguid); + resource = wined3d_volume_get_resource(This->wined3d_volume); + hr = wined3d_resource_free_private_data(resource, refguid); wined3d_mutex_unlock(); return hr; @@ -200,7 +206,7 @@ static HRESULT WINAPI IDirect3DVolume9Impl_GetDesc(IDirect3DVolume9 *iface, D3DV desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format); desc->Type = wined3d_desc.resource_type; - desc->Usage = wined3d_desc.usage; + desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->Width = wined3d_desc.width; desc->Height = wined3d_desc.height; @@ -219,8 +225,8 @@ static HRESULT WINAPI IDirect3DVolume9Impl_LockBox(IDirect3DVolume9 *iface, iface, pLockedVolume, pBox, Flags); wined3d_mutex_lock(); - hr = wined3d_volume_map(This->wined3d_volume, (WINED3DLOCKED_BOX *)pLockedVolume, - (const WINED3DBOX *)pBox, Flags); + hr = wined3d_volume_map(This->wined3d_volume, (struct wined3d_mapped_box *)pLockedVolume, + (const struct wined3d_box *)pBox, Flags); wined3d_mutex_unlock(); return hr; @@ -268,7 +274,7 @@ static const struct wined3d_parent_ops d3d9_volume_wined3d_parent_ops = }; HRESULT volume_init(IDirect3DVolume9Impl *volume, IDirect3DDevice9Impl *device, UINT width, UINT height, - UINT depth, DWORD usage, enum wined3d_format_id format, WINED3DPOOL pool) + UINT depth, DWORD usage, enum wined3d_format_id format, enum wined3d_pool pool) { HRESULT hr; diff --git a/reactos/dll/directx/wine/d3d9/volumetexture.c b/reactos/dll/directx/wine/d3d9/volumetexture.c index 9528e9b8dd5..d6d625b559e 100644 --- a/reactos/dll/directx/wine/d3d9/volumetexture.c +++ b/reactos/dll/directx/wine/d3d9/volumetexture.c @@ -107,13 +107,15 @@ static HRESULT WINAPI IDirect3DVolumeTexture9Impl_SetPrivateData(IDirect3DVolume REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) { IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", iface, debugstr_guid(refguid), pData, SizeOfData, Flags); wined3d_mutex_lock(); - hr = wined3d_texture_set_private_data(This->wined3d_texture, refguid, pData, SizeOfData, Flags); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags); wined3d_mutex_unlock(); return hr; @@ -123,13 +125,15 @@ static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetPrivateData(IDirect3DVolume REFGUID refguid, void *pData, DWORD *pSizeOfData) { IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %p.\n", iface, debugstr_guid(refguid), pData, pSizeOfData); wined3d_mutex_lock(); - hr = wined3d_texture_get_private_data(This->wined3d_texture, refguid, pData, pSizeOfData); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData); wined3d_mutex_unlock(); return hr; @@ -139,12 +143,14 @@ static HRESULT WINAPI IDirect3DVolumeTexture9Impl_FreePrivateData(IDirect3DVolum REFGUID refguid) { IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid)); wined3d_mutex_lock(); - hr = wined3d_texture_free_private_data(This->wined3d_texture, refguid); + resource = wined3d_texture_get_resource(This->wined3d_texture); + hr = wined3d_resource_free_private_data(resource, refguid); wined3d_mutex_unlock(); return hr; @@ -192,16 +198,9 @@ static void WINAPI IDirect3DVolumeTexture9Impl_PreLoad(IDirect3DVolumeTexture9 * static D3DRESOURCETYPE WINAPI IDirect3DVolumeTexture9Impl_GetType(IDirect3DVolumeTexture9 *iface) { - IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface); - D3DRESOURCETYPE type; - TRACE("iface %p.\n", iface); - wined3d_mutex_lock(); - type = wined3d_texture_get_type(This->wined3d_texture); - wined3d_mutex_unlock(); - - return type; + return D3DRTYPE_VOLUMETEXTURE; } static DWORD WINAPI IDirect3DVolumeTexture9Impl_SetLOD(IDirect3DVolumeTexture9 *iface, DWORD LODNew) @@ -255,7 +254,7 @@ static HRESULT WINAPI IDirect3DVolumeTexture9Impl_SetAutoGenFilterType(IDirect3D TRACE("iface %p, filter_type %#x.\n", iface, FilterType); wined3d_mutex_lock(); - hr = wined3d_texture_set_autogen_filter_type(This->wined3d_texture, (WINED3DTEXTUREFILTERTYPE)FilterType); + hr = wined3d_texture_set_autogen_filter_type(This->wined3d_texture, (enum wined3d_texture_filter_type)FilterType); wined3d_mutex_unlock(); return hr; @@ -305,7 +304,7 @@ static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetLevelDesc(IDirect3DVolumeTe wined3d_resource_get_desc(sub_resource, &wined3d_desc); desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format); desc->Type = wined3d_desc.resource_type; - desc->Usage = wined3d_desc.usage; + desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->Width = wined3d_desc.width; desc->Height = wined3d_desc.height; @@ -387,7 +386,7 @@ static HRESULT WINAPI IDirect3DVolumeTexture9Impl_AddDirtyBox(IDirect3DVolumeTex TRACE("iface %p, dirty_box %p.\n", iface, dirty_box); wined3d_mutex_lock(); - hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const WINED3DBOX *)dirty_box); + hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const struct wined3d_box *)dirty_box); wined3d_mutex_unlock(); return hr; diff --git a/reactos/dll/directx/wine/ddraw/CMakeLists.txt b/reactos/dll/directx/wine/ddraw/CMakeLists.txt index 300c52f52c6..58a609c2afe 100644 --- a/reactos/dll/directx/wine/ddraw/CMakeLists.txt +++ b/reactos/dll/directx/wine/ddraw/CMakeLists.txt @@ -16,19 +16,18 @@ spec2def(ddraw.dll ddraw.spec) list(APPEND SOURCE clipper.c ddraw.c + ddraw.rc device.c executebuffer.c light.c main.c material.c palette.c - regsvr.c stubs.c surface.c utils.c vertexbuffer.c viewport.c - version.rc ${CMAKE_CURRENT_BINARY_DIR}/ddraw_stubs.c ${CMAKE_CURRENT_BINARY_DIR}/ddraw.def) diff --git a/reactos/dll/directx/wine/ddraw/clipper.c b/reactos/dll/directx/wine/ddraw/clipper.c index c9290c85a50..81e9e8b8f9d 100644 --- a/reactos/dll/directx/wine/ddraw/clipper.c +++ b/reactos/dll/directx/wine/ddraw/clipper.c @@ -26,114 +26,102 @@ WINE_DEFAULT_DEBUG_CHANNEL(ddraw); -/***************************************************************************** - * IUnknown methods - *****************************************************************************/ +static inline struct ddraw_clipper *impl_from_IDirectDrawClipper(IDirectDrawClipper *iface) +{ + return CONTAINING_RECORD(iface, struct ddraw_clipper, IDirectDrawClipper_iface); +} -/***************************************************************************** - * IDirectDrawClipper::QueryInterface - * - * Can query the IUnknown and IDirectDrawClipper interface from a - * Clipper object. The IUnknown Interface is equal to the IDirectDrawClipper - * interface. Can't create other interfaces. - * - * Arguments: - * riid: Interface id asked for - * ppvObj: Returns the pointer to the interface - * - * Return values: - * DD_OK on success - * E_NOINTERFACE if the requested interface wasn't found. - * - *****************************************************************************/ -static HRESULT WINAPI IDirectDrawClipperImpl_QueryInterface( - LPDIRECTDRAWCLIPPER iface, REFIID riid, LPVOID* ppvObj -) { +static HRESULT WINAPI ddraw_clipper_QueryInterface(IDirectDrawClipper *iface, REFIID iid, void **object) +{ + struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface); - TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppvObj); + TRACE("iface %p, iid %s, object %p.\n", iface, debugstr_guid(iid), object); - if (IsEqualGUID(&IID_IDirectDrawClipper, riid) - || IsEqualGUID(&IID_IUnknown, riid)) + if (IsEqualGUID(&IID_IDirectDrawClipper, iid) + || IsEqualGUID(&IID_IUnknown, iid)) { - IUnknown_AddRef(iface); - *ppvObj = iface; + IDirectDrawClipper_AddRef(&clipper->IDirectDrawClipper_iface); + *object = &clipper->IDirectDrawClipper_iface; return S_OK; } + WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid)); + *object = NULL; + return E_NOINTERFACE; } -/***************************************************************************** - * IDirectDrawClipper::AddRef - * - * Increases the reference count of the interface, returns the new count - * - *****************************************************************************/ -static ULONG WINAPI IDirectDrawClipperImpl_AddRef( LPDIRECTDRAWCLIPPER iface ) +static ULONG WINAPI ddraw_clipper_AddRef(IDirectDrawClipper *iface) { - IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface; - ULONG ref = InterlockedIncrement(&This->ref); + struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface); + ULONG refcount = InterlockedIncrement(&clipper->ref); - TRACE("%p increasing refcount to %u.\n", This, ref); + TRACE("%p increasing refcount to %u.\n", clipper, refcount); - return ref; + return refcount; } -/***************************************************************************** - * IDirectDrawClipper::Release - * - * Decreases the reference count of the interface, returns the new count - * If the refcount is decreased to 0, the interface is destroyed. - * - *****************************************************************************/ -static ULONG WINAPI IDirectDrawClipperImpl_Release(IDirectDrawClipper *iface) { - IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface; - ULONG ref = InterlockedDecrement(&This->ref); +static ULONG WINAPI ddraw_clipper_Release(IDirectDrawClipper *iface) +{ + struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface); + ULONG refcount = InterlockedDecrement(&clipper->ref); - TRACE("%p decreasing refcount to %u.\n", This, ref); + TRACE("%p decreasing refcount to %u.\n", clipper, refcount); - if (ref == 0) + if (!refcount) { - EnterCriticalSection(&ddraw_cs); - wined3d_clipper_decref(This->wineD3DClipper); - HeapFree(GetProcessHeap(), 0, This); - LeaveCriticalSection(&ddraw_cs); - return 0; + if (clipper->region) + DeleteObject(clipper->region); + HeapFree(GetProcessHeap(), 0, clipper); } - else return ref; + + return refcount; } -/***************************************************************************** - * IDirectDrawClipper::SetHwnd - * - * Assigns a hWnd to the clipper interface. - * - * Arguments: - * Flags: Unsupported so far - * hWnd: The hWnd to set - * - * Return values: - * DD_OK on success - * DDERR_INVALIDPARAMS if Flags was != 0 - * - *****************************************************************************/ +static HRESULT WINAPI ddraw_clipper_SetHWnd(IDirectDrawClipper *iface, DWORD flags, HWND window) +{ + struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface); -static HRESULT WINAPI IDirectDrawClipperImpl_SetHwnd( - LPDIRECTDRAWCLIPPER iface, DWORD dwFlags, HWND hWnd -) { - IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface; - HRESULT hr; + TRACE("iface %p, flags %#x, window %p.\n", iface, flags, window); - TRACE("iface %p, flags %#x, window %p.\n", iface, dwFlags, hWnd); - - EnterCriticalSection(&ddraw_cs); - hr = wined3d_clipper_set_window(This->wineD3DClipper, dwFlags, hWnd); - LeaveCriticalSection(&ddraw_cs); - switch(hr) + if (flags) { - case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS; - default: return hr; + FIXME("flags %#x, not supported.\n", flags); + return DDERR_INVALIDPARAMS; } + + wined3d_mutex_lock(); + clipper->window = window; + wined3d_mutex_unlock(); + + return DD_OK; +} + +static HRGN get_window_region(HWND window) +{ + POINT origin = {0, 0}; + RECT client_rect; + + if (!GetClientRect(window, &client_rect)) + { + /* This can happen if the window is destroyed, for example. */ + WARN("Failed to get client rect.\n"); + return NULL; + } + + if (!ClientToScreen(window, &origin)) + { + ERR("Failed to translate origin.\n"); + return NULL; + } + + if (!OffsetRect(&client_rect, origin.x, origin.y)) + { + ERR("Failed to translate client rect.\n"); + return NULL; + } + + return CreateRectRgnIndirect(&client_rect); } /***************************************************************************** @@ -142,169 +130,197 @@ static HRESULT WINAPI IDirectDrawClipperImpl_SetHwnd( * Retrieve a copy of the clip list * * Arguments: - * Rect: Rectangle to be used to clip the clip list or NULL for the - * entire clip list - * ClipList: structure for the resulting copy of the clip list. - * If NULL, fills Size up to the number of bytes necessary to hold - * the entire clip. - * Size: Size of resulting clip list; size of the buffer at ClipList - * or, if ClipList is NULL, receives the required size of the buffer - * in bytes + * rect: Rectangle to be used to clip the clip list or NULL for the + * entire clip list. + * clip_list: structure for the resulting copy of the clip list. + * If NULL, fills Size up to the number of bytes necessary to hold + * the entire clip. + * clip_list_size: Size of resulting clip list; size of the buffer at clip_list + * or, if clip_list is NULL, receives the required size of the buffer + * in bytes. * * RETURNS * Either DD_OK or DDERR_* ************************************************************************/ -static HRESULT WINAPI IDirectDrawClipperImpl_GetClipList( - LPDIRECTDRAWCLIPPER iface, LPRECT lpRect, LPRGNDATA lpClipList, - LPDWORD lpdwSize) +static HRESULT WINAPI ddraw_clipper_GetClipList(IDirectDrawClipper *iface, RECT *rect, + RGNDATA *clip_list, DWORD *clip_list_size) { - IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface; - HRESULT hr; + struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface); + HRGN region; TRACE("iface %p, rect %s, clip_list %p, clip_list_size %p.\n", - iface, wine_dbgstr_rect(lpRect), lpClipList, lpdwSize); + iface, wine_dbgstr_rect(rect), clip_list, clip_list_size); - EnterCriticalSection(&ddraw_cs); - hr = wined3d_clipper_get_clip_list(This->wineD3DClipper, lpRect, lpClipList, lpdwSize); - LeaveCriticalSection(&ddraw_cs); - return hr; + wined3d_mutex_lock(); + + if (clipper->window) + { + if (!(region = get_window_region(clipper->window))) + { + wined3d_mutex_unlock(); + WARN("Failed to get window region.\n"); + return E_FAIL; + } + } + else + { + if (!(region = clipper->region)) + { + wined3d_mutex_unlock(); + WARN("No clip list set.\n"); + return DDERR_NOCLIPLIST; + } + } + + if (rect) + { + HRGN clip_region; + + if (!(clip_region = CreateRectRgnIndirect(rect))) + { + wined3d_mutex_unlock(); + ERR("Failed to create region.\n"); + if (clipper->window) + DeleteObject(region); + return E_FAIL; + } + + if (CombineRgn(clip_region, region, clip_region, RGN_AND) == ERROR) + { + wined3d_mutex_unlock(); + ERR("Failed to combine regions.\n"); + DeleteObject(clip_region); + if (clipper->window) + DeleteObject(region); + return E_FAIL; + } + + if (clipper->window) + DeleteObject(region); + region = clip_region; + } + + *clip_list_size = GetRegionData(region, *clip_list_size, clip_list); + if (rect || clipper->window) + DeleteObject(region); + + wined3d_mutex_unlock(); + return DD_OK; } /***************************************************************************** * IDirectDrawClipper::SetClipList * - * Sets or deletes (if lprgn is NULL) the clip list + * Sets or deletes (if region is NULL) the clip list * * This implementation is a stub and returns DD_OK always to make the app * happy. * * PARAMS - * lprgn Pointer to a LRGNDATA structure or NULL - * dwFlags not used, must be 0 + * region Pointer to a LRGNDATA structure or NULL + * flags not used, must be 0 * RETURNS * Either DD_OK or DDERR_* *****************************************************************************/ -static HRESULT WINAPI IDirectDrawClipperImpl_SetClipList( - LPDIRECTDRAWCLIPPER iface,LPRGNDATA lprgn,DWORD dwFlag -) { - IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface; - HRESULT hr; +static HRESULT WINAPI ddraw_clipper_SetClipList(IDirectDrawClipper *iface, RGNDATA *region, DWORD flags) +{ + struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface); - TRACE("iface %p, clip_list %p, flags %#x.\n", iface, lprgn, dwFlag); + TRACE("iface %p, region %p, flags %#x.\n", iface, region, flags); - EnterCriticalSection(&ddraw_cs); - hr = wined3d_clipper_set_clip_list(This->wineD3DClipper, lprgn, dwFlag); - LeaveCriticalSection(&ddraw_cs); - return hr; -} + wined3d_mutex_lock(); -/***************************************************************************** - * IDirectDrawClipper::GetHwnd - * - * Returns the hwnd assigned with SetHwnd - * - * Arguments: - * hWndPtr: Address to store the HWND at - * - * Return values: - * Always returns DD_OK; - *****************************************************************************/ -static HRESULT WINAPI IDirectDrawClipperImpl_GetHWnd( - LPDIRECTDRAWCLIPPER iface, HWND* hWndPtr -) { - IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface; - HRESULT hr; - - TRACE("iface %p, window %p.\n", iface, hWndPtr); - - EnterCriticalSection(&ddraw_cs); - hr = wined3d_clipper_get_window(This->wineD3DClipper, hWndPtr); - LeaveCriticalSection(&ddraw_cs); - return hr; -} - -/***************************************************************************** - * IDirectDrawClipper::Initialize - * - * Initializes the interface. Well, there isn't much to do for this - * implementation, but it stores the DirectDraw Interface. - * - * Arguments: - * DD: Pointer to a IDirectDraw interface - * Flags: Unsupported by now - * - * Return values: - * DD_OK on success - * DDERR_ALREADYINITIALIZED if this interface isn't initialized already - *****************************************************************************/ -static HRESULT WINAPI IDirectDrawClipperImpl_Initialize( - LPDIRECTDRAWCLIPPER iface, LPDIRECTDRAW lpDD, DWORD dwFlags -) { - IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface; - - TRACE("iface %p, ddraw %p, flags %#x.\n", iface, lpDD, dwFlags); - - EnterCriticalSection(&ddraw_cs); - if (This->initialized) + if (clipper->window) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return DDERR_CLIPPERISUSINGHWND; + } + + if (clipper->region) + DeleteObject(clipper->region); + if (!region) + clipper->region = NULL; + else if (!(clipper->region = ExtCreateRegion(NULL, 0, region))) + { + wined3d_mutex_unlock(); + ERR("Failed to create region.\n"); + return E_FAIL; + } + + wined3d_mutex_unlock(); + + return DD_OK; +} + +static HRESULT WINAPI ddraw_clipper_GetHWnd(IDirectDrawClipper *iface, HWND *window) +{ + struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface); + + TRACE("iface %p, window %p.\n", iface, window); + + wined3d_mutex_lock(); + *window = clipper->window; + wined3d_mutex_unlock(); + + return DD_OK; +} + +static HRESULT WINAPI ddraw_clipper_Initialize(IDirectDrawClipper *iface, + IDirectDraw *ddraw, DWORD flags) +{ + struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface); + + TRACE("iface %p, ddraw %p, flags %#x.\n", iface, ddraw, flags); + + wined3d_mutex_lock(); + if (clipper->initialized) + { + wined3d_mutex_unlock(); return DDERR_ALREADYINITIALIZED; } - This->initialized = TRUE; + clipper->initialized = TRUE; + wined3d_mutex_unlock(); - LeaveCriticalSection(&ddraw_cs); return DD_OK; } -/***************************************************************************** - * IDirectDrawClipper::IsClipListChanged - * - * This function is a stub - * - * Arguments: - * Changed: - * - * Return values: - * DD_OK, because it's a stub - *****************************************************************************/ -static HRESULT WINAPI IDirectDrawClipperImpl_IsClipListChanged( - LPDIRECTDRAWCLIPPER iface, BOOL* lpbChanged -) { - FIXME("iface %p, changed %p stub!\n", iface, lpbChanged); +static HRESULT WINAPI ddraw_clipper_IsClipListChanged(IDirectDrawClipper *iface, BOOL *changed) +{ + FIXME("iface %p, changed %p stub!\n", iface, changed); /* XXX What is safest? */ - *lpbChanged = FALSE; + *changed = FALSE; return DD_OK; } -/***************************************************************************** - * The VTable - *****************************************************************************/ static const struct IDirectDrawClipperVtbl ddraw_clipper_vtbl = { - IDirectDrawClipperImpl_QueryInterface, - IDirectDrawClipperImpl_AddRef, - IDirectDrawClipperImpl_Release, - IDirectDrawClipperImpl_GetClipList, - IDirectDrawClipperImpl_GetHWnd, - IDirectDrawClipperImpl_Initialize, - IDirectDrawClipperImpl_IsClipListChanged, - IDirectDrawClipperImpl_SetClipList, - IDirectDrawClipperImpl_SetHwnd + ddraw_clipper_QueryInterface, + ddraw_clipper_AddRef, + ddraw_clipper_Release, + ddraw_clipper_GetClipList, + ddraw_clipper_GetHWnd, + ddraw_clipper_Initialize, + ddraw_clipper_IsClipListChanged, + ddraw_clipper_SetClipList, + ddraw_clipper_SetHWnd, }; -HRESULT ddraw_clipper_init(IDirectDrawClipperImpl *clipper) +HRESULT ddraw_clipper_init(struct ddraw_clipper *clipper) { - clipper->lpVtbl = &ddraw_clipper_vtbl; + clipper->IDirectDrawClipper_iface.lpVtbl = &ddraw_clipper_vtbl; clipper->ref = 1; - clipper->wineD3DClipper = wined3d_clipper_create(); - if (!clipper->wineD3DClipper) - { - WARN("Failed to create wined3d clipper.\n"); - return E_OUTOFMEMORY; - } return DD_OK; } + +struct ddraw_clipper *unsafe_impl_from_IDirectDrawClipper(IDirectDrawClipper *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &ddraw_clipper_vtbl); + + return impl_from_IDirectDrawClipper(iface); +} diff --git a/reactos/dll/directx/wine/ddraw/ddraw.c b/reactos/dll/directx/wine/ddraw/ddraw.c index 0c6ba3c2656..8397d5d233c 100644 --- a/reactos/dll/directx/wine/ddraw/ddraw.c +++ b/reactos/dll/directx/wine/ddraw/ddraw.c @@ -39,6 +39,35 @@ static const DDDEVICEIDENTIFIER2 deviceidentifier = 0 }; +static struct enum_device_entry +{ + char interface_name[100]; + char device_name[100]; + const GUID *device_guid; +} device_list7[] = +{ + /* T&L HAL device */ + { + "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D", + "Wine D3D7 T&L HAL", + &IID_IDirect3DTnLHalDevice, + }, + + /* HAL device */ + { + "WINE Direct3D7 Hardware acceleration using WineD3D", + "Direct3D HAL", + &IID_IDirect3DHALDevice, + }, + + /* RGB device */ + { + "WINE Direct3D7 RGB Software Emulation using WineD3D", + "Wine D3D7 RGB", + &IID_IDirect3DRGBDevice, + }, +}; + static void STDMETHODCALLTYPE ddraw_null_wined3d_object_destroyed(void *parent) {} const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops = @@ -56,11 +85,6 @@ static inline IDirectDrawImpl *impl_from_IDirectDraw2(IDirectDraw2 *iface) return CONTAINING_RECORD(iface, IDirectDrawImpl, IDirectDraw2_iface); } -static inline IDirectDrawImpl *impl_from_IDirectDraw3(IDirectDraw3 *iface) -{ - return CONTAINING_RECORD(iface, IDirectDrawImpl, IDirectDraw3_iface); -} - static inline IDirectDrawImpl *impl_from_IDirectDraw4(IDirectDraw4 *iface) { return CONTAINING_RECORD(iface, IDirectDrawImpl, IDirectDraw4_iface); @@ -122,14 +146,14 @@ static HRESULT WINAPI ddraw7_QueryInterface(IDirectDraw7 *iface, REFIID refiid, TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(refiid), obj); /* Can change surface impl type */ - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */ *obj = NULL; if(!refiid) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } @@ -150,7 +174,7 @@ static HRESULT WINAPI ddraw7_QueryInterface(IDirectDraw7 *iface, REFIID refiid, /* This Interface exists in ddrawex.dll, it is implemented in a wrapper */ WARN("IDirectDraw3 is not valid in ddraw.dll\n"); *obj = NULL; - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return E_NOINTERFACE; } else if ( IsEqualGUID( &IID_IDirectDraw2, refiid ) ) @@ -177,20 +201,7 @@ static HRESULT WINAPI ddraw7_QueryInterface(IDirectDraw7 *iface, REFIID refiid, IsEqualGUID( &IID_IDirect3D7 , refiid ) ) { /* Check the surface implementation */ - if(This->ImplType == SURFACE_UNKNOWN) - { - /* Apps may create the IDirect3D Interface before the primary surface. - * set the surface implementation */ - This->ImplType = SURFACE_OPENGL; - TRACE("(%p) Choosing OpenGL surfaces because a Direct3D interface was requested\n", This); - } - else if(This->ImplType != SURFACE_OPENGL && DefaultSurfaceType == SURFACE_UNKNOWN) - { - ERR("(%p) The App is requesting a D3D device, but a non-OpenGL surface type was choosen. Prepare for trouble!\n", This); - ERR(" (%p) You may want to contact wine-devel for help\n", This); - /* Should I assert(0) here??? */ - } - else if(This->ImplType != SURFACE_OPENGL) + if (DefaultSurfaceType != SURFACE_OPENGL) { WARN("The app requests a Direct3D interface, but non-opengl surfaces where set in winecfg\n"); /* Do not abort here, only reject 3D Device creation */ @@ -225,12 +236,13 @@ static HRESULT WINAPI ddraw7_QueryInterface(IDirectDraw7 *iface, REFIID refiid, else { ERR("(%p)->(%s, %p): No interface found\n", This, debugstr_guid(refiid), obj); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return E_NOINTERFACE; } IUnknown_AddRef( (IUnknown *) *obj ); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return S_OK; } @@ -243,15 +255,6 @@ static HRESULT WINAPI ddraw4_QueryInterface(IDirectDraw4 *iface, REFIID riid, vo return ddraw7_QueryInterface(&This->IDirectDraw7_iface, riid, object); } -static HRESULT WINAPI ddraw3_QueryInterface(IDirectDraw3 *iface, REFIID riid, void **object) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - - TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); - - return ddraw7_QueryInterface(&This->IDirectDraw7_iface, riid, object); -} - static HRESULT WINAPI ddraw2_QueryInterface(IDirectDraw2 *iface, REFIID riid, void **object) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); @@ -348,18 +351,6 @@ static ULONG WINAPI ddraw4_AddRef(IDirectDraw4 *iface) return ref; } -static ULONG WINAPI ddraw3_AddRef(IDirectDraw3 *iface) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - ULONG ref = InterlockedIncrement(&This->ref3); - - TRACE("%p increasing refcount to %u.\n", This, ref); - - if (ref == 1) InterlockedIncrement(&This->numIfaces); - - return ref; -} - static ULONG WINAPI ddraw2_AddRef(IDirectDraw2 *iface) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); @@ -420,6 +411,51 @@ static ULONG WINAPI d3d1_AddRef(IDirect3D *iface) return ddraw1_AddRef(&This->IDirectDraw_iface); } +void ddraw_destroy_swapchain(IDirectDrawImpl *ddraw) +{ + TRACE("Destroying the swapchain.\n"); + + wined3d_swapchain_decref(ddraw->wined3d_swapchain); + ddraw->wined3d_swapchain = NULL; + + if (DefaultSurfaceType == SURFACE_OPENGL) + { + UINT i; + + for (i = 0; i < ddraw->numConvertedDecls; ++i) + { + wined3d_vertex_declaration_decref(ddraw->decls[i].decl); + } + HeapFree(GetProcessHeap(), 0, ddraw->decls); + ddraw->numConvertedDecls = 0; + + if (FAILED(wined3d_device_uninit_3d(ddraw->wined3d_device))) + { + ERR("Failed to uninit 3D.\n"); + } + else + { + /* Free the d3d window if one was created. */ + if (ddraw->d3d_window && ddraw->d3d_window != ddraw->dest_window) + { + TRACE("Destroying the hidden render window %p.\n", ddraw->d3d_window); + DestroyWindow(ddraw->d3d_window); + ddraw->d3d_window = 0; + } + } + + ddraw->d3d_initialized = FALSE; + } + else + { + wined3d_device_uninit_gdi(ddraw->wined3d_device); + } + + ddraw_set_swapchain_window(ddraw, NULL); + + TRACE("Swapchain destroyed.\n"); +} + /***************************************************************************** * ddraw_destroy * @@ -443,13 +479,14 @@ static void ddraw_destroy(IDirectDrawImpl *This) This->devicewindow = 0; } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); list_remove(&This->ddraw_list_entry); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); - /* Release the attached WineD3D stuff */ + if (This->wined3d_swapchain) + ddraw_destroy_swapchain(This); wined3d_device_decref(This->wined3d_device); - wined3d_decref(This->wineD3D); + wined3d_decref(This->wined3d); /* Now free the object */ HeapFree(GetProcessHeap(), 0, This); @@ -488,19 +525,6 @@ static ULONG WINAPI ddraw4_Release(IDirectDraw4 *iface) return ref; } -static ULONG WINAPI ddraw3_Release(IDirectDraw3 *iface) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - ULONG ref = InterlockedDecrement(&This->ref3); - - TRACE("%p decreasing refcount to %u.\n", This, ref); - - if (!ref && !InterlockedDecrement(&This->numIfaces)) - ddraw_destroy(This); - - return ref; -} - static ULONG WINAPI ddraw2_Release(IDirectDraw2 *iface) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); @@ -567,6 +591,127 @@ static ULONG WINAPI d3d1_Release(IDirect3D *iface) * IDirectDraw methods *****************************************************************************/ +static HRESULT ddraw_set_focus_window(IDirectDrawImpl *ddraw, HWND window) +{ + /* FIXME: This looks wrong, exclusive mode should imply a destination + * window. */ + if ((ddraw->cooperative_level & DDSCL_EXCLUSIVE) && ddraw->dest_window) + { + TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET.\n"); + return DDERR_HWNDALREADYSET; + } + + ddraw->focuswindow = window; + + /* Use the focus window for drawing too. */ + ddraw->dest_window = ddraw->focuswindow; + + return DD_OK; +} + +static HRESULT ddraw_attach_d3d_device(IDirectDrawImpl *ddraw, + struct wined3d_swapchain_desc *swapchain_desc) +{ + HWND window = swapchain_desc->device_window; + HRESULT hr; + + TRACE("ddraw %p.\n", ddraw); + + if (!window || window == GetDesktopWindow()) + { + window = CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME, "Hidden D3D Window", + WS_DISABLED, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), + NULL, NULL, NULL, NULL); + if (!window) + { + ERR("Failed to create window, last error %#x.\n", GetLastError()); + return E_FAIL; + } + + ShowWindow(window, SW_HIDE); /* Just to be sure */ + WARN("No window for the Direct3DDevice, created hidden window %p.\n", window); + + swapchain_desc->device_window = window; + } + else + { + TRACE("Using existing window %p for Direct3D rendering.\n", window); + } + ddraw->d3d_window = window; + + /* Set this NOW, otherwise creating the depth stencil surface will cause a + * recursive loop until ram or emulated video memory is full. */ + ddraw->d3d_initialized = TRUE; + hr = wined3d_device_init_3d(ddraw->wined3d_device, swapchain_desc); + if (FAILED(hr)) + { + ddraw->d3d_initialized = FALSE; + return hr; + } + + ddraw->declArraySize = 2; + ddraw->decls = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ddraw->decls) * ddraw->declArraySize); + if (!ddraw->decls) + { + ERR("Error allocating an array for the converted vertex decls.\n"); + ddraw->declArraySize = 0; + hr = wined3d_device_uninit_3d(ddraw->wined3d_device); + return E_OUTOFMEMORY; + } + + TRACE("Successfully initialized 3D.\n"); + + return DD_OK; +} + +static HRESULT ddraw_create_swapchain(IDirectDrawImpl *ddraw, HWND window, BOOL windowed) +{ + struct wined3d_swapchain_desc swapchain_desc; + struct wined3d_display_mode mode; + HRESULT hr = WINED3D_OK; + + /* FIXME: wined3d_get_adapter_display_mode() would be more appropriate + * here, since we don't actually have a swapchain yet, but + * wined3d_device_get_display_mode() has some special handling for color + * depth changes. */ + hr = wined3d_device_get_display_mode(ddraw->wined3d_device, 0, &mode); + if (FAILED(hr)) + { + ERR("Failed to get display mode.\n"); + return hr; + } + + memset(&swapchain_desc, 0, sizeof(swapchain_desc)); + swapchain_desc.backbuffer_width = mode.width; + swapchain_desc.backbuffer_height = mode.height; + swapchain_desc.backbuffer_format = mode.format_id; + swapchain_desc.swap_effect = WINED3D_SWAP_EFFECT_COPY; + swapchain_desc.device_window = window; + swapchain_desc.windowed = windowed; + + if (DefaultSurfaceType == SURFACE_OPENGL) + hr = ddraw_attach_d3d_device(ddraw, &swapchain_desc); + else + hr = wined3d_device_init_gdi(ddraw->wined3d_device, &swapchain_desc); + + if (FAILED(hr)) + { + ERR("Failed to create swapchain, hr %#x.\n", hr); + return hr; + } + + if (FAILED(hr = wined3d_device_get_swapchain(ddraw->wined3d_device, 0, &ddraw->wined3d_swapchain))) + { + ERR("Failed to get swapchain, hr %#x.\n", hr); + ddraw->wined3d_swapchain = NULL; + return hr; + } + + ddraw_set_swapchain_window(ddraw, window); + + return DD_OK; +} + /***************************************************************************** * IDirectDraw7::SetCooperativeLevel * @@ -614,12 +759,16 @@ static ULONG WINAPI d3d1_Release(IDirect3D *iface) static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd, DWORD cooplevel) { IDirectDrawImpl *This = impl_from_IDirectDraw7(iface); + struct wined3d_stateblock *stateblock; + struct wined3d_surface *rt, *ds; + BOOL restore_state = FALSE; HWND window; + HRESULT hr; TRACE("iface %p, window %p, flags %#x.\n", iface, hwnd, cooplevel); DDRAW_dump_cooperativelevel(cooplevel); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); /* Get the old window */ window = This->dest_window; @@ -630,69 +779,103 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd, DDSCL_EXCLUSIVE ))) { TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return DDERR_INVALIDPARAMS; + } + + if ((cooplevel & DDSCL_CREATEDEVICEWINDOW) && !(cooplevel & DDSCL_EXCLUSIVE)) + { + WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n"); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } /* Handle those levels first which set various hwnds */ - if(cooplevel & DDSCL_SETFOCUSWINDOW) + if ((cooplevel & DDSCL_SETFOCUSWINDOW) && !(cooplevel & DDSCL_CREATEDEVICEWINDOW)) { /* This isn't compatible with a lot of flags */ - if(cooplevel & ( DDSCL_MULTITHREADED | - DDSCL_CREATEDEVICEWINDOW | - DDSCL_FPUSETUP | - DDSCL_FPUPRESERVE | - DDSCL_ALLOWREBOOT | - DDSCL_ALLOWMODEX | - DDSCL_SETDEVICEWINDOW | - DDSCL_NORMAL | - DDSCL_EXCLUSIVE | - DDSCL_FULLSCREEN ) ) + if (cooplevel & (DDSCL_MULTITHREADED + | DDSCL_FPUSETUP + | DDSCL_FPUPRESERVE + | DDSCL_ALLOWREBOOT + | DDSCL_ALLOWMODEX + | DDSCL_SETDEVICEWINDOW + | DDSCL_NORMAL + | DDSCL_EXCLUSIVE + | DDSCL_FULLSCREEN)) { - TRACE("Called with incompatible flags, returning DDERR_INVALIDPARAMS\n"); - LeaveCriticalSection(&ddraw_cs); + WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n"); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } - if( (This->cooperative_level & DDSCL_EXCLUSIVE) && window ) + hr = ddraw_set_focus_window(This, hwnd); + wined3d_mutex_unlock(); + return hr; + } + + if (cooplevel & DDSCL_EXCLUSIVE) + { + if (!(cooplevel & DDSCL_FULLSCREEN) || !(hwnd || (cooplevel & DDSCL_CREATEDEVICEWINDOW))) { - TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET\n"); - LeaveCriticalSection(&ddraw_cs); - return DDERR_HWNDALREADYSET; + WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n"); + wined3d_mutex_unlock(); + return DDERR_INVALIDPARAMS; } - This->focuswindow = hwnd; - /* Won't use the hwnd param for anything else */ - hwnd = NULL; - - /* Use the focus window for drawing too */ - This->dest_window = This->focuswindow; - - /* Destroy the device window, if we have one */ - if(This->devicewindow) + if (cooplevel & DDSCL_CREATEDEVICEWINDOW) { + HWND device_window; + + if (!This->focuswindow && !(cooplevel & DDSCL_SETFOCUSWINDOW)) + { + WARN("No focus window set.\n"); + wined3d_mutex_unlock(); + return DDERR_NOFOCUSWINDOW; + } + + device_window = CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME, "DirectDrawDeviceWnd", + WS_POPUP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), + NULL, NULL, NULL, NULL); + if (!device_window) + { + ERR("Failed to create window, last error %#x.\n", GetLastError()); + wined3d_mutex_unlock(); + return E_FAIL; + } + + ShowWindow(device_window, SW_SHOW); + TRACE("Created a device window %p.\n", device_window); + + /* Native apparently leaks the created device window if setting the + * focus window below fails. */ + This->cooperative_level |= DDSCL_CREATEDEVICEWINDOW; + This->devicewindow = device_window; + + if (cooplevel & DDSCL_SETFOCUSWINDOW) + { + if (!hwnd) + { + wined3d_mutex_unlock(); + return DDERR_NOHWND; + } + + if (FAILED(hr = ddraw_set_focus_window(This, hwnd))) + { + wined3d_mutex_unlock(); + return hr; + } + } + + hwnd = device_window; + } + } + else + { + if (This->cooperative_level & DDSCL_CREATEDEVICEWINDOW) DestroyWindow(This->devicewindow); - This->devicewindow = NULL; - } - - LeaveCriticalSection(&ddraw_cs); - return DD_OK; - } - - if(cooplevel & DDSCL_EXCLUSIVE) - { - if( !(cooplevel & DDSCL_FULLSCREEN) || !hwnd ) - { - TRACE("(%p) DDSCL_EXCLUSIVE needs DDSCL_FULLSCREEN and a window\n", This); - LeaveCriticalSection(&ddraw_cs); - return DDERR_INVALIDPARAMS; - } - } - else if( !(cooplevel & DDSCL_NORMAL) ) - { - TRACE("(%p) SetCooperativeLevel needs at least SetFocusWindow or Exclusive or Normal mode\n", This); - LeaveCriticalSection(&ddraw_cs); - return DDERR_INVALIDPARAMS; + This->devicewindow = NULL; + This->focuswindow = NULL; } if ((This->cooperative_level & DDSCL_EXCLUSIVE) @@ -706,22 +889,22 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd, if (cooplevel & DDSCL_FULLSCREEN) { - WINED3DDISPLAYMODE display_mode; + struct wined3d_display_mode display_mode; - wined3d_get_adapter_display_mode(This->wineD3D, WINED3DADAPTER_DEFAULT, &display_mode); + wined3d_get_adapter_display_mode(This->wined3d, WINED3DADAPTER_DEFAULT, &display_mode); wined3d_device_setup_fullscreen_window(This->wined3d_device, hwnd, - display_mode.Width, display_mode.Height); + display_mode.width, display_mode.height); } } if ((cooplevel & DDSCL_EXCLUSIVE) && (hwnd != window || !(This->cooperative_level & DDSCL_EXCLUSIVE))) { - HRESULT hr = wined3d_device_acquire_focus_window(This->wined3d_device, hwnd); + hr = wined3d_device_acquire_focus_window(This->wined3d_device, hwnd); if (FAILED(hr)) { ERR("Failed to acquire focus window, hr %#x.\n", hr); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } } @@ -730,32 +913,70 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd, if (hwnd && !This->focuswindow && !This->devicewindow && (hwnd != window)) This->dest_window = hwnd; - if(cooplevel & DDSCL_CREATEDEVICEWINDOW) - { - /* Don't create a device window if a focus window is set */ - if( !(This->focuswindow) ) - { - HWND devicewindow = CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME, "DDraw device window", - WS_POPUP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), - NULL, NULL, NULL, NULL); - if (!devicewindow) - { - ERR("Failed to create window, last error %#x.\n", GetLastError()); - LeaveCriticalSection(&ddraw_cs); - return E_FAIL; - } - - ShowWindow(devicewindow, SW_SHOW); /* Just to be sure */ - TRACE("(%p) Created a DDraw device window. HWND=%p\n", This, devicewindow); - - This->devicewindow = devicewindow; - This->dest_window = devicewindow; - } - } - if (cooplevel & DDSCL_MULTITHREADED && !(This->cooperative_level & DDSCL_MULTITHREADED)) wined3d_device_set_multithreaded(This->wined3d_device); + if (This->wined3d_swapchain) + { + if (DefaultSurfaceType != SURFACE_GDI) + { + restore_state = TRUE; + + if (FAILED(hr = wined3d_stateblock_create(This->wined3d_device, WINED3D_SBT_ALL, &stateblock))) + { + ERR("Failed to create stateblock, hr %#x.\n", hr); + wined3d_mutex_unlock(); + return hr; + } + + if (FAILED(hr = wined3d_stateblock_capture(stateblock))) + { + ERR("Failed to capture stateblock, hr %#x.\n", hr); + wined3d_stateblock_decref(stateblock); + wined3d_mutex_unlock(); + return hr; + } + + wined3d_device_get_render_target(This->wined3d_device, 0, &rt); + if (rt == This->wined3d_frontbuffer) + { + wined3d_surface_decref(rt); + rt = NULL; + } + + wined3d_device_get_depth_stencil(This->wined3d_device, &ds); + } + + ddraw_destroy_swapchain(This); + } + + if (FAILED(hr = ddraw_create_swapchain(This, This->dest_window, !(cooplevel & DDSCL_FULLSCREEN)))) + ERR("Failed to create swapchain, hr %#x.\n", hr); + + if (restore_state) + { + if (ds) + { + wined3d_device_set_depth_stencil(This->wined3d_device, ds); + wined3d_surface_decref(ds); + } + + if (rt) + { + wined3d_device_set_render_target(This->wined3d_device, 0, rt, FALSE); + wined3d_surface_decref(rt); + } + + hr = wined3d_stateblock_apply(stateblock); + wined3d_stateblock_decref(stateblock); + if (FAILED(hr)) + { + ERR("Failed to apply stateblock, hr %#x.\n", hr); + wined3d_mutex_unlock(); + return hr; + } + } + /* Unhandled flags */ if(cooplevel & DDSCL_ALLOWREBOOT) WARN("(%p) Unhandled flag DDSCL_ALLOWREBOOT, harmless\n", This); @@ -767,7 +988,8 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd, /* Store the cooperative_level */ This->cooperative_level = cooplevel; TRACE("SetCooperativeLevel retuning DD_OK\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return DD_OK; } @@ -780,15 +1002,6 @@ static HRESULT WINAPI ddraw4_SetCooperativeLevel(IDirectDraw4 *iface, HWND windo return ddraw7_SetCooperativeLevel(&This->IDirectDraw7_iface, window, flags); } -static HRESULT WINAPI ddraw3_SetCooperativeLevel(IDirectDraw3 *iface, HWND window, DWORD flags) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - - TRACE("iface %p, window %p, flags %#x.\n", iface, window, flags); - - return ddraw7_SetCooperativeLevel(&This->IDirectDraw7_iface, window, flags); -} - static HRESULT WINAPI ddraw2_SetCooperativeLevel(IDirectDraw2 *iface, HWND window, DWORD flags) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); @@ -822,19 +1035,19 @@ static HRESULT WINAPI ddraw1_SetCooperativeLevel(IDirectDraw *iface, HWND window static HRESULT ddraw_set_display_mode(IDirectDrawImpl *ddraw, DWORD Width, DWORD Height, DWORD BPP, DWORD RefreshRate, DWORD Flags) { + struct wined3d_display_mode mode; enum wined3d_format_id format; - WINED3DDISPLAYMODE Mode; HRESULT hr; TRACE("ddraw %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n", ddraw, Width, Height, BPP, RefreshRate, Flags); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if( !Width || !Height ) { ERR("Width %u, Height %u, what to do?\n", Width, Height); /* It looks like Need for Speed Porsche Unleashed expects DD_OK here */ - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DD_OK; } @@ -848,17 +1061,17 @@ static HRESULT ddraw_set_display_mode(IDirectDrawImpl *ddraw, DWORD Width, DWORD default: format = WINED3DFMT_UNKNOWN; break; } - if (FAILED(hr = wined3d_device_get_display_mode(ddraw->wined3d_device, 0, &Mode))) + if (FAILED(hr = wined3d_device_get_display_mode(ddraw->wined3d_device, 0, &mode))) { ERR("Failed to get current display mode, hr %#x.\n", hr); } - else if (Mode.Width == Width - && Mode.Height == Height - && Mode.Format == format - && Mode.RefreshRate == RefreshRate) + else if (mode.width == Width + && mode.height == Height + && mode.format_id == format + && mode.refresh_rate == RefreshRate) { TRACE("Skipping redundant mode setting call.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DD_OK; } @@ -871,10 +1084,10 @@ static HRESULT ddraw_set_display_mode(IDirectDrawImpl *ddraw, DWORD Width, DWORD * depends on this */ - Mode.Width = Width; - Mode.Height = Height; - Mode.RefreshRate = RefreshRate; - Mode.Format = format; + mode.width = Width; + mode.height = Height; + mode.refresh_rate = RefreshRate; + mode.format_id = format; /* TODO: The possible return values from msdn suggest that * the screen mode can't be changed if a surface is locked @@ -882,15 +1095,10 @@ static HRESULT ddraw_set_display_mode(IDirectDrawImpl *ddraw, DWORD Width, DWORD */ /* TODO: Lose the primary surface */ - hr = wined3d_device_set_display_mode(ddraw->wined3d_device, 0, &Mode); + hr = wined3d_device_set_display_mode(ddraw->wined3d_device, 0, &mode); - if (ddraw->cooperative_level & DDSCL_EXCLUSIVE) - { - wined3d_device_restore_fullscreen_window(ddraw->wined3d_device, ddraw->dest_window); - wined3d_device_setup_fullscreen_window(ddraw->wined3d_device, ddraw->dest_window, Width, Height); - } + wined3d_mutex_unlock(); - LeaveCriticalSection(&ddraw_cs); switch(hr) { case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED; @@ -949,17 +1157,6 @@ static HRESULT WINAPI ddraw4_SetDisplayMode(IDirectDraw4 *iface, DWORD width, DW return ddraw7_SetDisplayMode(&This->IDirectDraw7_iface, width, height, bpp, refresh_rate, flags); } -static HRESULT WINAPI ddraw3_SetDisplayMode(IDirectDraw3 *iface, DWORD width, DWORD height, - DWORD bpp, DWORD refresh_rate, DWORD flags) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - - TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n", - iface, width, height, bpp, refresh_rate, flags); - - return ddraw7_SetDisplayMode(&This->IDirectDraw7_iface, width, height, bpp, refresh_rate, flags); -} - static HRESULT WINAPI ddraw2_SetDisplayMode(IDirectDraw2 *iface, DWORD width, DWORD height, DWORD bpp, DWORD refresh_rate, DWORD flags) { @@ -1019,15 +1216,6 @@ static HRESULT WINAPI ddraw4_RestoreDisplayMode(IDirectDraw4 *iface) return ddraw7_RestoreDisplayMode(&This->IDirectDraw7_iface); } -static HRESULT WINAPI ddraw3_RestoreDisplayMode(IDirectDraw3 *iface) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - - TRACE("iface %p.\n", iface); - - return ddraw7_RestoreDisplayMode(&This->IDirectDraw7_iface); -} - static HRESULT WINAPI ddraw2_RestoreDisplayMode(IDirectDraw2 *iface) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); @@ -1081,37 +1269,38 @@ static HRESULT WINAPI ddraw7_GetCaps(IDirectDraw7 *iface, DDCAPS *DriverCaps, DD memset(&caps, 0, sizeof(caps)); memset(&winecaps, 0, sizeof(winecaps)); caps.dwSize = sizeof(caps); - EnterCriticalSection(&ddraw_cs); + + wined3d_mutex_lock(); hr = wined3d_device_get_device_caps(This->wined3d_device, &winecaps); if (FAILED(hr)) { WARN("IWineD3DDevice::GetDeviceCaps failed\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } hr = IDirectDraw7_GetAvailableVidMem(iface, &ddscaps, &caps.dwVidMemTotal, &caps.dwVidMemFree); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); if(FAILED(hr)) { WARN("IDirectDraw7::GetAvailableVidMem failed\n"); return hr; } - caps.dwCaps = winecaps.DirectDrawCaps.Caps; - caps.dwCaps2 = winecaps.DirectDrawCaps.Caps2; - caps.dwCKeyCaps = winecaps.DirectDrawCaps.CKeyCaps; - caps.dwFXCaps = winecaps.DirectDrawCaps.FXCaps; - caps.dwPalCaps = winecaps.DirectDrawCaps.PalCaps; - caps.ddsCaps.dwCaps = winecaps.DirectDrawCaps.ddsCaps; - caps.dwSVBCaps = winecaps.DirectDrawCaps.SVBCaps; - caps.dwSVBCKeyCaps = winecaps.DirectDrawCaps.SVBCKeyCaps; - caps.dwSVBFXCaps = winecaps.DirectDrawCaps.SVBFXCaps; - caps.dwVSBCaps = winecaps.DirectDrawCaps.VSBCaps; - caps.dwVSBCKeyCaps = winecaps.DirectDrawCaps.VSBCKeyCaps; - caps.dwVSBFXCaps = winecaps.DirectDrawCaps.VSBFXCaps; - caps.dwSSBCaps = winecaps.DirectDrawCaps.SSBCaps; - caps.dwSSBCKeyCaps = winecaps.DirectDrawCaps.SSBCKeyCaps; - caps.dwSSBFXCaps = winecaps.DirectDrawCaps.SSBFXCaps; + caps.dwCaps = winecaps.ddraw_caps.caps; + caps.dwCaps2 = winecaps.ddraw_caps.caps2; + caps.dwCKeyCaps = winecaps.ddraw_caps.color_key_caps; + caps.dwFXCaps = winecaps.ddraw_caps.fx_caps; + caps.dwPalCaps = winecaps.ddraw_caps.pal_caps; + caps.ddsCaps.dwCaps = winecaps.ddraw_caps.dds_caps; + caps.dwSVBCaps = winecaps.ddraw_caps.svb_caps; + caps.dwSVBCKeyCaps = winecaps.ddraw_caps.svb_color_key_caps; + caps.dwSVBFXCaps = winecaps.ddraw_caps.svb_fx_caps; + caps.dwVSBCaps = winecaps.ddraw_caps.vsb_caps; + caps.dwVSBCKeyCaps = winecaps.ddraw_caps.vsb_color_key_caps; + caps.dwVSBFXCaps = winecaps.ddraw_caps.vsb_fx_caps; + caps.dwSSBCaps = winecaps.ddraw_caps.ssb_caps; + caps.dwSSBCKeyCaps = winecaps.ddraw_caps.ssb_color_key_caps; + caps.dwSSBFXCaps = winecaps.ddraw_caps.ssb_fx_caps; /* Even if WineD3D supports 3D rendering, remove the cap if ddraw is configured * not to use it @@ -1120,9 +1309,10 @@ static HRESULT WINAPI ddraw7_GetCaps(IDirectDraw7 *iface, DDCAPS *DriverCaps, DD caps.dwCaps &= ~DDCAPS_3D; caps.ddsCaps.dwCaps &= ~(DDSCAPS_3DDEVICE | DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_ZBUFFER); } - if(winecaps.DirectDrawCaps.StrideAlign != 0) { + if (winecaps.ddraw_caps.stride_align) + { caps.dwCaps |= DDCAPS_ALIGNSTRIDE; - caps.dwAlignStrideAlign = winecaps.DirectDrawCaps.StrideAlign; + caps.dwAlignStrideAlign = winecaps.ddraw_caps.stride_align; } if(DriverCaps) @@ -1157,15 +1347,6 @@ static HRESULT WINAPI ddraw4_GetCaps(IDirectDraw4 *iface, DDCAPS *driver_caps, D return ddraw7_GetCaps(&This->IDirectDraw7_iface, driver_caps, hel_caps); } -static HRESULT WINAPI ddraw3_GetCaps(IDirectDraw3 *iface, DDCAPS *driver_caps, DDCAPS *hel_caps) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - - TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface, driver_caps, hel_caps); - - return ddraw7_GetCaps(&This->IDirectDraw7_iface, driver_caps, hel_caps); -} - static HRESULT WINAPI ddraw2_GetCaps(IDirectDraw2 *iface, DDCAPS *driver_caps, DDCAPS *hel_caps) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); @@ -1209,15 +1390,6 @@ static HRESULT WINAPI ddraw4_Compact(IDirectDraw4 *iface) return ddraw7_Compact(&This->IDirectDraw7_iface); } -static HRESULT WINAPI ddraw3_Compact(IDirectDraw3 *iface) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - - TRACE("iface %p.\n", iface); - - return ddraw7_Compact(&This->IDirectDraw7_iface); -} - static HRESULT WINAPI ddraw2_Compact(IDirectDraw2 *iface) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); @@ -1253,27 +1425,27 @@ static HRESULT WINAPI ddraw1_Compact(IDirectDraw *iface) static HRESULT WINAPI ddraw7_GetDisplayMode(IDirectDraw7 *iface, DDSURFACEDESC2 *DDSD) { IDirectDrawImpl *This = impl_from_IDirectDraw7(iface); + struct wined3d_display_mode mode; HRESULT hr; - WINED3DDISPLAYMODE Mode; DWORD Size; TRACE("iface %p, surface_desc %p.\n", iface, DDSD); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); /* This seems sane */ if (!DDSD) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } /* The necessary members of LPDDSURFACEDESC and LPDDSURFACEDESC2 are equal, * so one method can be used for all versions (Hopefully) */ - hr = wined3d_device_get_display_mode(This->wined3d_device, 0, &Mode); + hr = wined3d_device_get_display_mode(This->wined3d_device, 0, &mode); if (FAILED(hr)) { ERR(" (%p) IWineD3DDevice::GetDisplayMode returned %08x\n", This, hr); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } @@ -1282,13 +1454,13 @@ static HRESULT WINAPI ddraw7_GetDisplayMode(IDirectDraw7 *iface, DDSURFACEDESC2 DDSD->dwSize = Size; DDSD->dwFlags |= DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_PITCH | DDSD_REFRESHRATE; - DDSD->dwWidth = Mode.Width; - DDSD->dwHeight = Mode.Height; + DDSD->dwWidth = mode.width; + DDSD->dwHeight = mode.height; DDSD->u2.dwRefreshRate = 60; DDSD->ddsCaps.dwCaps = 0; DDSD->u4.ddpfPixelFormat.dwSize = sizeof(DDSD->u4.ddpfPixelFormat); - PixelFormat_WineD3DtoDD(&DDSD->u4.ddpfPixelFormat, Mode.Format); - DDSD->u1.lPitch = Mode.Width * DDSD->u4.ddpfPixelFormat.u1.dwRGBBitCount / 8; + PixelFormat_WineD3DtoDD(&DDSD->u4.ddpfPixelFormat, mode.format_id); + DDSD->u1.lPitch = mode.width * DDSD->u4.ddpfPixelFormat.u1.dwRGBBitCount / 8; if(TRACE_ON(ddraw)) { @@ -1296,7 +1468,8 @@ static HRESULT WINAPI ddraw7_GetDisplayMode(IDirectDraw7 *iface, DDSURFACEDESC2 DDRAW_dump_surface_desc(DDSD); } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return DD_OK; } @@ -1309,21 +1482,13 @@ static HRESULT WINAPI ddraw4_GetDisplayMode(IDirectDraw4 *iface, DDSURFACEDESC2 return ddraw7_GetDisplayMode(&This->IDirectDraw7_iface, surface_desc); } -static HRESULT WINAPI ddraw3_GetDisplayMode(IDirectDraw3 *iface, DDSURFACEDESC *surface_desc) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - - TRACE("iface %p, surface_desc %p.\n", iface, surface_desc); - - return ddraw7_GetDisplayMode(&This->IDirectDraw7_iface, (DDSURFACEDESC2 *)surface_desc); -} - static HRESULT WINAPI ddraw2_GetDisplayMode(IDirectDraw2 *iface, DDSURFACEDESC *surface_desc) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); TRACE("iface %p, surface_desc %p.\n", iface, surface_desc); + /* FIXME: Test sizes, properly convert surface_desc */ return ddraw7_GetDisplayMode(&This->IDirectDraw7_iface, (DDSURFACEDESC2 *)surface_desc); } @@ -1333,6 +1498,7 @@ static HRESULT WINAPI ddraw1_GetDisplayMode(IDirectDraw *iface, DDSURFACEDESC *s TRACE("iface %p, surface_desc %p.\n", iface, surface_desc); + /* FIXME: Test sizes, properly convert surface_desc */ return ddraw7_GetDisplayMode(&This->IDirectDraw7_iface, (DDSURFACEDESC2 *)surface_desc); } @@ -1362,23 +1528,20 @@ static HRESULT WINAPI ddraw7_GetFourCCCodes(IDirectDraw7 *iface, DWORD *NumCodes WINED3DFMT_DXT1, WINED3DFMT_DXT2, WINED3DFMT_DXT3, WINED3DFMT_DXT4, WINED3DFMT_DXT5, WINED3DFMT_ATI2N, WINED3DFMT_NVHU, WINED3DFMT_NVHS }; + struct wined3d_display_mode mode; DWORD count = 0, i, outsize; HRESULT hr; - WINED3DDISPLAYMODE d3ddm; - WINED3DSURFTYPE type = This->ImplType; TRACE("iface %p, codes_count %p, codes %p.\n", iface, NumCodes, Codes); - wined3d_device_get_display_mode(This->wined3d_device, 0, &d3ddm); + wined3d_device_get_display_mode(This->wined3d_device, 0, &mode); outsize = NumCodes && Codes ? *NumCodes : 0; - if(type == SURFACE_UNKNOWN) type = SURFACE_GDI; - for (i = 0; i < (sizeof(formats) / sizeof(formats[0])); ++i) { - hr = wined3d_check_device_format(This->wineD3D, WINED3DADAPTER_DEFAULT, WINED3DDEVTYPE_HAL, - d3ddm.Format, 0, WINED3DRTYPE_SURFACE, formats[i], type); + hr = wined3d_check_device_format(This->wined3d, WINED3DADAPTER_DEFAULT, WINED3D_DEVICE_TYPE_HAL, + mode.format_id, 0, WINED3D_RTYPE_SURFACE, formats[i], DefaultSurfaceType); if (SUCCEEDED(hr)) { if (count < outsize) @@ -1403,15 +1566,6 @@ static HRESULT WINAPI ddraw4_GetFourCCCodes(IDirectDraw4 *iface, DWORD *codes_co return ddraw7_GetFourCCCodes(&This->IDirectDraw7_iface, codes_count, codes); } -static HRESULT WINAPI ddraw3_GetFourCCCodes(IDirectDraw3 *iface, DWORD *codes_count, DWORD *codes) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - - TRACE("iface %p, codes_count %p, codes %p.\n", iface, codes_count, codes); - - return ddraw7_GetFourCCCodes(&This->IDirectDraw7_iface, codes_count, codes); -} - static HRESULT WINAPI ddraw2_GetFourCCCodes(IDirectDraw2 *iface, DWORD *codes_count, DWORD *codes) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); @@ -1464,15 +1618,6 @@ static HRESULT WINAPI ddraw4_GetMonitorFrequency(IDirectDraw4 *iface, DWORD *fre return ddraw7_GetMonitorFrequency(&This->IDirectDraw7_iface, frequency); } -static HRESULT WINAPI ddraw3_GetMonitorFrequency(IDirectDraw3 *iface, DWORD *frequency) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - - TRACE("iface %p, frequency %p.\n", iface, frequency); - - return ddraw7_GetMonitorFrequency(&This->IDirectDraw7_iface, frequency); -} - static HRESULT WINAPI ddraw2_GetMonitorFrequency(IDirectDraw2 *iface, DWORD *frequency) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); @@ -1507,21 +1652,16 @@ static HRESULT WINAPI ddraw1_GetMonitorFrequency(IDirectDraw *iface, DWORD *freq *****************************************************************************/ static HRESULT WINAPI ddraw7_GetVerticalBlankStatus(IDirectDraw7 *iface, BOOL *status) { - IDirectDrawImpl *This = impl_from_IDirectDraw7(iface); + static BOOL fake_vblank; TRACE("iface %p, status %p.\n", iface, status); - /* This looks sane, the MSDN suggests it too */ - EnterCriticalSection(&ddraw_cs); if(!status) - { - LeaveCriticalSection(&ddraw_cs); return DDERR_INVALIDPARAMS; - } - *status = This->fake_vblank; - This->fake_vblank = !This->fake_vblank; - LeaveCriticalSection(&ddraw_cs); + *status = fake_vblank; + fake_vblank = !fake_vblank; + return DD_OK; } @@ -1534,15 +1674,6 @@ static HRESULT WINAPI ddraw4_GetVerticalBlankStatus(IDirectDraw4 *iface, BOOL *s return ddraw7_GetVerticalBlankStatus(&This->IDirectDraw7_iface, status); } -static HRESULT WINAPI ddraw3_GetVerticalBlankStatus(IDirectDraw3 *iface, BOOL *status) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - - TRACE("iface %p, status %p.\n", iface, status); - - return ddraw7_GetVerticalBlankStatus(&This->IDirectDraw7_iface, status); -} - static HRESULT WINAPI ddraw2_GetVerticalBlankStatus(IDirectDraw2 *iface, BOOL *status) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); @@ -1580,6 +1711,7 @@ static HRESULT WINAPI ddraw7_GetAvailableVidMem(IDirectDraw7 *iface, DDSCAPS2 *C DWORD *free) { IDirectDrawImpl *This = impl_from_IDirectDraw7(iface); + HRESULT hr = DD_OK; TRACE("iface %p, caps %p, total %p, free %p.\n", iface, Caps, total, free); @@ -1588,7 +1720,7 @@ static HRESULT WINAPI ddraw7_GetAvailableVidMem(IDirectDraw7 *iface, DDSCAPS2 *C TRACE("(%p) Asked for memory with description: ", This); DDRAW_dump_DDSCAPS2(Caps); } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); /* Todo: System memory vs local video memory vs non-local video memory * The MSDN also mentions differences between texture memory and other @@ -1597,17 +1729,23 @@ static HRESULT WINAPI ddraw7_GetAvailableVidMem(IDirectDraw7 *iface, DDSCAPS2 *C if( (!total) && (!free) ) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } - if (total) - *total = This->total_vidmem; if (free) *free = wined3d_device_get_available_texture_mem(This->wined3d_device); + if (total) + { + struct wined3d_adapter_identifier desc = {0}; - LeaveCriticalSection(&ddraw_cs); - return DD_OK; + hr = wined3d_get_adapter_identifier(This->wined3d, WINED3DADAPTER_DEFAULT, 0, &desc); + *total = desc.video_memory; + } + + wined3d_mutex_unlock(); + + return hr; } static HRESULT WINAPI ddraw4_GetAvailableVidMem(IDirectDraw4 *iface, @@ -1620,18 +1758,6 @@ static HRESULT WINAPI ddraw4_GetAvailableVidMem(IDirectDraw4 *iface, return ddraw7_GetAvailableVidMem(&This->IDirectDraw7_iface, caps, total, free); } -static HRESULT WINAPI ddraw3_GetAvailableVidMem(IDirectDraw3 *iface, DDSCAPS *caps, DWORD *total, - DWORD *free) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - DDSCAPS2 caps2; - - TRACE("iface %p, caps %p, total %p, free %p.\n", iface, caps, total, free); - - DDRAW_Convert_DDSCAPS_1_To_2(caps, &caps2); - return ddraw7_GetAvailableVidMem(&This->IDirectDraw7_iface, &caps2, total, free); -} - static HRESULT WINAPI ddraw2_GetAvailableVidMem(IDirectDraw2 *iface, DDSCAPS *caps, DWORD *total, DWORD *free) { @@ -1658,20 +1784,22 @@ static HRESULT WINAPI ddraw2_GetAvailableVidMem(IDirectDraw2 *iface, * DDERR_ALREADYINITIALIZED on repeated calls * *****************************************************************************/ -static HRESULT WINAPI ddraw7_Initialize(IDirectDraw7 *iface, GUID *Guid) +static HRESULT WINAPI ddraw7_Initialize(IDirectDraw7 *iface, GUID *guid) { IDirectDrawImpl *This = impl_from_IDirectDraw7(iface); - TRACE("iface %p, guid %s.\n", iface, debugstr_guid(Guid)); + TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid)); - if(This->initialized) - { + if (This->initialized) return DDERR_ALREADYINITIALIZED; - } - else - { - return DD_OK; - } + + /* FIXME: To properly take the GUID into account we should call + * ddraw_init() here instead of in DDRAW_Create(). */ + if (guid) + FIXME("Ignoring guid %s.\n", debugstr_guid(guid)); + + This->initialized = TRUE; + return DD_OK; } static HRESULT WINAPI ddraw4_Initialize(IDirectDraw4 *iface, GUID *guid) @@ -1683,15 +1811,6 @@ static HRESULT WINAPI ddraw4_Initialize(IDirectDraw4 *iface, GUID *guid) return ddraw7_Initialize(&This->IDirectDraw7_iface, guid); } -static HRESULT WINAPI ddraw3_Initialize(IDirectDraw3 *iface, GUID *guid) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - - TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid)); - - return ddraw7_Initialize(&This->IDirectDraw7_iface, guid); -} - static HRESULT WINAPI ddraw2_Initialize(IDirectDraw2 *iface, GUID *guid) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); @@ -1714,7 +1833,7 @@ static HRESULT WINAPI d3d1_Initialize(IDirect3D *iface, REFIID riid) { TRACE("iface %p, riid %s.\n", iface, debugstr_guid(riid)); - return D3D_OK; + return DDERR_ALREADYINITIALIZED; } /***************************************************************************** @@ -1746,15 +1865,6 @@ static HRESULT WINAPI ddraw4_FlipToGDISurface(IDirectDraw4 *iface) return ddraw7_FlipToGDISurface(&This->IDirectDraw7_iface); } -static HRESULT WINAPI ddraw3_FlipToGDISurface(IDirectDraw3 *iface) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - - TRACE("iface %p.\n", iface); - - return ddraw7_FlipToGDISurface(&This->IDirectDraw7_iface); -} - static HRESULT WINAPI ddraw2_FlipToGDISurface(IDirectDraw2 *iface) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); @@ -1819,15 +1929,6 @@ static HRESULT WINAPI ddraw4_WaitForVerticalBlank(IDirectDraw4 *iface, DWORD fla return ddraw7_WaitForVerticalBlank(&This->IDirectDraw7_iface, flags, event); } -static HRESULT WINAPI ddraw3_WaitForVerticalBlank(IDirectDraw3 *iface, DWORD flags, HANDLE event) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - - TRACE("iface %p, flags %#x, event %p.\n", iface, flags, event); - - return ddraw7_WaitForVerticalBlank(&This->IDirectDraw7_iface, flags, event); -} - static HRESULT WINAPI ddraw2_WaitForVerticalBlank(IDirectDraw2 *iface, DWORD flags, HANDLE event) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); @@ -1861,29 +1962,30 @@ static HRESULT WINAPI ddraw1_WaitForVerticalBlank(IDirectDraw *iface, DWORD flag static HRESULT WINAPI ddraw7_GetScanLine(IDirectDraw7 *iface, DWORD *Scanline) { IDirectDrawImpl *This = impl_from_IDirectDraw7(iface); + struct wined3d_display_mode mode; + static DWORD cur_scanline; static BOOL hide = FALSE; - WINED3DDISPLAYMODE Mode; TRACE("iface %p, line %p.\n", iface, Scanline); /* This function is called often, so print the fixme only once */ - EnterCriticalSection(&ddraw_cs); if(!hide) { FIXME("iface %p, line %p partial stub!\n", iface, Scanline); hide = TRUE; } - wined3d_device_get_display_mode(This->wined3d_device, 0, &Mode); + wined3d_mutex_lock(); + wined3d_device_get_display_mode(This->wined3d_device, 0, &mode); + wined3d_mutex_unlock(); /* Fake the line sweeping of the monitor */ /* FIXME: We should synchronize with a source to keep the refresh rate */ - *Scanline = This->cur_scanline++; + *Scanline = cur_scanline++; /* Assume 20 scan lines in the vertical blank */ - if (This->cur_scanline >= Mode.Height + 20) - This->cur_scanline = 0; + if (cur_scanline >= mode.height + 20) + cur_scanline = 0; - LeaveCriticalSection(&ddraw_cs); return DD_OK; } @@ -1896,15 +1998,6 @@ static HRESULT WINAPI ddraw4_GetScanLine(IDirectDraw4 *iface, DWORD *line) return ddraw7_GetScanLine(&This->IDirectDraw7_iface, line); } -static HRESULT WINAPI ddraw3_GetScanLine(IDirectDraw3 *iface, DWORD *line) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - - TRACE("iface %p, line %p.\n", iface, line); - - return ddraw7_GetScanLine(&This->IDirectDraw7_iface, line); -} - static HRESULT WINAPI ddraw2_GetScanLine(IDirectDraw2 *iface, DWORD *line) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); @@ -1968,62 +2061,43 @@ static HRESULT WINAPI ddraw4_TestCooperativeLevel(IDirectDraw4 *iface) static HRESULT WINAPI ddraw7_GetGDISurface(IDirectDraw7 *iface, IDirectDrawSurface7 **GDISurface) { IDirectDrawImpl *This = impl_from_IDirectDraw7(iface); - struct wined3d_surface *wined3d_surface; - IDirectDrawSurface7 *ddsurf; - HRESULT hr; - DDSCAPS2 ddsCaps; TRACE("iface %p, surface %p.\n", iface, GDISurface); - /* Get the back buffer from the wineD3DDevice and search its - * attached surfaces for the front buffer. */ - EnterCriticalSection(&ddraw_cs); - hr = wined3d_device_get_back_buffer(This->wined3d_device, - 0, 0, WINED3DBACKBUFFER_TYPE_MONO, &wined3d_surface); - if (FAILED(hr) || !wined3d_surface) + wined3d_mutex_lock(); + + if (!(*GDISurface = &This->primary->IDirectDrawSurface7_iface)) { - ERR("IWineD3DDevice::GetBackBuffer failed\n"); - LeaveCriticalSection(&ddraw_cs); + WARN("Primary not created yet.\n"); + wined3d_mutex_unlock(); return DDERR_NOTFOUND; } + IDirectDrawSurface7_AddRef(*GDISurface); - ddsurf = wined3d_surface_get_parent(wined3d_surface); - wined3d_surface_decref(wined3d_surface); + wined3d_mutex_unlock(); - /* Find the front buffer */ - ddsCaps.dwCaps = DDSCAPS_FRONTBUFFER; - hr = IDirectDrawSurface7_GetAttachedSurface(ddsurf, - &ddsCaps, - GDISurface); - if(hr != DD_OK) - { - ERR("IDirectDrawSurface7::GetAttachedSurface failed, hr = %x\n", hr); - } - - /* The AddRef is OK this time */ - LeaveCriticalSection(&ddraw_cs); - return hr; + return DD_OK; } static HRESULT WINAPI ddraw4_GetGDISurface(IDirectDraw4 *iface, IDirectDrawSurface4 **surface) { IDirectDrawImpl *This = impl_from_IDirectDraw4(iface); - - TRACE("iface %p, surface %p.\n", iface, surface); - - return ddraw7_GetGDISurface(&This->IDirectDraw7_iface, (IDirectDrawSurface7 **)surface); -} - -static HRESULT WINAPI ddraw3_GetGDISurface(IDirectDraw3 *iface, IDirectDrawSurface **surface) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); IDirectDrawSurface7 *surface7; + IDirectDrawSurfaceImpl *surface_impl; HRESULT hr; TRACE("iface %p, surface %p.\n", iface, surface); hr = ddraw7_GetGDISurface(&This->IDirectDraw7_iface, &surface7); - *surface = surface7 ? (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)surface7)->IDirectDrawSurface3_vtbl : NULL; + if (FAILED(hr)) + { + *surface = NULL; + return hr; + } + surface_impl = impl_from_IDirectDrawSurface7(surface7); + *surface = &surface_impl->IDirectDrawSurface4_iface; + IDirectDrawSurface4_AddRef(*surface); + IDirectDrawSurface7_Release(surface7); return hr; } @@ -2032,12 +2106,21 @@ static HRESULT WINAPI ddraw2_GetGDISurface(IDirectDraw2 *iface, IDirectDrawSurfa { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); IDirectDrawSurface7 *surface7; + IDirectDrawSurfaceImpl *surface_impl; HRESULT hr; TRACE("iface %p, surface %p.\n", iface, surface); hr = ddraw7_GetGDISurface(&This->IDirectDraw7_iface, &surface7); - *surface = surface7 ? (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)surface7)->IDirectDrawSurface3_vtbl : NULL; + if (FAILED(hr)) + { + *surface = NULL; + return hr; + } + surface_impl = impl_from_IDirectDrawSurface7(surface7); + *surface = &surface_impl->IDirectDrawSurface_iface; + IDirectDrawSurface_AddRef(*surface); + IDirectDrawSurface7_Release(surface7); return hr; } @@ -2046,12 +2129,21 @@ static HRESULT WINAPI ddraw1_GetGDISurface(IDirectDraw *iface, IDirectDrawSurfac { IDirectDrawImpl *This = impl_from_IDirectDraw(iface); IDirectDrawSurface7 *surface7; + IDirectDrawSurfaceImpl *surface_impl; HRESULT hr; TRACE("iface %p, surface %p.\n", iface, surface); hr = ddraw7_GetGDISurface(&This->IDirectDraw7_iface, &surface7); - *surface = surface7 ? (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)surface7)->IDirectDrawSurface3_vtbl : NULL; + if (FAILED(hr)) + { + *surface = NULL; + return hr; + } + surface_impl = impl_from_IDirectDrawSurface7(surface7); + *surface = &surface_impl->IDirectDrawSurface_iface; + IDirectDrawSurface_AddRef(*surface); + IDirectDrawSurface7_Release(surface7); return hr; } @@ -2067,9 +2159,7 @@ static HRESULT CALLBACK EnumDisplayModesCallbackThunk(DDSURFACEDESC2 *surface_de struct displaymodescallback_context *cbcontext = context; DDSURFACEDESC desc; - memcpy(&desc, surface_desc, sizeof(desc)); - desc.dwSize = sizeof(desc); - + DDSD2_to_DDSD(surface_desc, &desc); return cbcontext->func(&desc, cbcontext->context); } @@ -2095,10 +2185,10 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags, DDSURFACEDESC2 *DDSD, void *Context, LPDDENUMMODESCALLBACK2 cb) { IDirectDrawImpl *This = impl_from_IDirectDraw7(iface); + struct wined3d_display_mode *enum_modes = NULL; + struct wined3d_display_mode mode; unsigned int modenum, fmt; - WINED3DDISPLAYMODE mode; DDSURFACEDESC2 callback_sd; - WINED3DDISPLAYMODE *enum_modes = NULL; unsigned enum_mode_count = 0, enum_mode_array_size = 0; DDPIXELFORMAT pixelformat; @@ -2112,22 +2202,18 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags, TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n", iface, Flags, DDSD, Context, cb); - EnterCriticalSection(&ddraw_cs); - /* This looks sane */ - if(!cb) - { - LeaveCriticalSection(&ddraw_cs); + if (!cb) return DDERR_INVALIDPARAMS; - } + wined3d_mutex_lock(); if(!(Flags & DDEDM_REFRESHRATES)) { enum_mode_array_size = 16; - enum_modes = HeapAlloc(GetProcessHeap(), 0, sizeof(WINED3DDISPLAYMODE) * enum_mode_array_size); + enum_modes = HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_modes) * enum_mode_array_size); if (!enum_modes) { ERR("Out of memory\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_OUTOFMEMORY; } } @@ -2136,17 +2222,21 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags, for(fmt = 0; fmt < (sizeof(checkFormatList) / sizeof(checkFormatList[0])); fmt++) { modenum = 0; - while (wined3d_enum_adapter_modes(This->wineD3D, WINED3DADAPTER_DEFAULT, + while (wined3d_enum_adapter_modes(This->wined3d, WINED3DADAPTER_DEFAULT, checkFormatList[fmt], modenum++, &mode) == WINED3D_OK) { - PixelFormat_WineD3DtoDD(&pixelformat, mode.Format); - if(DDSD) + PixelFormat_WineD3DtoDD(&pixelformat, mode.format_id); + if (DDSD) { - if(DDSD->dwFlags & DDSD_WIDTH && mode.Width != DDSD->dwWidth) continue; - if(DDSD->dwFlags & DDSD_HEIGHT && mode.Height != DDSD->dwHeight) continue; - if(DDSD->dwFlags & DDSD_REFRESHRATE && mode.RefreshRate != DDSD->u2.dwRefreshRate) continue; - if (DDSD->dwFlags & DDSD_PIXELFORMAT && - pixelformat.u1.dwRGBBitCount != DDSD->u4.ddpfPixelFormat.u1.dwRGBBitCount) continue; + if (DDSD->dwFlags & DDSD_WIDTH && mode.width != DDSD->dwWidth) + continue; + if (DDSD->dwFlags & DDSD_HEIGHT && mode.height != DDSD->dwHeight) + continue; + if (DDSD->dwFlags & DDSD_REFRESHRATE && mode.refresh_rate != DDSD->u2.dwRefreshRate) + continue; + if (DDSD->dwFlags & DDSD_PIXELFORMAT + && pixelformat.u1.dwRGBBitCount != DDSD->u4.ddpfPixelFormat.u1.dwRGBBitCount) + continue; } if(!(Flags & DDEDM_REFRESHRATES)) @@ -2160,8 +2250,8 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags, for (i = 0; i < enum_mode_count; i++) { - if(enum_modes[i].Width == mode.Width && enum_modes[i].Height == mode.Height && - enum_modes[i].Format == mode.Format) + if (enum_modes[i].width == mode.width && enum_modes[i].height == mode.height + && enum_modes[i].format_id == mode.format_id) { found = TRUE; break; @@ -2176,18 +2266,16 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags, callback_sd.u4.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); callback_sd.dwFlags = DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_PITCH|DDSD_REFRESHRATE; - if(Flags & DDEDM_REFRESHRATES) - { - callback_sd.u2.dwRefreshRate = mode.RefreshRate; - } + if (Flags & DDEDM_REFRESHRATES) + callback_sd.u2.dwRefreshRate = mode.refresh_rate; - callback_sd.dwWidth = mode.Width; - callback_sd.dwHeight = mode.Height; + callback_sd.dwWidth = mode.width; + callback_sd.dwHeight = mode.height; callback_sd.u4.ddpfPixelFormat=pixelformat; /* Calc pitch and DWORD align like MSDN says */ - callback_sd.u1.lPitch = (callback_sd.u4.ddpfPixelFormat.u1.dwRGBBitCount / 8) * mode.Width; + callback_sd.u1.lPitch = (callback_sd.u4.ddpfPixelFormat.u1.dwRGBBitCount / 8) * mode.width; callback_sd.u1.lPitch = (callback_sd.u1.lPitch + 3) & ~3; TRACE("Enumerating %dx%dx%d @%d\n", callback_sd.dwWidth, callback_sd.dwHeight, callback_sd.u4.ddpfPixelFormat.u1.dwRGBBitCount, @@ -2197,7 +2285,7 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags, { TRACE("Application asked to terminate the enumeration\n"); HeapFree(GetProcessHeap(), 0, enum_modes); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DD_OK; } @@ -2205,16 +2293,16 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags, { if (enum_mode_count == enum_mode_array_size) { - WINED3DDISPLAYMODE *new_enum_modes; + struct wined3d_display_mode *new_enum_modes; enum_mode_array_size *= 2; - new_enum_modes = HeapReAlloc(GetProcessHeap(), 0, enum_modes, sizeof(WINED3DDISPLAYMODE) * enum_mode_array_size); - + new_enum_modes = HeapReAlloc(GetProcessHeap(), 0, enum_modes, + sizeof(*new_enum_modes) * enum_mode_array_size); if (!new_enum_modes) { ERR("Out of memory\n"); HeapFree(GetProcessHeap(), 0, enum_modes); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_OUTOFMEMORY; } @@ -2228,7 +2316,8 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags, TRACE("End of enumeration\n"); HeapFree(GetProcessHeap(), 0, enum_modes); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return DD_OK; } @@ -2243,27 +2332,12 @@ static HRESULT WINAPI ddraw4_EnumDisplayModes(IDirectDraw4 *iface, DWORD flags, return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags, surface_desc, context, callback); } -static HRESULT WINAPI ddraw3_EnumDisplayModes(IDirectDraw3 *iface, DWORD flags, - DDSURFACEDESC *surface_desc, void *context, LPDDENUMMODESCALLBACK callback) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - struct displaymodescallback_context cbcontext; - - TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n", - iface, flags, surface_desc, context, callback); - - cbcontext.func = callback; - cbcontext.context = context; - - return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags, (DDSURFACEDESC2 *)surface_desc, - &cbcontext, EnumDisplayModesCallbackThunk); -} - static HRESULT WINAPI ddraw2_EnumDisplayModes(IDirectDraw2 *iface, DWORD flags, DDSURFACEDESC *surface_desc, void *context, LPDDENUMMODESCALLBACK callback) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); struct displaymodescallback_context cbcontext; + DDSURFACEDESC2 surface_desc2; TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n", iface, flags, surface_desc, context, callback); @@ -2271,8 +2345,9 @@ static HRESULT WINAPI ddraw2_EnumDisplayModes(IDirectDraw2 *iface, DWORD flags, cbcontext.func = callback; cbcontext.context = context; - return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags, (DDSURFACEDESC2 *)surface_desc, - &cbcontext, EnumDisplayModesCallbackThunk); + if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2); + return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags, + surface_desc ? &surface_desc2 : NULL, &cbcontext, EnumDisplayModesCallbackThunk); } static HRESULT WINAPI ddraw1_EnumDisplayModes(IDirectDraw *iface, DWORD flags, @@ -2280,6 +2355,7 @@ static HRESULT WINAPI ddraw1_EnumDisplayModes(IDirectDraw *iface, DWORD flags, { IDirectDrawImpl *This = impl_from_IDirectDraw(iface); struct displaymodescallback_context cbcontext; + DDSURFACEDESC2 surface_desc2; TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n", iface, flags, surface_desc, context, callback); @@ -2287,8 +2363,9 @@ static HRESULT WINAPI ddraw1_EnumDisplayModes(IDirectDraw *iface, DWORD flags, cbcontext.func = callback; cbcontext.context = context; - return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags, (DDSURFACEDESC2 *)surface_desc, - &cbcontext, EnumDisplayModesCallbackThunk); + if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2); + return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags, + surface_desc ? &surface_desc2 : NULL, &cbcontext, EnumDisplayModesCallbackThunk); } /***************************************************************************** @@ -2409,6 +2486,7 @@ static HRESULT WINAPI ddraw4_GetSurfaceFromDC(IDirectDraw4 *iface, HDC dc, { IDirectDrawImpl *This = impl_from_IDirectDraw4(iface); IDirectDrawSurface7 *surface7; + IDirectDrawSurfaceImpl *surface_impl; HRESULT hr; TRACE("iface %p, dc %p, surface %p.\n", iface, dc, surface); @@ -2416,21 +2494,20 @@ static HRESULT WINAPI ddraw4_GetSurfaceFromDC(IDirectDraw4 *iface, HDC dc, if (!surface) return E_INVALIDARG; hr = ddraw7_GetSurfaceFromDC(&This->IDirectDraw7_iface, dc, &surface7); - *surface = surface7 ? (IDirectDrawSurface4 *)&((IDirectDrawSurfaceImpl *)surface7)->IDirectDrawSurface3_vtbl : NULL; + if (FAILED(hr)) + { + *surface = NULL; + return hr; + } + surface_impl = impl_from_IDirectDrawSurface7(surface7); + /* Tests say this is true */ + *surface = (IDirectDrawSurface4 *)&surface_impl->IDirectDrawSurface_iface; + IDirectDrawSurface_AddRef(&surface_impl->IDirectDrawSurface_iface); + IDirectDrawSurface7_Release(surface7); return hr; } -static HRESULT WINAPI ddraw3_GetSurfaceFromDC(IDirectDraw3 *iface, HDC dc, - IDirectDrawSurface **surface) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - - TRACE("iface %p, dc %p, surface %p.\n", iface, dc, surface); - - return ddraw7_GetSurfaceFromDC(&This->IDirectDraw7_iface, dc, (IDirectDrawSurface7 **)surface); -} - /***************************************************************************** * IDirectDraw7::RestoreAllSurfaces * @@ -2504,113 +2581,6 @@ static HRESULT WINAPI ddraw7_StartModeTest(IDirectDraw7 *iface, SIZE *Modes, DWO return DD_OK; } -/***************************************************************************** - * ddraw_recreate_surfaces_cb - * - * Enumeration callback for ddraw_recreate_surface. - * It re-recreates the WineD3DSurface. It's pretty straightforward - * - *****************************************************************************/ -HRESULT WINAPI ddraw_recreate_surfaces_cb(IDirectDrawSurface7 *surf, DDSURFACEDESC2 *desc, void *Context) -{ - IDirectDrawSurfaceImpl *surfImpl = (IDirectDrawSurfaceImpl *)surf; - struct wined3d_resource_desc wined3d_desc; - struct wined3d_resource *wined3d_resource; - IDirectDrawImpl *This = surfImpl->ddraw; - struct wined3d_surface *wined3d_surface; - struct wined3d_swapchain *swapchain; - struct wined3d_clipper *clipper; - void *parent; - HRESULT hr; - - TRACE("surface %p, surface_desc %p, context %p.\n", - surf, desc, Context); - - /* For the enumeration */ - IDirectDrawSurface7_Release(surf); - - if(surfImpl->ImplType == This->ImplType) return DDENUMRET_OK; /* Continue */ - - /* Get the objects */ - swapchain = surfImpl->wined3d_swapchain; - surfImpl->wined3d_swapchain = NULL; - wined3d_surface = surfImpl->wined3d_surface; - - /* get the clipper */ - clipper = wined3d_surface_get_clipper(wined3d_surface); - - /* Get the surface properties */ - wined3d_resource = wined3d_surface_get_resource(wined3d_surface); - wined3d_resource_get_desc(wined3d_resource, &wined3d_desc); - - parent = wined3d_surface_get_parent(wined3d_surface); - hr = wined3d_surface_create(This->wined3d_device, wined3d_desc.width, wined3d_desc.height, - wined3d_desc.format, TRUE, FALSE, surfImpl->mipmap_level, wined3d_desc.usage, wined3d_desc.pool, - wined3d_desc.multisample_type, wined3d_desc.multisample_quality, This->ImplType, - parent, &ddraw_surface_wined3d_parent_ops, &surfImpl->wined3d_surface); - if (FAILED(hr)) - { - surfImpl->wined3d_surface = wined3d_surface; - return hr; - } - - wined3d_surface_set_clipper(surfImpl->wined3d_surface, clipper); - - /* TODO: Copy the surface content, except for render targets */ - - /* If there's a swapchain, it owns the wined3d surfaces. So Destroy - * the swapchain - */ - if (swapchain) - { - /* The backbuffers have the swapchain set as well, but the primary - * owns it and destroys it. */ - if (surfImpl->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) - wined3d_device_uninit_gdi(This->wined3d_device); - surfImpl->isRenderTarget = FALSE; - } - else - { - if (!wined3d_surface_decref(wined3d_surface)) - TRACE("Surface released successful, next surface\n"); - else - ERR("Something's still holding the old WineD3DSurface\n"); - } - - surfImpl->ImplType = This->ImplType; - - return DDENUMRET_OK; -} - -/***************************************************************************** - * ddraw_recreate_surfaces - * - * A function, that converts all wineD3DSurfaces to the new implementation type - * It enumerates all surfaces with IWineD3DDevice::EnumSurfaces, creates a - * new WineD3DSurface, copies the content and releases the old surface - * - *****************************************************************************/ -static HRESULT ddraw_recreate_surfaces(IDirectDrawImpl *This) -{ - DDSURFACEDESC2 desc; - TRACE("(%p): Switch to implementation %d\n", This, This->ImplType); - - if(This->ImplType != SURFACE_OPENGL && This->d3d_initialized) - { - /* Should happen almost never */ - FIXME("(%p) Switching to non-opengl surfaces with d3d started. Is this a bug?\n", This); - /* Shutdown d3d */ - wined3d_device_uninit_3d(This->wined3d_device); - } - /* Contrary: D3D starting is handled by the caller, because it knows the render target */ - - memset(&desc, 0, sizeof(desc)); - desc.dwSize = sizeof(desc); - - return IDirectDraw7_EnumSurfaces(&This->IDirectDraw7_iface, 0, &desc, This, - ddraw_recreate_surfaces_cb); -} - /***************************************************************************** * ddraw_create_surface * @@ -2626,9 +2596,8 @@ static HRESULT ddraw_recreate_surfaces(IDirectDrawImpl *This) * *****************************************************************************/ static HRESULT ddraw_create_surface(IDirectDrawImpl *This, DDSURFACEDESC2 *pDDSD, - IDirectDrawSurfaceImpl **ppSurf, UINT level) + IDirectDrawSurfaceImpl **ppSurf, UINT level, UINT version) { - WINED3DSURFTYPE ImplType = This->ImplType; HRESULT hr; TRACE("ddraw %p, surface_desc %p, surface %p, level %u.\n", @@ -2640,59 +2609,10 @@ static HRESULT ddraw_create_surface(IDirectDrawImpl *This, DDSURFACEDESC2 *pDDSD DDRAW_dump_surface_desc(pDDSD); } - /* Select the surface type, if it wasn't choosen yet */ - if(ImplType == SURFACE_UNKNOWN) + if ((pDDSD->ddsCaps.dwCaps & DDSCAPS_3DDEVICE) && DefaultSurfaceType != SURFACE_OPENGL) { - /* Use GL Surfaces if a D3DDEVICE Surface is requested */ - if(pDDSD->ddsCaps.dwCaps & DDSCAPS_3DDEVICE) - { - TRACE("(%p) Choosing GL surfaces because a 3DDEVICE Surface was requested\n", This); - ImplType = SURFACE_OPENGL; - } - - /* Otherwise use GDI surfaces for now */ - else - { - TRACE("(%p) Choosing GDI surfaces for 2D rendering\n", This); - ImplType = SURFACE_GDI; - } - - /* Policy if all surface implementations are available: - * First, check if a default type was set with winecfg. If not, - * try Xrender surfaces, and use them if they work. Next, check if - * accelerated OpenGL is available, and use GL surfaces in this - * case. If all else fails, use GDI surfaces. If a 3DDEVICE surface - * was created, always use OpenGL surfaces. - * - * (Note: Xrender surfaces are not implemented for now, the - * unaccelerated implementation uses GDI to render in Software) - */ - - /* Store the type. If it needs to be changed, all WineD3DSurfaces have to - * be re-created. This could be done with IDirectDrawSurface7::Restore - */ - This->ImplType = ImplType; - } - else - { - if ((pDDSD->ddsCaps.dwCaps & DDSCAPS_3DDEVICE) - && (This->ImplType != SURFACE_OPENGL) - && DefaultSurfaceType == SURFACE_UNKNOWN) - { - /* We have to change to OpenGL, - * and re-create all WineD3DSurfaces - */ - ImplType = SURFACE_OPENGL; - This->ImplType = ImplType; - TRACE("(%p) Re-creating all surfaces\n", This); - ddraw_recreate_surfaces(This); - TRACE("(%p) Done recreating all surfaces\n", This); - } - else if(This->ImplType != SURFACE_OPENGL && pDDSD->ddsCaps.dwCaps & DDSCAPS_3DDEVICE) - { - WARN("The application requests a 3D capable surface, but a non-opengl surface was set in the registry\n"); - /* Do not fail surface creation, only fail 3D device creation */ - } + WARN("The application requests a 3D capable surface, but a non-OpenGL surface type was set in the registry.\n"); + /* Do not fail surface creation, only fail 3D device creation. */ } /* Create the Surface object */ @@ -2703,7 +2623,7 @@ static HRESULT ddraw_create_surface(IDirectDrawImpl *This, DDSURFACEDESC2 *pDDSD return DDERR_OUTOFVIDEOMEMORY; } - hr = ddraw_surface_init(*ppSurf, This, pDDSD, level, ImplType); + hr = ddraw_surface_init(*ppSurf, This, pDDSD, level, version); if (FAILED(hr)) { WARN("Failed to initialize surface, hr %#x.\n", hr); @@ -2712,7 +2632,6 @@ static HRESULT ddraw_create_surface(IDirectDrawImpl *This, DDSURFACEDESC2 *pDDSD } /* Increase the surface counter, and attach the surface */ - InterlockedIncrement(&This->surfaces); list_add_head(&This->surface_list, &(*ppSurf)->surface_list_entry); TRACE("Created surface %p.\n", *ppSurf); @@ -2738,7 +2657,7 @@ CreateAdditionalSurfaces(IDirectDrawImpl *This, IDirectDrawSurfaceImpl *root, UINT count, DDSURFACEDESC2 DDSD, - BOOL CubeFaceRoot) + BOOL CubeFaceRoot, UINT version) { UINT i, j, level = 0; HRESULT hr; @@ -2765,7 +2684,7 @@ CreateAdditionalSurfaces(IDirectDrawImpl *This, } CubeFaceRoot = FALSE; - hr = ddraw_create_surface(This, &DDSD, &object2, level); + hr = ddraw_create_surface(This, &DDSD, &object2, level, version); if(hr != DD_OK) { return hr; @@ -2789,155 +2708,11 @@ CreateAdditionalSurfaces(IDirectDrawImpl *This, return DD_OK; } -/* Must set all attached surfaces (e.g. mipmaps) versions as well */ -static void ddraw_set_surface_version(IDirectDrawSurfaceImpl *surface, UINT version) +static HRESULT CDECL ddraw_reset_enum_callback(struct wined3d_resource *resource) { - unsigned int i; - - TRACE("surface %p, version %u -> %u.\n", surface, surface->version, version); - - surface->version = version; - for (i = 0; i < MAX_COMPLEX_ATTACHED; ++i) - { - if (!surface->complex_array[i]) break; - ddraw_set_surface_version(surface->complex_array[i], version); - } - while ((surface = surface->next_attached)) - { - ddraw_set_surface_version(surface, version); - } -} - -/***************************************************************************** - * ddraw_attach_d3d_device - * - * Initializes the D3D capabilities of WineD3D - * - * Params: - * primary: The primary surface for D3D - * - * Returns - * DD_OK on success, - * DDERR_* otherwise - * - *****************************************************************************/ -static HRESULT ddraw_attach_d3d_device(IDirectDrawImpl *ddraw, IDirectDrawSurfaceImpl *primary) -{ - WINED3DPRESENT_PARAMETERS localParameters; - HWND window = ddraw->dest_window; - HRESULT hr; - - TRACE("ddraw %p, primary %p.\n", ddraw, primary); - - if (!window || window == GetDesktopWindow()) - { - window = CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME, "Hidden D3D Window", - WS_DISABLED, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), - NULL, NULL, NULL, NULL); - if (!window) - { - ERR("Failed to create window, last error %#x.\n", GetLastError()); - return E_FAIL; - } - - ShowWindow(window, SW_HIDE); /* Just to be sure */ - WARN("No window for the Direct3DDevice, created hidden window %p.\n", window); - } - else - { - TRACE("Using existing window %p for Direct3D rendering.\n", window); - } - ddraw->d3d_window = window; - - /* Store the future Render Target surface */ - ddraw->d3d_target = primary; - - /* Use the surface description for the device parameters, not the device - * settings. The application might render to an offscreen surface. */ - localParameters.BackBufferWidth = primary->surface_desc.dwWidth; - localParameters.BackBufferHeight = primary->surface_desc.dwHeight; - localParameters.BackBufferFormat = PixelFormat_DD2WineD3D(&primary->surface_desc.u4.ddpfPixelFormat); - localParameters.BackBufferCount = (primary->surface_desc.dwFlags & DDSD_BACKBUFFERCOUNT) - ? primary->surface_desc.u5.dwBackBufferCount : 0; - localParameters.MultiSampleType = WINED3DMULTISAMPLE_NONE; - localParameters.MultiSampleQuality = 0; - localParameters.SwapEffect = WINED3DSWAPEFFECT_COPY; - localParameters.hDeviceWindow = window; - localParameters.Windowed = !(ddraw->cooperative_level & DDSCL_FULLSCREEN); - localParameters.EnableAutoDepthStencil = TRUE; - localParameters.AutoDepthStencilFormat = WINED3DFMT_D16_UNORM; - localParameters.Flags = 0; - localParameters.FullScreen_RefreshRateInHz = WINED3DPRESENT_RATE_DEFAULT; - localParameters.PresentationInterval = WINED3DPRESENT_INTERVAL_DEFAULT; - localParameters.AutoRestoreDisplayMode = FALSE; - - /* Set this NOW, otherwise creating the depth stencil surface will cause a - * recursive loop until ram or emulated video memory is full. */ - ddraw->d3d_initialized = TRUE; - hr = wined3d_device_init_3d(ddraw->wined3d_device, &localParameters); - if (FAILED(hr)) - { - ddraw->d3d_target = NULL; - ddraw->d3d_initialized = FALSE; - return hr; - } - - ddraw->declArraySize = 2; - ddraw->decls = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ddraw->decls) * ddraw->declArraySize); - if (!ddraw->decls) - { - ERR("Error allocating an array for the converted vertex decls.\n"); - ddraw->declArraySize = 0; - hr = wined3d_device_uninit_3d(ddraw->wined3d_device); - return E_OUTOFMEMORY; - } - - TRACE("Successfully initialized 3D.\n"); - return DD_OK; } -static HRESULT ddraw_create_gdi_swapchain(IDirectDrawImpl *ddraw, IDirectDrawSurfaceImpl *primary) -{ - WINED3DPRESENT_PARAMETERS presentation_parameters; - HWND window; - HRESULT hr; - - window = ddraw->dest_window; - - memset(&presentation_parameters, 0, sizeof(presentation_parameters)); - - /* Use the surface description for the device parameters, not the device - * settings. The application might render to an offscreen surface. */ - presentation_parameters.BackBufferWidth = primary->surface_desc.dwWidth; - presentation_parameters.BackBufferHeight = primary->surface_desc.dwHeight; - presentation_parameters.BackBufferFormat = PixelFormat_DD2WineD3D(&primary->surface_desc.u4.ddpfPixelFormat); - presentation_parameters.BackBufferCount = (primary->surface_desc.dwFlags & DDSD_BACKBUFFERCOUNT) - ? primary->surface_desc.u5.dwBackBufferCount : 0; - presentation_parameters.MultiSampleType = WINED3DMULTISAMPLE_NONE; - presentation_parameters.MultiSampleQuality = 0; - presentation_parameters.SwapEffect = WINED3DSWAPEFFECT_FLIP; - presentation_parameters.hDeviceWindow = window; - presentation_parameters.Windowed = !(ddraw->cooperative_level & DDSCL_FULLSCREEN); - presentation_parameters.EnableAutoDepthStencil = FALSE; /* Not on GDI swapchains */ - presentation_parameters.AutoDepthStencilFormat = 0; - presentation_parameters.Flags = 0; - presentation_parameters.FullScreen_RefreshRateInHz = WINED3DPRESENT_RATE_DEFAULT; - presentation_parameters.PresentationInterval = WINED3DPRESENT_INTERVAL_DEFAULT; - presentation_parameters.AutoRestoreDisplayMode = FALSE; - - ddraw->d3d_target = primary; - hr = wined3d_device_init_gdi(ddraw->wined3d_device, &presentation_parameters); - ddraw->d3d_target = NULL; - if (FAILED(hr)) - { - WARN("Failed to initialize GDI ddraw implementation, hr %#x.\n", hr); - primary->wined3d_swapchain = NULL; - } - - return hr; -} - /***************************************************************************** * IDirectDraw7::CreateSurface * @@ -3016,13 +2791,13 @@ static HRESULT ddraw_create_gdi_swapchain(IDirectDrawImpl *ddraw, IDirectDrawSur * *****************************************************************************/ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD, - IDirectDrawSurface7 **Surf, IUnknown *UnkOuter) + IDirectDrawSurfaceImpl **Surf, IUnknown *UnkOuter, UINT version) { IDirectDrawSurfaceImpl *object = NULL; + struct wined3d_display_mode mode; HRESULT hr; LONG extra_surfaces = 0; DDSURFACEDESC2 desc2; - WINED3DDISPLAYMODE Mode; const DWORD sysvidmem = DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY; TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p.\n", ddraw, DDSD, Surf, UnkOuter); @@ -3033,19 +2808,16 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD, TRACE(" (%p) Requesting surface desc :\n", ddraw); DDRAW_dump_surface_desc(DDSD); } - EnterCriticalSection(&ddraw_cs); if (UnkOuter != NULL) { FIXME("(%p) : outer != NULL?\n", ddraw); - LeaveCriticalSection(&ddraw_cs); return CLASS_E_NOAGGREGATION; /* unchecked */ } if (Surf == NULL) { FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", ddraw); - LeaveCriticalSection(&ddraw_cs); return E_POINTER; /* unchecked */ } @@ -3074,14 +2846,12 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD, TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n", ddraw); *Surf = NULL; - LeaveCriticalSection(&ddraw_cs); return DDERR_NOEXCLUSIVEMODE; } if((DDSD->ddsCaps.dwCaps & (DDSCAPS_BACKBUFFER | DDSCAPS_PRIMARYSURFACE)) == (DDSCAPS_BACKBUFFER | DDSCAPS_PRIMARYSURFACE)) { WARN("Application wanted to create back buffer primary surface\n"); - LeaveCriticalSection(&ddraw_cs); return DDERR_INVALIDCAPS; } @@ -3089,7 +2859,6 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD, { /* This is a special switch in ddrawex.dll, but not allowed in ddraw.dll */ WARN("Application tries to put the surface in both system and video memory\n"); - LeaveCriticalSection(&ddraw_cs); *Surf = NULL; return DDERR_INVALIDCAPS; } @@ -3101,14 +2870,12 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD, !(DDSD->ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP)) { WARN("Cube map faces requested without cube map flag\n"); - LeaveCriticalSection(&ddraw_cs); return DDERR_INVALIDCAPS; } if(DDSD->ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP && (DDSD->ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP_ALLFACES) == 0) { WARN("Cube map without faces requested\n"); - LeaveCriticalSection(&ddraw_cs); return DDERR_INVALIDPARAMS; } @@ -3129,34 +2896,34 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD, desc2.u4.ddpfPixelFormat.dwSize=sizeof(DDPIXELFORMAT); /* Just to be sure */ /* Get the video mode from WineD3D - we will need it */ - hr = wined3d_device_get_display_mode(ddraw->wined3d_device, 0, &Mode); + hr = wined3d_device_get_display_mode(ddraw->wined3d_device, 0, &mode); if (FAILED(hr)) { ERR("Failed to read display mode from wined3d\n"); switch(ddraw->orig_bpp) { case 8: - Mode.Format = WINED3DFMT_P8_UINT; + mode.format_id = WINED3DFMT_P8_UINT; break; case 15: - Mode.Format = WINED3DFMT_B5G5R5X1_UNORM; + mode.format_id = WINED3DFMT_B5G5R5X1_UNORM; break; case 16: - Mode.Format = WINED3DFMT_B5G6R5_UNORM; + mode.format_id = WINED3DFMT_B5G6R5_UNORM; break; case 24: - Mode.Format = WINED3DFMT_B8G8R8_UNORM; + mode.format_id = WINED3DFMT_B8G8R8_UNORM; break; case 32: - Mode.Format = WINED3DFMT_B8G8R8X8_UNORM; + mode.format_id = WINED3DFMT_B8G8R8X8_UNORM; break; } - Mode.Width = ddraw->orig_width; - Mode.Height = ddraw->orig_height; + mode.width = ddraw->orig_width; + mode.height = ddraw->orig_height; } /* No pixelformat given? Use the current screen format */ @@ -3165,31 +2932,7 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD, desc2.dwFlags |= DDSD_PIXELFORMAT; desc2.u4.ddpfPixelFormat.dwSize=sizeof(DDPIXELFORMAT); - /* Wait: It could be a Z buffer */ - if(desc2.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) - { - switch(desc2.u2.dwMipMapCount) /* Who had this glorious idea? */ - { - case 15: - PixelFormat_WineD3DtoDD(&desc2.u4.ddpfPixelFormat, WINED3DFMT_S1_UINT_D15_UNORM); - break; - case 16: - PixelFormat_WineD3DtoDD(&desc2.u4.ddpfPixelFormat, WINED3DFMT_D16_UNORM); - break; - case 24: - PixelFormat_WineD3DtoDD(&desc2.u4.ddpfPixelFormat, WINED3DFMT_X8D24_UNORM); - break; - case 32: - PixelFormat_WineD3DtoDD(&desc2.u4.ddpfPixelFormat, WINED3DFMT_D32_UNORM); - break; - default: - ERR("Unknown Z buffer bit depth\n"); - } - } - else - { - PixelFormat_WineD3DtoDD(&desc2.u4.ddpfPixelFormat, Mode.Format); - } + PixelFormat_WineD3DtoDD(&desc2.u4.ddpfPixelFormat, mode.format_id); } /* No Width or no Height? Use the original screen size @@ -3202,20 +2945,16 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD, { WARN("Creating a non-Primary surface without Width or Height info, returning DDERR_INVALIDPARAMS\n"); *Surf = NULL; - LeaveCriticalSection(&ddraw_cs); return DDERR_INVALIDPARAMS; } desc2.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT; - desc2.dwWidth = Mode.Width; - desc2.dwHeight = Mode.Height; + desc2.dwWidth = mode.width; + desc2.dwHeight = mode.height; } if (!desc2.dwWidth || !desc2.dwHeight) - { - LeaveCriticalSection(&ddraw_cs); return DDERR_INVALIDPARAMS; - } /* Mipmap count fixes */ if(desc2.ddsCaps.dwCaps & DDSCAPS_MIPMAP) @@ -3226,10 +2965,7 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD, { /* Mipmap count is given, should not be 0 */ if( desc2.u2.dwMipMapCount == 0 ) - { - LeaveCriticalSection(&ddraw_cs); return DDERR_INVALIDPARAMS; - } } else { @@ -3271,17 +3007,40 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD, desc2.ddsCaps.dwCaps2 |= DDSCAPS2_CUBEMAP_POSITIVEX; } + if ((desc2.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) && (ddraw->cooperative_level & DDSCL_EXCLUSIVE)) + { + struct wined3d_swapchain_desc swapchain_desc; + + hr = wined3d_swapchain_get_desc(ddraw->wined3d_swapchain, &swapchain_desc); + if (FAILED(hr)) + { + ERR("Failed to get present parameters.\n"); + return hr; + } + + swapchain_desc.backbuffer_width = mode.width; + swapchain_desc.backbuffer_height = mode.height; + swapchain_desc.backbuffer_format = mode.format_id; + + hr = wined3d_device_reset(ddraw->wined3d_device, + &swapchain_desc, ddraw_reset_enum_callback); + if (FAILED(hr)) + { + ERR("Failed to reset device.\n"); + return hr; + } + } + /* Create the first surface */ - hr = ddraw_create_surface(ddraw, &desc2, &object, 0); + hr = ddraw_create_surface(ddraw, &desc2, &object, 0, version); if (FAILED(hr)) { WARN("ddraw_create_surface failed, hr %#x.\n", hr); - LeaveCriticalSection(&ddraw_cs); return hr; } object->is_complex_root = TRUE; - *Surf = (IDirectDrawSurface7 *)object; + *Surf = object; /* Create Additional surfaces if necessary * This applies to Primary surfaces which have a back buffer count @@ -3301,93 +3060,39 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD, { desc2.ddsCaps.dwCaps2 &= ~DDSCAPS2_CUBEMAP_ALLFACES; desc2.ddsCaps.dwCaps2 |= DDSCAPS2_CUBEMAP_NEGATIVEZ; - hr |= CreateAdditionalSurfaces(ddraw, object, extra_surfaces + 1, desc2, TRUE); + hr |= CreateAdditionalSurfaces(ddraw, object, extra_surfaces + 1, desc2, TRUE, version); desc2.ddsCaps.dwCaps2 &= ~DDSCAPS2_CUBEMAP_NEGATIVEZ; desc2.ddsCaps.dwCaps2 |= DDSCAPS2_CUBEMAP_POSITIVEZ; - hr |= CreateAdditionalSurfaces(ddraw, object, extra_surfaces + 1, desc2, TRUE); + hr |= CreateAdditionalSurfaces(ddraw, object, extra_surfaces + 1, desc2, TRUE, version); desc2.ddsCaps.dwCaps2 &= ~DDSCAPS2_CUBEMAP_POSITIVEZ; desc2.ddsCaps.dwCaps2 |= DDSCAPS2_CUBEMAP_NEGATIVEY; - hr |= CreateAdditionalSurfaces(ddraw, object, extra_surfaces + 1, desc2, TRUE); + hr |= CreateAdditionalSurfaces(ddraw, object, extra_surfaces + 1, desc2, TRUE, version); desc2.ddsCaps.dwCaps2 &= ~DDSCAPS2_CUBEMAP_NEGATIVEY; desc2.ddsCaps.dwCaps2 |= DDSCAPS2_CUBEMAP_POSITIVEY; - hr |= CreateAdditionalSurfaces(ddraw, object, extra_surfaces + 1, desc2, TRUE); + hr |= CreateAdditionalSurfaces(ddraw, object, extra_surfaces + 1, desc2, TRUE, version); desc2.ddsCaps.dwCaps2 &= ~DDSCAPS2_CUBEMAP_POSITIVEY; desc2.ddsCaps.dwCaps2 |= DDSCAPS2_CUBEMAP_NEGATIVEX; - hr |= CreateAdditionalSurfaces(ddraw, object, extra_surfaces + 1, desc2, TRUE); + hr |= CreateAdditionalSurfaces(ddraw, object, extra_surfaces + 1, desc2, TRUE, version); desc2.ddsCaps.dwCaps2 &= ~DDSCAPS2_CUBEMAP_NEGATIVEX; desc2.ddsCaps.dwCaps2 |= DDSCAPS2_CUBEMAP_POSITIVEX; } - hr |= CreateAdditionalSurfaces(ddraw, object, extra_surfaces, desc2, FALSE); + hr |= CreateAdditionalSurfaces(ddraw, object, extra_surfaces, desc2, FALSE, version); if(hr != DD_OK) { /* This destroys and possibly created surfaces too */ - IDirectDrawSurface_Release((IDirectDrawSurface7 *)object); - LeaveCriticalSection(&ddraw_cs); + if (version == 7) + IDirectDrawSurface7_Release(&object->IDirectDrawSurface7_iface); + else if (version == 4) + IDirectDrawSurface4_Release(&object->IDirectDrawSurface4_iface); + else + IDirectDrawSurface_Release(&object->IDirectDrawSurface_iface); + return hr; } - /* If the implementation is OpenGL and there's no d3ddevice, attach a d3ddevice - * But attach the d3ddevice only if the currently created surface was - * a primary surface (2D app in 3D mode) or a 3DDEVICE surface (3D app) - * The only case I can think of where this doesn't apply is when a - * 2D app was configured by the user to run with OpenGL and it didn't create - * the render target as first surface. In this case the render target creation - * will cause the 3D init. - */ - if( (ddraw->ImplType == SURFACE_OPENGL) && !(ddraw->d3d_initialized) && - desc2.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE) ) - { - IDirectDrawSurfaceImpl *target = object, *surface; - struct list *entry; - - /* Search for the primary to use as render target */ - LIST_FOR_EACH(entry, &ddraw->surface_list) - { - surface = LIST_ENTRY(entry, IDirectDrawSurfaceImpl, surface_list_entry); - if((surface->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER)) == - (DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER)) - { - /* found */ - target = surface; - TRACE("Using primary %p as render target\n", target); - break; - } - } - - TRACE("(%p) Attaching a D3DDevice, rendertarget = %p\n", ddraw, target); - hr = ddraw_attach_d3d_device(ddraw, target); - if (hr != D3D_OK) - { - IDirectDrawSurfaceImpl *release_surf; - ERR("ddraw_attach_d3d_device failed, hr %#x\n", hr); - *Surf = NULL; - - /* The before created surface structures are in an incomplete state here. - * WineD3D holds the reference on the IParents, and it released them on the failure - * already. So the regular release method implementation would fail on the attempt - * to destroy either the IParents or the swapchain. So free the surface here. - * The surface structure here is a list, not a tree, because onscreen targets - * cannot be cube textures - */ - while(object) - { - release_surf = object; - object = object->complex_array[0]; - ddraw_surface_destroy(release_surf); - } - LeaveCriticalSection(&ddraw_cs); - return hr; - } - } - else if(!(ddraw->d3d_initialized) && desc2.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) - { - ddraw_create_gdi_swapchain(ddraw, object); - } - - /* Addref the ddraw interface to keep an reference for each surface */ - IDirectDraw7_AddRef(&ddraw->IDirectDraw7_iface); - object->ifaceToRelease = (IUnknown *)&ddraw->IDirectDraw7_iface; + if (desc2.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) + ddraw->primary = object; /* Create a WineD3DTexture if a texture was requested */ if (desc2.ddsCaps.dwCaps & DDSCAPS_TEXTURE) @@ -3397,7 +3102,6 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD, ddraw->tex_root = NULL; } - LeaveCriticalSection(&ddraw_cs); return hr; } @@ -3405,13 +3109,25 @@ static HRESULT WINAPI ddraw7_CreateSurface(IDirectDraw7 *iface, DDSURFACEDESC2 * IDirectDrawSurface7 **surface, IUnknown *outer_unknown) { IDirectDrawImpl *This = impl_from_IDirectDraw7(iface); + IDirectDrawSurfaceImpl *impl; + HRESULT hr; TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n", iface, surface_desc, surface, outer_unknown); + wined3d_mutex_lock(); + + if (!(This->cooperative_level & (DDSCL_NORMAL | DDSCL_EXCLUSIVE))) + { + WARN("Cooperative level not set.\n"); + wined3d_mutex_unlock(); + return DDERR_NOCOOPERATIVELEVELSET; + } + if(surface_desc == NULL || surface_desc->dwSize != sizeof(DDSURFACEDESC2)) { WARN("Application supplied invalid surface descriptor\n"); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } @@ -3424,10 +3140,23 @@ static HRESULT WINAPI ddraw7_CreateSurface(IDirectDraw7 *iface, DDSURFACEDESC2 * } WARN("Application tried to create an explicit front or back buffer\n"); + wined3d_mutex_unlock(); return DDERR_INVALIDCAPS; } - return CreateSurface(This, surface_desc, surface, outer_unknown); + hr = CreateSurface(This, surface_desc, &impl, outer_unknown, 7); + wined3d_mutex_unlock(); + if (FAILED(hr)) + { + *surface = NULL; + return hr; + } + + *surface = &impl->IDirectDrawSurface7_iface; + IDirectDraw7_AddRef(iface); + impl->ifaceToRelease = (IUnknown *)iface; + + return hr; } static HRESULT WINAPI ddraw4_CreateSurface(IDirectDraw4 *iface, @@ -3440,9 +3169,19 @@ static HRESULT WINAPI ddraw4_CreateSurface(IDirectDraw4 *iface, TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n", iface, surface_desc, surface, outer_unknown); + wined3d_mutex_lock(); + + if (!(This->cooperative_level & (DDSCL_NORMAL | DDSCL_EXCLUSIVE))) + { + WARN("Cooperative level not set.\n"); + wined3d_mutex_unlock(); + return DDERR_NOCOOPERATIVELEVELSET; + } + if(surface_desc == NULL || surface_desc->dwSize != sizeof(DDSURFACEDESC2)) { WARN("Application supplied invalid surface descriptor\n"); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } @@ -3455,63 +3194,20 @@ static HRESULT WINAPI ddraw4_CreateSurface(IDirectDraw4 *iface, } WARN("Application tried to create an explicit front or back buffer\n"); + wined3d_mutex_unlock(); return DDERR_INVALIDCAPS; } - hr = CreateSurface(This, surface_desc, (IDirectDrawSurface7 **)surface, outer_unknown); - impl = (IDirectDrawSurfaceImpl *)*surface; - if (SUCCEEDED(hr) && impl) - { - ddraw_set_surface_version(impl, 4); - IDirectDraw7_Release(&This->IDirectDraw7_iface); - IDirectDraw4_AddRef(iface); - impl->ifaceToRelease = (IUnknown *)iface; - } - - return hr; -} - -static HRESULT WINAPI ddraw3_CreateSurface(IDirectDraw3 *iface, DDSURFACEDESC *surface_desc, - IDirectDrawSurface **surface, IUnknown *outer_unknown) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - IDirectDrawSurface7 *surface7; - IDirectDrawSurfaceImpl *impl; - HRESULT hr; - - TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n", - iface, surface_desc, surface, outer_unknown); - - if(surface_desc == NULL || surface_desc->dwSize != sizeof(DDSURFACEDESC)) - { - WARN("Application supplied invalid surface descriptor\n"); - return DDERR_INVALIDPARAMS; - } - - if(surface_desc->ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_BACKBUFFER)) - { - if (TRACE_ON(ddraw)) - { - TRACE(" (%p) Requesting surface desc :\n", iface); - DDRAW_dump_surface_desc((LPDDSURFACEDESC2)surface_desc); - } - - WARN("Application tried to create an explicit front or back buffer\n"); - return DDERR_INVALIDCAPS; - } - - hr = CreateSurface(This, (DDSURFACEDESC2 *)surface_desc, &surface7, outer_unknown); + hr = CreateSurface(This, surface_desc, &impl, outer_unknown, 4); + wined3d_mutex_unlock(); if (FAILED(hr)) { *surface = NULL; return hr; } - impl = (IDirectDrawSurfaceImpl *)surface7; - *surface = (IDirectDrawSurface *)&impl->IDirectDrawSurface3_vtbl; - ddraw_set_surface_version(impl, 3); - IDirectDraw7_Release(&This->IDirectDraw7_iface); - IDirectDraw3_AddRef(iface); + *surface = &impl->IDirectDrawSurface4_iface; + IDirectDraw4_AddRef(iface); impl->ifaceToRelease = (IUnknown *)iface; return hr; @@ -3521,19 +3217,30 @@ static HRESULT WINAPI ddraw2_CreateSurface(IDirectDraw2 *iface, DDSURFACEDESC *surface_desc, IDirectDrawSurface **surface, IUnknown *outer_unknown) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); - IDirectDrawSurface7 *surface7; IDirectDrawSurfaceImpl *impl; HRESULT hr; + DDSURFACEDESC2 surface_desc2; TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n", iface, surface_desc, surface, outer_unknown); + wined3d_mutex_lock(); + + if (!(This->cooperative_level & (DDSCL_NORMAL | DDSCL_EXCLUSIVE))) + { + WARN("Cooperative level not set.\n"); + wined3d_mutex_unlock(); + return DDERR_NOCOOPERATIVELEVELSET; + } + if(surface_desc == NULL || surface_desc->dwSize != sizeof(DDSURFACEDESC)) { WARN("Application supplied invalid surface descriptor\n"); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } + DDSD_to_DDSD2(surface_desc, &surface_desc2); if(surface_desc->ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_BACKBUFFER)) { if (TRACE_ON(ddraw)) @@ -3543,20 +3250,19 @@ static HRESULT WINAPI ddraw2_CreateSurface(IDirectDraw2 *iface, } WARN("Application tried to create an explicit front or back buffer\n"); + wined3d_mutex_unlock(); return DDERR_INVALIDCAPS; } - hr = CreateSurface(This, (DDSURFACEDESC2 *)surface_desc, &surface7, outer_unknown); + hr = CreateSurface(This, &surface_desc2, &impl, outer_unknown, 2); + wined3d_mutex_unlock(); if (FAILED(hr)) { *surface = NULL; return hr; } - impl = (IDirectDrawSurfaceImpl *)surface7; - *surface = (IDirectDrawSurface *)&impl->IDirectDrawSurface3_vtbl; - ddraw_set_surface_version(impl, 2); - IDirectDraw7_Release(&This->IDirectDraw7_iface); + *surface = &impl->IDirectDrawSurface_iface; impl->ifaceToRelease = NULL; return hr; @@ -3566,33 +3272,42 @@ static HRESULT WINAPI ddraw1_CreateSurface(IDirectDraw *iface, DDSURFACEDESC *surface_desc, IDirectDrawSurface **surface, IUnknown *outer_unknown) { IDirectDrawImpl *This = impl_from_IDirectDraw(iface); - IDirectDrawSurface7 *surface7; IDirectDrawSurfaceImpl *impl; HRESULT hr; + DDSURFACEDESC2 surface_desc2; TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n", iface, surface_desc, surface, outer_unknown); + wined3d_mutex_lock(); + + if (!(This->cooperative_level & (DDSCL_NORMAL | DDSCL_EXCLUSIVE))) + { + WARN("Cooperative level not set.\n"); + wined3d_mutex_unlock(); + return DDERR_NOCOOPERATIVELEVELSET; + } + if(surface_desc == NULL || surface_desc->dwSize != sizeof(DDSURFACEDESC)) { WARN("Application supplied invalid surface descriptor\n"); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } /* Remove front buffer flag, this causes failure in v7, and its added to normal * primaries anyway. */ surface_desc->ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER; - hr = CreateSurface(This, (DDSURFACEDESC2 *)surface_desc, &surface7, outer_unknown); + DDSD_to_DDSD2(surface_desc, &surface_desc2); + hr = CreateSurface(This, &surface_desc2, &impl, outer_unknown, 1); + wined3d_mutex_unlock(); if (FAILED(hr)) { *surface = NULL; return hr; } - impl = (IDirectDrawSurfaceImpl *)surface7; - *surface = (IDirectDrawSurface *)&impl->IDirectDrawSurface3_vtbl; - ddraw_set_surface_version(impl, 1); - IDirectDraw7_Release(&This->IDirectDraw7_iface); + *surface = &impl->IDirectDrawSurface_iface; impl->ifaceToRelease = NULL; return hr; @@ -3710,18 +3425,41 @@ static BOOL ddraw_match_surface_desc(const DDSURFACEDESC2 *requested, const DDSU #undef DDENUMSURFACES_SEARCHTYPE #undef DDENUMSURFACES_MATCHTYPE +struct surfacescallback2_context +{ + LPDDENUMSURFACESCALLBACK2 func; + void *context; +}; + struct surfacescallback_context { LPDDENUMSURFACESCALLBACK func; void *context; }; +static HRESULT CALLBACK EnumSurfacesCallback2Thunk(IDirectDrawSurface7 *surface, + DDSURFACEDESC2 *surface_desc, void *context) +{ + IDirectDrawSurfaceImpl *surface_impl = impl_from_IDirectDrawSurface7(surface); + struct surfacescallback2_context *cbcontext = context; + + IDirectDrawSurface4_AddRef(&surface_impl->IDirectDrawSurface4_iface); + IDirectDrawSurface7_Release(surface); + + return cbcontext->func(&surface_impl->IDirectDrawSurface4_iface, + surface_desc, cbcontext->context); +} + static HRESULT CALLBACK EnumSurfacesCallbackThunk(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *surface_desc, void *context) { + IDirectDrawSurfaceImpl *surface_impl = impl_from_IDirectDrawSurface7(surface); struct surfacescallback_context *cbcontext = context; - return cbcontext->func((IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)surface)->IDirectDrawSurface3_vtbl, + IDirectDrawSurface_AddRef(&surface_impl->IDirectDrawSurface_iface); + IDirectDrawSurface7_Release(surface); + + return cbcontext->func(&surface_impl->IDirectDrawSurface_iface, (DDSURFACEDESC *)surface_desc, cbcontext->context); } @@ -3765,30 +3503,37 @@ static HRESULT WINAPI ddraw7_EnumSurfaces(IDirectDraw7 *iface, DWORD Flags, all = Flags & DDENUMSURFACES_ALL; nomatch = Flags & DDENUMSURFACES_NOMATCH; - EnterCriticalSection(&ddraw_cs); - - if(!Callback) - { - LeaveCriticalSection(&ddraw_cs); + if (!Callback) return DDERR_INVALIDPARAMS; - } + + wined3d_mutex_lock(); /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */ LIST_FOR_EACH_SAFE(entry, entry2, &This->surface_list) { surf = LIST_ENTRY(entry, IDirectDrawSurfaceImpl, surface_list_entry); + + if (!surf->iface_count) + { + WARN("Not enumerating surface %p because it doesn't have any references.\n", surf); + continue; + } + if (all || (nomatch != ddraw_match_surface_desc(DDSD, &surf->surface_desc))) { + TRACE("Enumerating surface %p.\n", surf); desc = surf->surface_desc; - IDirectDrawSurface7_AddRef((IDirectDrawSurface7 *)surf); - if (Callback((IDirectDrawSurface7 *)surf, &desc, Context) != DDENUMRET_OK) + IDirectDrawSurface7_AddRef(&surf->IDirectDrawSurface7_iface); + if (Callback(&surf->IDirectDrawSurface7_iface, &desc, Context) != DDENUMRET_OK) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DD_OK; } } } - LeaveCriticalSection(&ddraw_cs); + + wined3d_mutex_unlock(); + return DD_OK; } @@ -3796,19 +3541,7 @@ static HRESULT WINAPI ddraw4_EnumSurfaces(IDirectDraw4 *iface, DWORD flags, DDSURFACEDESC2 *surface_desc, void *context, LPDDENUMSURFACESCALLBACK2 callback) { IDirectDrawImpl *This = impl_from_IDirectDraw4(iface); - - TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n", - iface, flags, surface_desc, context, callback); - - return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, surface_desc, context, - (LPDDENUMSURFACESCALLBACK7)callback); -} - -static HRESULT WINAPI ddraw3_EnumSurfaces(IDirectDraw3 *iface, DWORD flags, - DDSURFACEDESC *surface_desc, void *context, LPDDENUMSURFACESCALLBACK callback) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - struct surfacescallback_context cbcontext; + struct surfacescallback2_context cbcontext; TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n", iface, flags, surface_desc, context, callback); @@ -3816,8 +3549,8 @@ static HRESULT WINAPI ddraw3_EnumSurfaces(IDirectDraw3 *iface, DWORD flags, cbcontext.func = callback; cbcontext.context = context; - return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, (DDSURFACEDESC2 *)surface_desc, - &cbcontext, EnumSurfacesCallbackThunk); + return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, surface_desc, + &cbcontext, EnumSurfacesCallback2Thunk); } static HRESULT WINAPI ddraw2_EnumSurfaces(IDirectDraw2 *iface, DWORD flags, @@ -3825,6 +3558,7 @@ static HRESULT WINAPI ddraw2_EnumSurfaces(IDirectDraw2 *iface, DWORD flags, { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); struct surfacescallback_context cbcontext; + DDSURFACEDESC2 surface_desc2; TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n", iface, flags, surface_desc, context, callback); @@ -3832,8 +3566,9 @@ static HRESULT WINAPI ddraw2_EnumSurfaces(IDirectDraw2 *iface, DWORD flags, cbcontext.func = callback; cbcontext.context = context; - return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, (DDSURFACEDESC2 *)surface_desc, - &cbcontext, EnumSurfacesCallbackThunk); + if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2); + return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, + surface_desc ? &surface_desc2 : NULL, &cbcontext, EnumSurfacesCallbackThunk); } static HRESULT WINAPI ddraw1_EnumSurfaces(IDirectDraw *iface, DWORD flags, @@ -3841,6 +3576,7 @@ static HRESULT WINAPI ddraw1_EnumSurfaces(IDirectDraw *iface, DWORD flags, { IDirectDrawImpl *This = impl_from_IDirectDraw(iface); struct surfacescallback_context cbcontext; + DDSURFACEDESC2 surface_desc2; TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n", iface, flags, surface_desc, context, callback); @@ -3848,8 +3584,9 @@ static HRESULT WINAPI ddraw1_EnumSurfaces(IDirectDraw *iface, DWORD flags, cbcontext.func = callback; cbcontext.context = context; - return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, (DDSURFACEDESC2 *)surface_desc, - &cbcontext, EnumSurfacesCallbackThunk); + if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2); + return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, + surface_desc ? &surface_desc2 : NULL, &cbcontext, EnumSurfacesCallbackThunk); } /***************************************************************************** @@ -3867,29 +3604,23 @@ static HRESULT WINAPI ddraw1_EnumSurfaces(IDirectDraw *iface, DWORD flags, * E_OUTOFMEMORY if allocating the object failed * *****************************************************************************/ -HRESULT WINAPI -DirectDrawCreateClipper(DWORD Flags, - LPDIRECTDRAWCLIPPER *Clipper, - IUnknown *UnkOuter) +HRESULT WINAPI DirectDrawCreateClipper(DWORD flags, IDirectDrawClipper **clipper, IUnknown *outer_unknown) { - IDirectDrawClipperImpl* object; + struct ddraw_clipper *object; HRESULT hr; TRACE("flags %#x, clipper %p, outer_unknown %p.\n", - Flags, Clipper, UnkOuter); + flags, clipper, outer_unknown); - EnterCriticalSection(&ddraw_cs); - if (UnkOuter != NULL) - { - LeaveCriticalSection(&ddraw_cs); + if (outer_unknown) return CLASS_E_NOAGGREGATION; - } - object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, - sizeof(IDirectDrawClipperImpl)); - if (object == NULL) + wined3d_mutex_lock(); + + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + if (!object) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return E_OUTOFMEMORY; } @@ -3898,13 +3629,14 @@ DirectDrawCreateClipper(DWORD Flags, { WARN("Failed to initialize clipper, hr %#x.\n", hr); HeapFree(GetProcessHeap(), 0, object); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } TRACE("Created clipper %p.\n", object); - *Clipper = (IDirectDrawClipper *) object; - LeaveCriticalSection(&ddraw_cs); + *clipper = &object->IDirectDrawClipper_iface; + wined3d_mutex_unlock(); + return DD_OK; } @@ -3934,17 +3666,6 @@ static HRESULT WINAPI ddraw4_CreateClipper(IDirectDraw4 *iface, DWORD flags, return ddraw7_CreateClipper(&This->IDirectDraw7_iface, flags, clipper, outer_unknown); } -static HRESULT WINAPI ddraw3_CreateClipper(IDirectDraw3 *iface, DWORD flags, - IDirectDrawClipper **clipper, IUnknown *outer_unknown) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - - TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n", - iface, flags, clipper, outer_unknown); - - return ddraw7_CreateClipper(&This->IDirectDraw7_iface, flags, clipper, outer_unknown); -} - static HRESULT WINAPI ddraw2_CreateClipper(IDirectDraw2 *iface, DWORD flags, IDirectDrawClipper **clipper, IUnknown *outer_unknown) { @@ -3994,19 +3715,16 @@ static HRESULT WINAPI ddraw7_CreatePalette(IDirectDraw7 *iface, DWORD Flags, TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n", iface, Flags, ColorTable, Palette, pUnkOuter); - EnterCriticalSection(&ddraw_cs); - if(pUnkOuter != NULL) - { - WARN("pUnkOuter is %p, returning CLASS_E_NOAGGREGATION\n", pUnkOuter); - LeaveCriticalSection(&ddraw_cs); + if (pUnkOuter) return CLASS_E_NOAGGREGATION; - } + + wined3d_mutex_lock(); /* The refcount test shows that a cooplevel is required for this */ if(!This->cooperative_level) { WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_NOCOOPERATIVELEVELSET; } @@ -4014,7 +3732,7 @@ static HRESULT WINAPI ddraw7_CreatePalette(IDirectDraw7 *iface, DWORD Flags, if(!object) { ERR("Out of memory when allocating memory for a palette implementation\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return E_OUTOFMEMORY; } @@ -4023,13 +3741,14 @@ static HRESULT WINAPI ddraw7_CreatePalette(IDirectDraw7 *iface, DWORD Flags, { WARN("Failed to initialize palette, hr %#x.\n", hr); HeapFree(GetProcessHeap(), 0, object); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } TRACE("Created palette %p.\n", object); - *Palette = (IDirectDrawPalette *)object; - LeaveCriticalSection(&ddraw_cs); + *Palette = &object->IDirectDrawPalette_iface; + wined3d_mutex_unlock(); + return DD_OK; } @@ -4045,7 +3764,7 @@ static HRESULT WINAPI ddraw4_CreatePalette(IDirectDraw4 *iface, DWORD flags, PAL hr = ddraw7_CreatePalette(&This->IDirectDraw7_iface, flags, entries, palette, outer_unknown); if (SUCCEEDED(hr) && *palette) { - IDirectDrawPaletteImpl *impl = (IDirectDrawPaletteImpl *)*palette; + IDirectDrawPaletteImpl *impl = impl_from_IDirectDrawPalette(*palette); IDirectDraw7_Release(&This->IDirectDraw7_iface); IDirectDraw4_AddRef(iface); impl->ifaceToRelease = (IUnknown *)iface; @@ -4053,27 +3772,6 @@ static HRESULT WINAPI ddraw4_CreatePalette(IDirectDraw4 *iface, DWORD flags, PAL return hr; } -static HRESULT WINAPI ddraw3_CreatePalette(IDirectDraw3 *iface, DWORD flags, - PALETTEENTRY *entries, IDirectDrawPalette **palette, IUnknown *outer_unknown) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - HRESULT hr; - - TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n", - iface, flags, entries, palette, outer_unknown); - - hr = ddraw7_CreatePalette(&This->IDirectDraw7_iface, flags, entries, palette, outer_unknown); - if (SUCCEEDED(hr) && *palette) - { - IDirectDrawPaletteImpl *impl = (IDirectDrawPaletteImpl *)*palette; - IDirectDraw7_Release(&This->IDirectDraw7_iface); - IDirectDraw4_AddRef(iface); - impl->ifaceToRelease = (IUnknown *)iface; - } - - return hr; -} - static HRESULT WINAPI ddraw2_CreatePalette(IDirectDraw2 *iface, DWORD flags, PALETTEENTRY *entries, IDirectDrawPalette **palette, IUnknown *outer_unknown) { @@ -4086,7 +3784,7 @@ static HRESULT WINAPI ddraw2_CreatePalette(IDirectDraw2 *iface, DWORD flags, hr = ddraw7_CreatePalette(&This->IDirectDraw7_iface, flags, entries, palette, outer_unknown); if (SUCCEEDED(hr) && *palette) { - IDirectDrawPaletteImpl *impl = (IDirectDrawPaletteImpl *)*palette; + IDirectDrawPaletteImpl *impl = impl_from_IDirectDrawPalette(*palette); IDirectDraw7_Release(&This->IDirectDraw7_iface); impl->ifaceToRelease = NULL; } @@ -4106,7 +3804,7 @@ static HRESULT WINAPI ddraw1_CreatePalette(IDirectDraw *iface, DWORD flags, hr = ddraw7_CreatePalette(&This->IDirectDraw7_iface, flags, entries, palette, outer_unknown); if (SUCCEEDED(hr) && *palette) { - IDirectDrawPaletteImpl *impl = (IDirectDrawPaletteImpl *)*palette; + IDirectDrawPaletteImpl *impl = impl_from_IDirectDrawPalette(*palette); IDirectDraw7_Release(&This->IDirectDraw7_iface); impl->ifaceToRelease = NULL; } @@ -4134,7 +3832,7 @@ static HRESULT WINAPI ddraw1_CreatePalette(IDirectDraw *iface, DWORD flags, static HRESULT WINAPI ddraw7_DuplicateSurface(IDirectDraw7 *iface, IDirectDrawSurface7 *Src, IDirectDrawSurface7 **Dest) { - IDirectDrawSurfaceImpl *Surf = (IDirectDrawSurfaceImpl *)Src; + IDirectDrawSurfaceImpl *Surf = unsafe_impl_from_IDirectDrawSurface7(Src); FIXME("iface %p, src %p, dst %p partial stub!\n", iface, Src, Dest); @@ -4149,26 +3847,24 @@ static HRESULT WINAPI ddraw4_DuplicateSurface(IDirectDraw4 *iface, IDirectDrawSu IDirectDrawSurface4 **dst) { IDirectDrawImpl *This = impl_from_IDirectDraw4(iface); - - TRACE("iface %p, src %p, dst %p.\n", iface, src, dst); - - return ddraw7_DuplicateSurface(&This->IDirectDraw7_iface, (IDirectDrawSurface7 *)src, - (IDirectDrawSurface7 **)dst); -} - -static HRESULT WINAPI ddraw3_DuplicateSurface(IDirectDraw3 *iface, IDirectDrawSurface *src, - IDirectDrawSurface **dst) -{ - IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - IDirectDrawSurface7 *src7, *dst7; + IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface4(src); + IDirectDrawSurface7 *dst7; + IDirectDrawSurfaceImpl *dst_impl; HRESULT hr; TRACE("iface %p, src %p, dst %p.\n", iface, src, dst); - src7 = (IDirectDrawSurface7 *)surface_from_surface3((IDirectDrawSurface3 *)src); - hr = ddraw7_DuplicateSurface(&This->IDirectDraw7_iface, src7, &dst7); + hr = ddraw7_DuplicateSurface(&This->IDirectDraw7_iface, + src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, &dst7); if (FAILED(hr)) + { + *dst = NULL; return hr; - *dst = (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)dst7)->IDirectDrawSurface3_vtbl; + } + dst_impl = impl_from_IDirectDrawSurface7(dst7); + *dst = &dst_impl->IDirectDrawSurface4_iface; + IDirectDrawSurface4_AddRef(*dst); + IDirectDrawSurface7_Release(dst7); + return hr; } @@ -4176,15 +3872,21 @@ static HRESULT WINAPI ddraw2_DuplicateSurface(IDirectDraw2 *iface, IDirectDrawSurface *src, IDirectDrawSurface **dst) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); - IDirectDrawSurface7 *src7, *dst7; + IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface(src); + IDirectDrawSurface7 *dst7; + IDirectDrawSurfaceImpl *dst_impl; HRESULT hr; TRACE("iface %p, src %p, dst %p.\n", iface, src, dst); - src7 = (IDirectDrawSurface7 *)surface_from_surface3((IDirectDrawSurface3 *)src); - hr = ddraw7_DuplicateSurface(&This->IDirectDraw7_iface, src7, &dst7); + hr = ddraw7_DuplicateSurface(&This->IDirectDraw7_iface, + src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, &dst7); if (FAILED(hr)) return hr; - *dst = (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)dst7)->IDirectDrawSurface3_vtbl; + dst_impl = impl_from_IDirectDrawSurface7(dst7); + *dst = &dst_impl->IDirectDrawSurface_iface; + IDirectDrawSurface_AddRef(*dst); + IDirectDrawSurface7_Release(dst7); + return hr; } @@ -4192,15 +3894,21 @@ static HRESULT WINAPI ddraw1_DuplicateSurface(IDirectDraw *iface, IDirectDrawSur IDirectDrawSurface **dst) { IDirectDrawImpl *This = impl_from_IDirectDraw(iface); - IDirectDrawSurface7 *src7, *dst7; + IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface(src); + IDirectDrawSurface7 *dst7; + IDirectDrawSurfaceImpl *dst_impl; HRESULT hr; TRACE("iface %p, src %p, dst %p.\n", iface, src, dst); - src7 = (IDirectDrawSurface7 *)surface_from_surface3((IDirectDrawSurface3 *)src); - hr = ddraw7_DuplicateSurface(&This->IDirectDraw7_iface, src7, &dst7); + hr = ddraw7_DuplicateSurface(&This->IDirectDraw7_iface, + src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, &dst7); if (FAILED(hr)) return hr; - *dst = (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)dst7)->IDirectDrawSurface3_vtbl; + dst_impl = impl_from_IDirectDrawSurface7(dst7); + *dst = &dst_impl->IDirectDrawSurface_iface; + IDirectDrawSurface_AddRef(*dst); + IDirectDrawSurface7_Release(dst7); + return hr; } @@ -4220,39 +3928,43 @@ static HRESULT WINAPI ddraw1_DuplicateSurface(IDirectDraw *iface, IDirectDrawSur *****************************************************************************/ static HRESULT WINAPI d3d7_EnumDevices(IDirect3D7 *iface, LPD3DENUMDEVICESCALLBACK7 callback, void *context) { - char interface_name_tnl[] = "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D"; - char device_name_tnl[] = "Wine D3D7 T&L HAL"; - char interface_name_hal[] = "WINE Direct3D7 Hardware acceleration using WineD3D"; - char device_name_hal[] = "Wine D3D7 HAL"; - char interface_name_rgb[] = "WINE Direct3D7 RGB Software Emulation using WineD3D"; - char device_name_rgb[] = "Wine D3D7 RGB"; - IDirectDrawImpl *This = impl_from_IDirect3D7(iface); D3DDEVICEDESC7 device_desc7; D3DDEVICEDESC device_desc1; HRESULT hr; + size_t i; TRACE("iface %p, callback %p, context %p.\n", iface, callback, context); - EnterCriticalSection(&ddraw_cs); + if (!callback) + return DDERR_INVALIDPARAMS; - hr = IDirect3DImpl_GetCaps(This->wineD3D, &device_desc1, &device_desc7); + wined3d_mutex_lock(); + + hr = IDirect3DImpl_GetCaps(This->wined3d, &device_desc1, &device_desc7); if (hr != D3D_OK) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } - callback(interface_name_tnl, device_name_tnl, &device_desc7, context); - device_desc7.deviceGUID = IID_IDirect3DHALDevice; - callback(interface_name_hal, device_name_hal, &device_desc7, context); + for (i = 0; i < sizeof(device_list7)/sizeof(device_list7[0]); i++) + { + HRESULT ret; - device_desc7.deviceGUID = IID_IDirect3DRGBDevice; - callback(interface_name_rgb, device_name_rgb, &device_desc7, context); + device_desc7.deviceGUID = *device_list7[i].device_guid; + ret = callback(device_list7[i].interface_name, device_list7[i].device_name, &device_desc7, context); + if (ret != DDENUMRET_OK) + { + TRACE("Application cancelled the enumeration.\n"); + wined3d_mutex_unlock(); + return D3D_OK; + } + } TRACE("End of enumeration.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } @@ -4291,12 +4003,15 @@ static HRESULT WINAPI d3d3_EnumDevices(IDirect3D3 *iface, LPD3DENUMDEVICESCALLBA TRACE("iface %p, callback %p, context %p.\n", iface, callback, context); - EnterCriticalSection(&ddraw_cs); + if (!callback) + return DDERR_INVALIDPARAMS; - hr = IDirect3DImpl_GetCaps(This->wineD3D, &device_desc1, &device_desc7); + wined3d_mutex_lock(); + + hr = IDirect3DImpl_GetCaps(This->wined3d, &device_desc1, &device_desc7); if (hr != D3D_OK) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } @@ -4331,12 +4046,15 @@ static HRESULT WINAPI d3d3_EnumDevices(IDirect3D3 *iface, LPD3DENUMDEVICESCALLBA | D3DPTEXTURECAPS_NONPOW2CONDITIONAL | D3DPTEXTURECAPS_PERSPECTIVE); hal_desc.dpcTriCaps.dwTextureCaps &= ~(D3DPTEXTURECAPS_POW2 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL | D3DPTEXTURECAPS_PERSPECTIVE); + /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */ + hal_desc.dcmColorModel = 0; + hr = callback((GUID *)&IID_IDirect3DRGBDevice, reference_description, device_name, &hal_desc, &hel_desc, context); if (hr != D3DENUMRET_OK) { TRACE("Application cancelled the enumeration.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } } @@ -4346,23 +4064,28 @@ static HRESULT WINAPI d3d3_EnumDevices(IDirect3D3 *iface, LPD3DENUMDEVICESCALLBA TRACE("Enumerating HAL Direct3D device.\n"); hal_desc = device_desc1; hel_desc = device_desc1; + /* The hal device does not have the pow2 flag set in hel, but in hal. */ hel_desc.dpcLineCaps.dwTextureCaps &= ~(D3DPTEXTURECAPS_POW2 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL | D3DPTEXTURECAPS_PERSPECTIVE); hel_desc.dpcTriCaps.dwTextureCaps &= ~(D3DPTEXTURECAPS_POW2 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL | D3DPTEXTURECAPS_PERSPECTIVE); + /* HAL devices have a HEL dcmColorModel of 0 */ + hel_desc.dcmColorModel = 0; + hr = callback((GUID *)&IID_IDirect3DHALDevice, wined3d_description, device_name, &hal_desc, &hel_desc, context); if (hr != D3DENUMRET_OK) { TRACE("Application cancelled the enumeration.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } TRACE("End of enumeration.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } @@ -4425,7 +4148,7 @@ static HRESULT WINAPI d3d3_CreateLight(IDirect3D3 *iface, IDirect3DLight **light d3d_light_init(object, This); TRACE("Created light %p.\n", object); - *light = (IDirect3DLight *)object; + *light = &object->IDirect3DLight_iface; return D3D_OK; } @@ -4478,52 +4201,59 @@ static HRESULT WINAPI d3d3_CreateMaterial(IDirect3D3 *iface, IDirect3DMaterial3 if (outer_unknown) return CLASS_E_NOAGGREGATION; - object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + object = d3d_material_create(This); if (!object) { ERR("Failed to allocate material memory.\n"); return DDERR_OUTOFMEMORY; } - d3d_material_init(object, This); - TRACE("Created material %p.\n", object); - *material = (IDirect3DMaterial3 *)object; + *material = &object->IDirect3DMaterial3_iface; return D3D_OK; } -static HRESULT WINAPI d3d2_CreateMaterial(IDirect3D2 *iface, IDirect3DMaterial2 **material, IUnknown *outer_unknown) +static HRESULT WINAPI d3d2_CreateMaterial(IDirect3D2 *iface, IDirect3DMaterial2 **material, + IUnknown *outer_unknown) { IDirectDrawImpl *This = impl_from_IDirect3D2(iface); - IDirect3DMaterial3 *material3; - HRESULT hr; + IDirect3DMaterialImpl *object; TRACE("iface %p, material %p, outer_unknown %p.\n", iface, material, outer_unknown); - hr = d3d3_CreateMaterial(&This->IDirect3D3_iface, &material3, outer_unknown); - *material = material3 ? (IDirect3DMaterial2 *)&((IDirect3DMaterialImpl *)material3)->IDirect3DMaterial2_vtbl : NULL; + object = d3d_material_create(This); + if (!object) + { + ERR("Failed to allocate material memory.\n"); + return DDERR_OUTOFMEMORY; + } - TRACE("Returning material %p.\n", *material); + TRACE("Created material %p.\n", object); + *material = &object->IDirect3DMaterial2_iface; - return hr; + return D3D_OK; } -static HRESULT WINAPI d3d1_CreateMaterial(IDirect3D *iface, IDirect3DMaterial **material, IUnknown *outer_unknown) +static HRESULT WINAPI d3d1_CreateMaterial(IDirect3D *iface, IDirect3DMaterial **material, + IUnknown *outer_unknown) { - IDirect3DMaterial3 *material3; - HRESULT hr; - IDirectDrawImpl *This = impl_from_IDirect3D(iface); + IDirect3DMaterialImpl *object; TRACE("iface %p, material %p, outer_unknown %p.\n", iface, material, outer_unknown); - hr = d3d3_CreateMaterial(&This->IDirect3D3_iface, &material3, outer_unknown); - *material = material3 ? (IDirect3DMaterial *)&((IDirect3DMaterialImpl *)material3)->IDirect3DMaterial_vtbl : NULL; + object = d3d_material_create(This); + if (!object) + { + ERR("Failed to allocate material memory.\n"); + return DDERR_OUTOFMEMORY; + } - TRACE("Returning material %p.\n", *material); + TRACE("Created material %p.\n", object); + *material = &object->IDirect3DMaterial_iface; - return hr; + return D3D_OK; } /***************************************************************************** @@ -4566,7 +4296,7 @@ static HRESULT WINAPI d3d3_CreateViewport(IDirect3D3 *iface, IDirect3DViewport3 d3d_viewport_init(object, This); TRACE("Created viewport %p.\n", object); - *viewport = (IDirect3DViewport3 *)object; + *viewport = &object->IDirect3DViewport3_iface; return D3D_OK; } @@ -4642,7 +4372,7 @@ static HRESULT WINAPI d3d3_FindDevice(IDirect3D3 *iface, D3DFINDDEVICESEARCH *fd } /* Get the caps */ - hr = IDirect3DImpl_GetCaps(This->wineD3D, &desc1, &desc7); + hr = IDirect3DImpl_GetCaps(This->wined3d, &desc1, &desc7); if (hr != D3D_OK) return hr; /* Now return our own GUID */ @@ -4697,32 +4427,32 @@ static HRESULT WINAPI d3d1_FindDevice(IDirect3D *iface, D3DFINDDEVICESEARCH *fds static HRESULT WINAPI d3d7_CreateDevice(IDirect3D7 *iface, REFCLSID riid, IDirectDrawSurface7 *surface, IDirect3DDevice7 **device) { - IDirectDrawSurfaceImpl *target = (IDirectDrawSurfaceImpl *)surface; + IDirectDrawSurfaceImpl *target = unsafe_impl_from_IDirectDrawSurface7(surface); IDirectDrawImpl *This = impl_from_IDirect3D7(iface); IDirect3DDeviceImpl *object; HRESULT hr; TRACE("iface %p, riid %s, surface %p, device %p.\n", iface, debugstr_guid(riid), surface, device); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); *device = NULL; /* Fail device creation if non-opengl surfaces are used. */ - if (This->ImplType != SURFACE_OPENGL) + if (DefaultSurfaceType != SURFACE_OPENGL) { ERR("The application wants to create a Direct3D device, but non-opengl surfaces are set in the registry.\n"); ERR("Please set the surface implementation to opengl or autodetection to allow 3D rendering.\n"); /* We only hit this path if a default surface is set in the registry. Incorrect autodetection * is caught in CreateSurface or QueryInterface. */ - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_NO3D; } if (This->d3ddevice) { FIXME("Only one Direct3D device per DirectDraw object supported.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } @@ -4730,7 +4460,7 @@ static HRESULT WINAPI d3d7_CreateDevice(IDirect3D7 *iface, REFCLSID riid, if (!object) { ERR("Failed to allocate device memory.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_OUTOFMEMORY; } @@ -4739,14 +4469,15 @@ static HRESULT WINAPI d3d7_CreateDevice(IDirect3D7 *iface, REFCLSID riid, { WARN("Failed to initialize device, hr %#x.\n", hr); HeapFree(GetProcessHeap(), 0, object); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } TRACE("Created device %p.\n", object); - *device = (IDirect3DDevice7 *)object; + *device = &object->IDirect3DDevice7_iface; + + wined3d_mutex_unlock(); - LeaveCriticalSection(&ddraw_cs); return D3D_OK; } @@ -4754,6 +4485,9 @@ static HRESULT WINAPI d3d3_CreateDevice(IDirect3D3 *iface, REFCLSID riid, IDirectDrawSurface4 *surface, IDirect3DDevice3 **device, IUnknown *outer_unknown) { IDirectDrawImpl *This = impl_from_IDirect3D3(iface); + IDirectDrawSurfaceImpl *surface_impl = unsafe_impl_from_IDirectDrawSurface4(surface); + IDirect3DDevice7 *device7; + IDirect3DDeviceImpl *device_impl; HRESULT hr; TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n", @@ -4761,9 +4495,13 @@ static HRESULT WINAPI d3d3_CreateDevice(IDirect3D3 *iface, REFCLSID riid, if (outer_unknown) return CLASS_E_NOAGGREGATION; - hr = d3d7_CreateDevice(&This->IDirect3D7_iface, riid, (IDirectDrawSurface7 *)surface, - (IDirect3DDevice7 **)device); - if (*device) *device = (IDirect3DDevice3 *)&((IDirect3DDeviceImpl *)*device)->IDirect3DDevice3_vtbl; + hr = d3d7_CreateDevice(&This->IDirect3D7_iface, riid, + surface_impl ? &surface_impl->IDirectDrawSurface7_iface : NULL, device ? &device7 : NULL); + if (SUCCEEDED(hr)) + { + device_impl = impl_from_IDirect3DDevice7(device7); + *device = &device_impl->IDirect3DDevice3_iface; + } return hr; } @@ -4772,15 +4510,21 @@ static HRESULT WINAPI d3d2_CreateDevice(IDirect3D2 *iface, REFCLSID riid, IDirectDrawSurface *surface, IDirect3DDevice2 **device) { IDirectDrawImpl *This = impl_from_IDirect3D2(iface); + IDirectDrawSurfaceImpl *surface_impl = unsafe_impl_from_IDirectDrawSurface(surface); + IDirect3DDevice7 *device7; + IDirect3DDeviceImpl *device_impl; HRESULT hr; TRACE("iface %p, riid %s, surface %p, device %p.\n", iface, debugstr_guid(riid), surface, device); hr = d3d7_CreateDevice(&This->IDirect3D7_iface, riid, - surface ? (IDirectDrawSurface7 *)surface_from_surface3((IDirectDrawSurface3 *)surface) : NULL, - (IDirect3DDevice7 **)device); - if (*device) *device = (IDirect3DDevice2 *)&((IDirect3DDeviceImpl *)*device)->IDirect3DDevice2_vtbl; + surface_impl ? &surface_impl->IDirectDrawSurface7_iface : NULL, device ? &device7 : NULL); + if (SUCCEEDED(hr)) + { + device_impl = impl_from_IDirect3DDevice7(device7); + *device = &device_impl->IDirect3DDevice2_iface; + } return hr; } @@ -4817,49 +4561,41 @@ static HRESULT WINAPI d3d7_CreateVertexBuffer(IDirect3D7 *iface, D3DVERTEXBUFFER if (!vertex_buffer || !desc) return DDERR_INVALIDPARAMS; - TRACE("Vertex buffer description:\n"); - TRACE(" dwSize %u\n", desc->dwSize); - TRACE(" dwCaps %#x\n", desc->dwCaps); - TRACE(" FVF %#x\n", desc->dwFVF); - TRACE(" dwNumVertices %u\n", desc->dwNumVertices); - - /* Now create the vertex buffer */ - object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); - if (!object) + hr = d3d_vertex_buffer_create(&object, This, desc); + if (hr == D3D_OK) { - ERR("Failed to allocate vertex buffer memory.\n"); - return DDERR_OUTOFMEMORY; + TRACE("Created vertex buffer %p.\n", object); + *vertex_buffer = &object->IDirect3DVertexBuffer7_iface; } + else + WARN("Failed to create vertex buffer, hr %#x.\n", hr); - hr = d3d_vertex_buffer_init(object, This, desc); - if (FAILED(hr)) - { - WARN("Failed to initialize vertex buffer, hr %#x.\n", hr); - HeapFree(GetProcessHeap(), 0, object); - return hr; - } - - TRACE("Created vertex buffer %p.\n", object); - *vertex_buffer = (IDirect3DVertexBuffer7 *)object; - - return D3D_OK; + return hr; } static HRESULT WINAPI d3d3_CreateVertexBuffer(IDirect3D3 *iface, D3DVERTEXBUFFERDESC *desc, IDirect3DVertexBuffer **vertex_buffer, DWORD flags, IUnknown *outer_unknown) { IDirectDrawImpl *This = impl_from_IDirect3D3(iface); + IDirect3DVertexBufferImpl *object; HRESULT hr; TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n", iface, desc, vertex_buffer, flags, outer_unknown); - if (outer_unknown) return CLASS_E_NOAGGREGATION; + if (outer_unknown) + return CLASS_E_NOAGGREGATION; + if (!vertex_buffer || !desc) + return DDERR_INVALIDPARAMS; - hr = d3d7_CreateVertexBuffer(&This->IDirect3D7_iface, desc, - (IDirect3DVertexBuffer7 **)vertex_buffer, flags); - if (*vertex_buffer) - *vertex_buffer = (IDirect3DVertexBuffer *)&((IDirect3DVertexBufferImpl *)*vertex_buffer)->IDirect3DVertexBuffer_vtbl; + hr = d3d_vertex_buffer_create(&object, This, desc); + if (hr == D3D_OK) + { + TRACE("Created vertex buffer %p.\n", object); + *vertex_buffer = &object->IDirect3DVertexBuffer_iface; + } + else + WARN("Failed to create vertex buffer, hr %#x.\n", hr); return hr; } @@ -4886,8 +4622,8 @@ static HRESULT WINAPI d3d7_EnumZBufferFormats(IDirect3D7 *iface, REFCLSID device LPD3DENUMPIXELFORMATSCALLBACK callback, void *context) { IDirectDrawImpl *This = impl_from_IDirect3D7(iface); - WINED3DDISPLAYMODE d3ddm; - WINED3DDEVTYPE type; + struct wined3d_display_mode mode; + enum wined3d_device_type type; unsigned int i; HRESULT hr; @@ -4913,43 +4649,43 @@ static HRESULT WINAPI d3d7_EnumZBufferFormats(IDirect3D7 *iface, REFCLSID device || IsEqualGUID(device_iid, &IID_D3DDEVICE_WineD3D)) { TRACE("Asked for HAL device.\n"); - type = WINED3DDEVTYPE_HAL; + type = WINED3D_DEVICE_TYPE_HAL; } else if (IsEqualGUID(device_iid, &IID_IDirect3DRGBDevice) || IsEqualGUID(device_iid, &IID_IDirect3DMMXDevice)) { TRACE("Asked for SW device.\n"); - type = WINED3DDEVTYPE_SW; + type = WINED3D_DEVICE_TYPE_SW; } else if (IsEqualGUID(device_iid, &IID_IDirect3DRefDevice)) { TRACE("Asked for REF device.\n"); - type = WINED3DDEVTYPE_REF; + type = WINED3D_DEVICE_TYPE_REF; } else if (IsEqualGUID(device_iid, &IID_IDirect3DNullDevice)) { TRACE("Asked for NULLREF device.\n"); - type = WINED3DDEVTYPE_NULLREF; + type = WINED3D_DEVICE_TYPE_NULLREF; } else { FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid)); - type = WINED3DDEVTYPE_HAL; + type = WINED3D_DEVICE_TYPE_HAL; } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); /* We need an adapter format from somewhere to please wined3d and WGL. * Use the current display mode. So far all cards offer the same depth * stencil format for all modes, but if some do not and applications do * not like that we'll have to find some workaround, like iterating over * all imaginable formats and collecting all the depth stencil formats we * can get. */ - hr = wined3d_device_get_display_mode(This->wined3d_device, 0, &d3ddm); + hr = wined3d_device_get_display_mode(This->wined3d_device, 0, &mode); for (i = 0; i < (sizeof(formats) / sizeof(*formats)); ++i) { - hr = wined3d_check_device_format(This->wineD3D, WINED3DADAPTER_DEFAULT, type, d3ddm.Format, - WINED3DUSAGE_DEPTHSTENCIL, WINED3DRTYPE_SURFACE, formats[i], SURFACE_OPENGL); + hr = wined3d_check_device_format(This->wined3d, WINED3DADAPTER_DEFAULT, type, mode.format_id, + WINED3DUSAGE_DEPTHSTENCIL, WINED3D_RTYPE_SURFACE, formats[i], SURFACE_OPENGL); if (SUCCEEDED(hr)) { DDPIXELFORMAT pformat; @@ -4963,14 +4699,33 @@ static HRESULT WINAPI d3d7_EnumZBufferFormats(IDirect3D7 *iface, REFCLSID device if (hr != DDENUMRET_OK) { TRACE("Format enumeration cancelled by application.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } } } + + /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM, + * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per + * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and + * newer enumerate both versions, so we do the same(bug 22434) */ + hr = wined3d_check_device_format(This->wined3d, WINED3DADAPTER_DEFAULT, type, mode.format_id, + WINED3DUSAGE_DEPTHSTENCIL, WINED3D_RTYPE_SURFACE, WINED3DFMT_X8D24_UNORM, SURFACE_OPENGL); + if (SUCCEEDED(hr)) + { + DDPIXELFORMAT x8d24 = + { + sizeof(x8d24), DDPF_ZBUFFER, 0, + {24}, {0x00000000}, {0x00ffffff}, {0x00000000} + }; + TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n"); + callback(&x8d24, context); + } + TRACE("End of enumeration.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } @@ -4999,10 +4754,14 @@ static HRESULT WINAPI d3d3_EnumZBufferFormats(IDirect3D3 *iface, REFCLSID device *****************************************************************************/ static HRESULT WINAPI d3d7_EvictManagedTextures(IDirect3D7 *iface) { - FIXME("iface %p stub!\n", iface); + IDirectDrawImpl *This = impl_from_IDirect3D7(iface); - /* TODO: Just enumerate resources using IWineD3DDevice_EnumResources(), - * then unload surfaces / textures. */ + TRACE("iface %p!\n", iface); + + wined3d_mutex_lock(); + if (This->d3d_initialized) + wined3d_device_evict_managed_resources(This->wined3d_device); + wined3d_mutex_unlock(); return D3D_OK; } @@ -5041,9 +4800,9 @@ HRESULT IDirect3DImpl_GetCaps(const struct wined3d *wined3d, D3DDEVICEDESC *desc memset(&wined3d_caps, 0, sizeof(wined3d_caps)); - EnterCriticalSection(&ddraw_cs); - hr = wined3d_get_device_caps(wined3d, 0, WINED3DDEVTYPE_HAL, &wined3d_caps); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); + hr = wined3d_get_device_caps(wined3d, 0, WINED3D_DEVICE_TYPE_HAL, &wined3d_caps); + wined3d_mutex_unlock(); if (FAILED(hr)) { WARN("Failed to get device caps, hr %#x.\n", hr); @@ -5396,39 +5155,6 @@ static const struct IDirectDraw4Vtbl ddraw4_vtbl = ddraw4_GetDeviceIdentifier, }; -static const struct IDirectDraw3Vtbl ddraw3_vtbl = -{ - /* IUnknown */ - ddraw3_QueryInterface, - ddraw3_AddRef, - ddraw3_Release, - /* IDirectDraw */ - ddraw3_Compact, - ddraw3_CreateClipper, - ddraw3_CreatePalette, - ddraw3_CreateSurface, - ddraw3_DuplicateSurface, - ddraw3_EnumDisplayModes, - ddraw3_EnumSurfaces, - ddraw3_FlipToGDISurface, - ddraw3_GetCaps, - ddraw3_GetDisplayMode, - ddraw3_GetFourCCCodes, - ddraw3_GetGDISurface, - ddraw3_GetMonitorFrequency, - ddraw3_GetScanLine, - ddraw3_GetVerticalBlankStatus, - ddraw3_Initialize, - ddraw3_RestoreDisplayMode, - ddraw3_SetCooperativeLevel, - ddraw3_SetDisplayMode, - ddraw3_WaitForVerticalBlank, - /* IDirectDraw2 */ - ddraw3_GetAvailableVidMem, - /* IDirectDraw3 */ - ddraw3_GetSurfaceFromDC, -}; - static const struct IDirectDraw2Vtbl ddraw2_vtbl = { /* IUnknown */ @@ -5632,9 +5358,41 @@ static void CDECL device_parent_wined3d_device_created(struct wined3d_device_par TRACE("device_parent %p, device %p.\n", device_parent, device); } +static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent) +{ + struct IDirectDrawImpl *ddraw = ddraw_from_device_parent(device_parent); + MONITORINFO monitor_info; + HMONITOR monitor; + BOOL ret; + RECT *r; + + TRACE("device_parent %p.\n", device_parent); + + if (!(ddraw->cooperative_level & DDSCL_EXCLUSIVE) || !ddraw->swapchain_window) + { + TRACE("Nothing to resize.\n"); + return; + } + + monitor = MonitorFromWindow(ddraw->swapchain_window, MONITOR_DEFAULTTOPRIMARY); + monitor_info.cbSize = sizeof(monitor_info); + if (!(ret = GetMonitorInfoW(monitor, &monitor_info))) + { + ERR("Failed to get monitor info.\n"); + return; + } + + r = &monitor_info.rcMonitor; + TRACE("Resizing window %p to %s.\n", ddraw->swapchain_window, wine_dbgstr_rect(r)); + + if (!(ret = SetWindowPos(ddraw->swapchain_window, HWND_TOP, r->left, r->top, + r->right - r->left, r->bottom - r->top, SWP_SHOWWINDOW | SWP_NOACTIVATE))) + ERR("Failed to resize window.\n"); +} + static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent *device_parent, void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage, - WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, struct wined3d_surface **surface) + enum wined3d_pool pool, UINT level, enum wined3d_cubemap_face face, struct wined3d_surface **surface) { struct IDirectDrawImpl *ddraw = ddraw_from_device_parent(device_parent); IDirectDrawSurfaceImpl *surf = NULL; @@ -5646,38 +5404,39 @@ static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent * device_parent, container_parent, width, height, format, usage, pool, level, face, surface); searchcaps.dwCaps2 &= ~DDSCAPS2_CUBEMAP_ALLFACES; - switch(face) + switch (face) { - case WINED3DCUBEMAP_FACE_POSITIVE_X: + case WINED3D_CUBEMAP_FACE_POSITIVE_X: TRACE("Asked for positive x\n"); if (searchcaps.dwCaps2 & DDSCAPS2_CUBEMAP) { searchcaps.dwCaps2 |= DDSCAPS2_CUBEMAP_POSITIVEX; } surf = ddraw->tex_root; break; - case WINED3DCUBEMAP_FACE_NEGATIVE_X: + case WINED3D_CUBEMAP_FACE_NEGATIVE_X: TRACE("Asked for negative x\n"); searchcaps.dwCaps2 |= DDSCAPS2_CUBEMAP_NEGATIVEX; break; - case WINED3DCUBEMAP_FACE_POSITIVE_Y: + case WINED3D_CUBEMAP_FACE_POSITIVE_Y: TRACE("Asked for positive y\n"); searchcaps.dwCaps2 |= DDSCAPS2_CUBEMAP_POSITIVEY; break; - case WINED3DCUBEMAP_FACE_NEGATIVE_Y: + case WINED3D_CUBEMAP_FACE_NEGATIVE_Y: TRACE("Asked for negative y\n"); searchcaps.dwCaps2 |= DDSCAPS2_CUBEMAP_NEGATIVEY; break; - case WINED3DCUBEMAP_FACE_POSITIVE_Z: + case WINED3D_CUBEMAP_FACE_POSITIVE_Z: TRACE("Asked for positive z\n"); searchcaps.dwCaps2 |= DDSCAPS2_CUBEMAP_POSITIVEZ; break; - case WINED3DCUBEMAP_FACE_NEGATIVE_Z: + case WINED3D_CUBEMAP_FACE_NEGATIVE_Z: TRACE("Asked for negative z\n"); searchcaps.dwCaps2 |= DDSCAPS2_CUBEMAP_NEGATIVEZ; break; - default: {ERR("Unexpected cube face\n");} /* Stupid compiler */ + default: + ERR("Unexpected cube face.\n"); } if (!surf) { IDirectDrawSurface7 *attached; - IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7 *)ddraw->tex_root, &searchcaps, &attached); - surf = (IDirectDrawSurfaceImpl *)attached; + IDirectDrawSurface7_GetAttachedSurface(&ddraw->tex_root->IDirectDrawSurface7_iface, &searchcaps, &attached); + surf = unsafe_impl_from_IDirectDrawSurface7(attached); IDirectDrawSurface7_Release(attached); } if (!surf) ERR("root search surface not found\n"); @@ -5686,9 +5445,9 @@ static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent * while (i < level) { IDirectDrawSurface7 *attached; - IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7 *)surf, &searchcaps, &attached); + IDirectDrawSurface7_GetAttachedSurface(&surf->IDirectDrawSurface7_iface, &searchcaps, &attached); if(!attached) ERR("Surface not found\n"); - surf = (IDirectDrawSurfaceImpl *)attached; + surf = impl_from_IDirectDrawSurface7(attached); IDirectDrawSurface7_Release(attached); ++i; } @@ -5702,119 +5461,60 @@ static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent * return D3D_OK; } -static HRESULT WINAPI findRenderTarget(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *surface_desc, void *ctx) +static void STDMETHODCALLTYPE ddraw_frontbuffer_destroyed(void *parent) { - IDirectDrawSurfaceImpl *s = (IDirectDrawSurfaceImpl *)surface; - IDirectDrawSurfaceImpl **target = ctx; - - if (!s->isRenderTarget) - { - *target = s; - IDirectDrawSurface7_Release(surface); - return DDENUMRET_CANCEL; - } - - /* Recurse into the surface tree */ - IDirectDrawSurface7_EnumAttachedSurfaces(surface, ctx, findRenderTarget); - - IDirectDrawSurface7_Release(surface); - if (*target) return DDENUMRET_CANCEL; - - return DDENUMRET_OK; + struct IDirectDrawImpl *ddraw = parent; + ddraw->wined3d_frontbuffer = NULL; } +static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops = +{ + ddraw_frontbuffer_destroyed, +}; + static HRESULT CDECL device_parent_create_rendertarget(struct wined3d_device_parent *device_parent, void *container_parent, UINT width, UINT height, enum wined3d_format_id format, - WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable, + enum wined3d_multisample_type multisample_type, DWORD multisample_quality, BOOL lockable, struct wined3d_surface **surface) { struct IDirectDrawImpl *ddraw = ddraw_from_device_parent(device_parent); - IDirectDrawSurfaceImpl *d3d_surface = ddraw->d3d_target; - IDirectDrawSurfaceImpl *target = NULL; + DWORD flags = 0; + HRESULT hr; TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n" "\tmultisample_quality %u, lockable %u, surface %p.\n", device_parent, container_parent, width, height, format, multisample_type, multisample_quality, lockable, surface); - if (d3d_surface->isRenderTarget) + if (ddraw->wined3d_frontbuffer) { - IDirectDrawSurface7_EnumAttachedSurfaces((IDirectDrawSurface7 *)d3d_surface, &target, findRenderTarget); - } - else - { - target = d3d_surface; + ERR("Frontbuffer already created.\n"); + return E_FAIL; } - if (!target) - { - target = ddraw->d3d_target; - ERR(" (%p) : No DirectDrawSurface found to create the back buffer. Using the front buffer as back buffer. Uncertain consequences\n", ddraw); - } + if (lockable) + flags |= WINED3D_SURFACE_MAPPABLE; - /* TODO: Return failure if the dimensions do not match, but this shouldn't happen */ + hr = wined3d_surface_create(ddraw->wined3d_device, width, height, format, 0, + WINED3DUSAGE_RENDERTARGET, WINED3D_POOL_DEFAULT, multisample_type, multisample_quality, + DefaultSurfaceType, flags, ddraw, &ddraw_frontbuffer_parent_ops, surface); + if (SUCCEEDED(hr)) + ddraw->wined3d_frontbuffer = *surface; - *surface = target->wined3d_surface; - wined3d_surface_incref(*surface); - target->isRenderTarget = TRUE; - - TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *surface, d3d_surface); - - return D3D_OK; + return hr; } static HRESULT CDECL device_parent_create_depth_stencil(struct wined3d_device_parent *device_parent, - UINT width, UINT height, enum wined3d_format_id format, WINED3DMULTISAMPLE_TYPE multisample_type, + UINT width, UINT height, enum wined3d_format_id format, enum wined3d_multisample_type multisample_type, DWORD multisample_quality, BOOL discard, struct wined3d_surface **surface) { - struct IDirectDrawImpl *ddraw = ddraw_from_device_parent(device_parent); - IDirectDrawSurfaceImpl *ddraw_surface; - DDSURFACEDESC2 ddsd; - HRESULT hr; - - TRACE("device_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n" - "\tmultisample_quality %u, discard %u, surface %p.\n", - device_parent, width, height, format, multisample_type, multisample_quality, discard, surface); - - *surface = NULL; - - /* Create a DirectDraw surface */ - memset(&ddsd, 0, sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); - ddsd.u4.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); - ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; - ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; - ddsd.dwHeight = height; - ddsd.dwWidth = width; - if (format) - { - PixelFormat_WineD3DtoDD(&ddsd.u4.ddpfPixelFormat, format); - } - else - { - ddsd.dwFlags ^= DDSD_PIXELFORMAT; - } - - ddraw->depthstencil = TRUE; - hr = IDirectDraw7_CreateSurface(&ddraw->IDirectDraw7_iface, &ddsd, - (IDirectDrawSurface7 **)&ddraw_surface, NULL); - ddraw->depthstencil = FALSE; - if (FAILED(hr)) - { - WARN("Failed to create depth/stencil surface, hr %#x.\n", hr); - return hr; - } - - *surface = ddraw_surface->wined3d_surface; - wined3d_surface_incref(*surface); - IDirectDrawSurface7_Release((IDirectDrawSurface7 *)ddraw_surface); - - return D3D_OK; + ERR("DirectDraw doesn't have and shouldn't try creating implicit depth buffers.\n"); + return E_NOTIMPL; } static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *device_parent, void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format, - WINED3DPOOL pool, DWORD usage, struct wined3d_volume **volume) + enum wined3d_pool pool, DWORD usage, struct wined3d_volume **volume) { TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, " "format %#x, pool %#x, usage %#x, volume %p.\n", @@ -5827,30 +5527,23 @@ static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *d } static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent, - WINED3DPRESENT_PARAMETERS *present_parameters, struct wined3d_swapchain **swapchain) + struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain) { struct IDirectDrawImpl *ddraw = ddraw_from_device_parent(device_parent); - IDirectDrawSurfaceImpl *iterator; HRESULT hr; - TRACE("device_parent %p, present_parameters %p, swapchain %p.\n", device_parent, present_parameters, swapchain); + TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain); - hr = wined3d_swapchain_create(ddraw->wined3d_device, present_parameters, - ddraw->ImplType, NULL, &ddraw_null_wined3d_parent_ops, swapchain); + if (ddraw->wined3d_swapchain) + { + ERR("Swapchain already created.\n"); + return E_FAIL; + } + + hr = wined3d_swapchain_create(ddraw->wined3d_device, desc, + DefaultSurfaceType, NULL, &ddraw_null_wined3d_parent_ops, swapchain); if (FAILED(hr)) - { WARN("Failed to create swapchain, hr %#x.\n", hr); - *swapchain = NULL; - return hr; - } - - ddraw->d3d_target->wined3d_swapchain = *swapchain; - iterator = ddraw->d3d_target->complex_array[0]; - while (iterator) - { - iterator->wined3d_swapchain = *swapchain; - iterator = iterator->complex_array[0]; - } return hr; } @@ -5858,6 +5551,7 @@ static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops = { device_parent_wined3d_device_created, + device_parent_mode_changed, device_parent_create_surface, device_parent_create_rendertarget, device_parent_create_depth_stencil, @@ -5865,7 +5559,7 @@ static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops = device_parent_create_swapchain, }; -HRESULT ddraw_init(IDirectDrawImpl *ddraw, WINED3DDEVTYPE device_type) +HRESULT ddraw_init(IDirectDrawImpl *ddraw, enum wined3d_device_type device_type) { HRESULT hr; HDC hDC; @@ -5873,7 +5567,6 @@ HRESULT ddraw_init(IDirectDrawImpl *ddraw, WINED3DDEVTYPE device_type) ddraw->IDirectDraw7_iface.lpVtbl = &ddraw7_vtbl; ddraw->IDirectDraw_iface.lpVtbl = &ddraw1_vtbl; ddraw->IDirectDraw2_iface.lpVtbl = &ddraw2_vtbl; - ddraw->IDirectDraw3_iface.lpVtbl = &ddraw3_vtbl; ddraw->IDirectDraw4_iface.lpVtbl = &ddraw4_vtbl; ddraw->IDirect3D_iface.lpVtbl = &d3d1_vtbl; ddraw->IDirect3D2_iface.lpVtbl = &d3d2_vtbl; @@ -5883,10 +5576,6 @@ HRESULT ddraw_init(IDirectDrawImpl *ddraw, WINED3DDEVTYPE device_type) ddraw->numIfaces = 1; ddraw->ref7 = 1; - /* See comments in IDirectDrawImpl_CreateNewSurface for a description of - * this field. */ - ddraw->ImplType = DefaultSurfaceType; - /* Get the current screen settings. */ hDC = GetDC(0); ddraw->orig_bpp = GetDeviceCaps(hDC, BITSPIXEL) * GetDeviceCaps(hDC, PLANES); @@ -5894,25 +5583,23 @@ HRESULT ddraw_init(IDirectDrawImpl *ddraw, WINED3DDEVTYPE device_type) ddraw->orig_width = GetSystemMetrics(SM_CXSCREEN); ddraw->orig_height = GetSystemMetrics(SM_CYSCREEN); - ddraw->wineD3D = wined3d_create(7, &ddraw->IDirectDraw7_iface); - if (!ddraw->wineD3D) + ddraw->wined3d = wined3d_create(7, WINED3D_LEGACY_DEPTH_BIAS, + &ddraw->IDirectDraw7_iface); + if (!ddraw->wined3d) { WARN("Failed to create a wined3d object.\n"); return E_OUTOFMEMORY; } - hr = wined3d_device_create(ddraw->wineD3D, WINED3DADAPTER_DEFAULT, device_type, - NULL, 0, &ddraw->device_parent, &ddraw->wined3d_device); + hr = wined3d_device_create(ddraw->wined3d, WINED3DADAPTER_DEFAULT, device_type, + NULL, 0, 8, &ddraw->device_parent, &ddraw->wined3d_device); if (FAILED(hr)) { WARN("Failed to create a wined3d device, hr %#x.\n", hr); - wined3d_decref(ddraw->wineD3D); + wined3d_decref(ddraw->wined3d); return hr; } - /* Get the amount of video memory */ - ddraw->total_vidmem = wined3d_device_get_available_texture_mem(ddraw->wined3d_device); - list_init(&ddraw->surface_list); return DD_OK; diff --git a/reactos/dll/directx/wine/ddraw/ddraw.rc b/reactos/dll/directx/wine/ddraw/ddraw.rc new file mode 100644 index 00000000000..14a2b40fc0b --- /dev/null +++ b/reactos/dll/directx/wine/ddraw/ddraw.rc @@ -0,0 +1,3 @@ +#include "version.rc" + +1 WINE_REGISTRY ddraw.rgs \ No newline at end of file diff --git a/reactos/dll/directx/wine/ddraw/ddraw.rgs b/reactos/dll/directx/wine/ddraw/ddraw.rgs new file mode 100644 index 00000000000..d8f8cb43aa2 --- /dev/null +++ b/reactos/dll/directx/wine/ddraw/ddraw.rgs @@ -0,0 +1,21 @@ +HKCR +{ + NoRemove Interface + { + } + NoRemove CLSID + { + '{D7B70EE0-4340-11CF-B063-0020AFC2CD35}' = s 'DirectDraw Object' + { + InprocServer32 = s '%MODULE%' { val ThreadingModel = s 'Both' } + } + '{3C305196-50DB-11D3-9CFE-00C04FD930C5}' = s 'DirectDraw 7 Object' + { + InprocServer32 = s '%MODULE%' { val ThreadingModel = s 'Both' } + } + '{593817A0-7DB3-11CF-A2DE-00AA00B93356}' = s 'DirectDraw Clipper Object' + { + InprocServer32 = s '%MODULE%' { val ThreadingModel = s 'Both' } + } + } +} diff --git a/reactos/dll/directx/wine/ddraw/ddraw_private.h b/reactos/dll/directx/wine/ddraw/ddraw_private.h index 78e69b77aad..67da685cccd 100644 --- a/reactos/dll/directx/wine/ddraw/ddraw_private.h +++ b/reactos/dll/directx/wine/ddraw/ddraw_private.h @@ -44,7 +44,6 @@ extern const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops DECLSPEC_HI /* Typdef the interfaces */ typedef struct IDirectDrawImpl IDirectDrawImpl; typedef struct IDirectDrawSurfaceImpl IDirectDrawSurfaceImpl; -typedef struct IDirectDrawClipperImpl IDirectDrawClipperImpl; typedef struct IDirectDrawPaletteImpl IDirectDrawPaletteImpl; typedef struct IDirect3DDeviceImpl IDirect3DDeviceImpl; typedef struct IDirect3DLightImpl IDirect3DLightImpl; @@ -53,9 +52,6 @@ typedef struct IDirect3DMaterialImpl IDirect3DMaterialImpl; typedef struct IDirect3DExecuteBufferImpl IDirect3DExecuteBufferImpl; typedef struct IDirect3DVertexBufferImpl IDirect3DVertexBufferImpl; -/* Global critical section */ -extern CRITICAL_SECTION ddraw_cs DECLSPEC_HIDDEN; - extern DWORD force_refresh_rate DECLSPEC_HIDDEN; /***************************************************************************** @@ -72,7 +68,6 @@ struct IDirectDrawImpl /* Interfaces */ IDirectDraw7 IDirectDraw7_iface; IDirectDraw4 IDirectDraw4_iface; - IDirectDraw3 IDirectDraw3_iface; IDirectDraw2 IDirectDraw2_iface; IDirectDraw IDirectDraw_iface; IDirect3D7 IDirect3D7_iface; @@ -83,17 +78,17 @@ struct IDirectDrawImpl /* See comment in IDirectDraw::AddRef */ LONG ref7, ref4, ref2, ref3, ref1, numIfaces; + BOOL initialized; - /* WineD3D linkage */ - struct wined3d *wineD3D; + struct wined3d *wined3d; struct wined3d_device *wined3d_device; BOOL d3d_initialized; - /* Misc ddraw fields */ - UINT total_vidmem; - DWORD cur_scanline; - BOOL fake_vblank; - BOOL initialized; + IDirectDrawSurfaceImpl *primary; + RECT primary_lock; + struct wined3d_surface *wined3d_frontbuffer; + struct wined3d_swapchain *wined3d_swapchain; + HWND swapchain_window; /* DirectDraw things, which are not handled by WineD3D */ DWORD cooperative_level; @@ -102,7 +97,6 @@ struct IDirectDrawImpl DWORD orig_bpp; /* D3D things */ - IDirectDrawSurfaceImpl *d3d_target; HWND d3d_window; IDirect3DDeviceImpl *d3ddevice; int d3dversion; @@ -112,12 +106,8 @@ struct IDirectDrawImpl HWND devicewindow; HWND dest_window; - /* The surface type to request */ - WINED3DSURFTYPE ImplType; - /* Helpers for surface creation */ IDirectDrawSurfaceImpl *tex_root; - BOOL depthstencil; /* For the dll unload cleanup code */ struct list ddraw_list_entry; @@ -125,37 +115,27 @@ struct IDirectDrawImpl * because of IParent */ struct list surface_list; - LONG surfaces; /* FVF management */ struct FvfToDecl *decls; UINT numConvertedDecls, declArraySize; }; -#define DDRAW_WINDOW_CLASS_NAME "ddraw_wc" +#define DDRAW_WINDOW_CLASS_NAME "DirectDrawDeviceWnd" -HRESULT ddraw_init(IDirectDrawImpl *ddraw, WINED3DDEVTYPE device_type) DECLSPEC_HIDDEN; +HRESULT ddraw_init(IDirectDrawImpl *ddraw, enum wined3d_device_type device_type) DECLSPEC_HIDDEN; +void ddraw_destroy_swapchain(IDirectDrawImpl *ddraw) DECLSPEC_HIDDEN; -/* Helper structures */ -typedef struct EnumDisplayModesCBS +static inline void ddraw_set_swapchain_window(struct IDirectDrawImpl *ddraw, HWND window) { - void *context; - LPDDENUMMODESCALLBACK2 callback; -} EnumDisplayModesCBS; - -typedef struct EnumSurfacesCBS -{ - void *context; - LPDDENUMSURFACESCALLBACK7 callback; - LPDDSURFACEDESC2 pDDSD; - DWORD Flags; -} EnumSurfacesCBS; + if (window == GetDesktopWindow()) + window = NULL; + ddraw->swapchain_window = window; +} /* Utility functions */ void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS *pIn, DDSCAPS2 *pOut) DECLSPEC_HIDDEN; void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2 *pIn, DDDEVICEIDENTIFIER *pOut) DECLSPEC_HIDDEN; -HRESULT WINAPI ddraw_recreate_surfaces_cb(IDirectDrawSurface7 *surf, - DDSURFACEDESC2 *desc, void *Context) DECLSPEC_HIDDEN; struct wined3d_vertex_declaration *ddraw_find_decl(IDirectDrawImpl *This, DWORD fvf) DECLSPEC_HIDDEN; /* The default surface type */ @@ -168,13 +148,16 @@ extern WINED3DSURFTYPE DefaultSurfaceType DECLSPEC_HIDDEN; struct IDirectDrawSurfaceImpl { /* IUnknown fields */ - const IDirectDrawSurface7Vtbl *lpVtbl; - const IDirectDrawSurface3Vtbl *IDirectDrawSurface3_vtbl; - const IDirectDrawGammaControlVtbl *IDirectDrawGammaControl_vtbl; - const IDirect3DTexture2Vtbl *IDirect3DTexture2_vtbl; - const IDirect3DTextureVtbl *IDirect3DTexture_vtbl; + IDirectDrawSurface7 IDirectDrawSurface7_iface; + IDirectDrawSurface4 IDirectDrawSurface4_iface; + IDirectDrawSurface3 IDirectDrawSurface3_iface; + IDirectDrawSurface2 IDirectDrawSurface2_iface; + IDirectDrawSurface IDirectDrawSurface_iface; + IDirectDrawGammaControl IDirectDrawGammaControl_iface; + IDirect3DTexture2 IDirect3DTexture2_iface; + IDirect3DTexture IDirect3DTexture_iface; - LONG ref; + LONG ref7, ref4, ref3, ref2, ref1, iface_count, gamma_count; IUnknown *ifaceToRelease; int version; @@ -183,11 +166,11 @@ struct IDirectDrawSurfaceImpl IDirectDrawImpl *ddraw; struct wined3d_surface *wined3d_surface; struct wined3d_texture *wined3d_texture; - struct wined3d_swapchain *wined3d_swapchain; /* This implementation handles attaching surfaces to other surfaces */ IDirectDrawSurfaceImpl *next_attached; IDirectDrawSurfaceImpl *first_attached; + IUnknown *attached_iface; /* Complex surfaces are organized in a tree, although the tree is degenerated to a list in most cases. * In mipmap and primary surfaces each level has only one attachment, which is the next surface level. @@ -207,13 +190,9 @@ struct IDirectDrawSurfaceImpl /* Misc things */ DWORD uniqueness_value; UINT mipmap_level; - WINED3DSURFTYPE ImplType; - - /* For D3DDevice creation */ - BOOL isRenderTarget; /* Clipper objects */ - IDirectDrawClipperImpl *clipper; + struct ddraw_clipper *clipper; /* For the ddraw surface list */ struct list surface_list_entry; @@ -222,28 +201,51 @@ struct IDirectDrawSurfaceImpl }; HRESULT ddraw_surface_create_texture(IDirectDrawSurfaceImpl *surface) DECLSPEC_HIDDEN; -void ddraw_surface_destroy(IDirectDrawSurfaceImpl *surface) DECLSPEC_HIDDEN; HRESULT ddraw_surface_init(IDirectDrawSurfaceImpl *surface, IDirectDrawImpl *ddraw, - DDSURFACEDESC2 *desc, UINT mip_level, WINED3DSURFTYPE surface_type) DECLSPEC_HIDDEN; + DDSURFACEDESC2 *desc, UINT mip_level, UINT version) DECLSPEC_HIDDEN; +ULONG ddraw_surface_release_iface(IDirectDrawSurfaceImpl *This) DECLSPEC_HIDDEN; -static inline IDirectDrawSurfaceImpl *surface_from_texture1(IDirect3DTexture *iface) +static inline IDirectDrawSurfaceImpl *impl_from_IDirect3DTexture(IDirect3DTexture *iface) { - return (IDirectDrawSurfaceImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawSurfaceImpl, IDirect3DTexture_vtbl)); + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirect3DTexture_iface); } -static inline IDirectDrawSurfaceImpl *surface_from_texture2(IDirect3DTexture2 *iface) +static inline IDirectDrawSurfaceImpl *impl_from_IDirect3DTexture2(IDirect3DTexture2 *iface) { - return (IDirectDrawSurfaceImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawSurfaceImpl, IDirect3DTexture2_vtbl)); + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirect3DTexture2_iface); } -static inline IDirectDrawSurfaceImpl *surface_from_surface3(IDirectDrawSurface3 *iface) +static inline IDirectDrawSurfaceImpl *impl_from_IDirectDrawSurface(IDirectDrawSurface *iface) { - return (IDirectDrawSurfaceImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawSurfaceImpl, IDirectDrawSurface3_vtbl)); + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirectDrawSurface_iface); } -/* Get the number of bytes per pixel for a given surface */ -#define PFGET_BPP(pf) (pf.dwFlags&DDPF_PALETTEINDEXED8?1:((pf.dwRGBBitCount+7)/8)) -#define GET_BPP(desc) PFGET_BPP(desc.ddpfPixelFormat) +static inline IDirectDrawSurfaceImpl *impl_from_IDirectDrawSurface2(IDirectDrawSurface2 *iface) +{ + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirectDrawSurface2_iface); +} + +static inline IDirectDrawSurfaceImpl *impl_from_IDirectDrawSurface3(IDirectDrawSurface3 *iface) +{ + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirectDrawSurface3_iface); +} + +static inline IDirectDrawSurfaceImpl *impl_from_IDirectDrawSurface4(IDirectDrawSurface4 *iface) +{ + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirectDrawSurface4_iface); +} + +static inline IDirectDrawSurfaceImpl *impl_from_IDirectDrawSurface7(IDirectDrawSurface7 *iface) +{ + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirectDrawSurface7_iface); +} + +IDirectDrawSurfaceImpl *unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface *iface) DECLSPEC_HIDDEN; +IDirectDrawSurfaceImpl *unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4 *iface) DECLSPEC_HIDDEN; +IDirectDrawSurfaceImpl *unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7 *iface) DECLSPEC_HIDDEN; + +IDirectDrawSurfaceImpl *unsafe_impl_from_IDirect3DTexture(IDirect3DTexture *iface) DECLSPEC_HIDDEN; +IDirectDrawSurfaceImpl *unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2 *iface) DECLSPEC_HIDDEN; #define DDRAW_INVALID_HANDLE ~0U @@ -279,10 +281,10 @@ void *ddraw_get_object(struct ddraw_handle_table *t, DWORD handle, enum ddraw_ha struct IDirect3DDeviceImpl { /* IUnknown */ - const IDirect3DDevice7Vtbl *lpVtbl; - const IDirect3DDevice3Vtbl *IDirect3DDevice3_vtbl; - const IDirect3DDevice2Vtbl *IDirect3DDevice2_vtbl; - const IDirect3DDeviceVtbl *IDirect3DDevice_vtbl; + IDirect3DDevice7 IDirect3DDevice7_iface; + IDirect3DDevice3 IDirect3DDevice3_iface; + IDirect3DDevice2 IDirect3DDevice2_iface; + IDirect3DDevice IDirect3DDevice_iface; LONG ref; /* Other object connections */ @@ -298,6 +300,10 @@ struct IDirect3DDeviceImpl /* Required to keep track which of two available texture blending modes in d3ddevice3 is used */ BOOL legacyTextureBlending; + BOOL from_surface; + + D3DMATRIX legacy_projection; + D3DMATRIX legacy_clipspace; /* Light state */ DWORD material; @@ -325,52 +331,44 @@ extern const GUID IID_D3DDEVICE_WineD3D DECLSPEC_HIDDEN; /* Helper functions */ HRESULT IDirect3DImpl_GetCaps(const struct wined3d *wined3d, D3DDEVICEDESC *Desc123, D3DDEVICEDESC7 *Desc7) DECLSPEC_HIDDEN; -WINED3DZBUFFERTYPE IDirect3DDeviceImpl_UpdateDepthStencil(IDirect3DDeviceImpl *This) DECLSPEC_HIDDEN; +enum wined3d_depth_buffer_type IDirect3DDeviceImpl_UpdateDepthStencil(IDirect3DDeviceImpl *device) DECLSPEC_HIDDEN; -static inline IDirect3DDeviceImpl *device_from_device1(IDirect3DDevice *iface) +static inline IDirect3DDeviceImpl *impl_from_IDirect3DDevice(IDirect3DDevice *iface) { - return (IDirect3DDeviceImpl *)((char*)iface - FIELD_OFFSET(IDirect3DDeviceImpl, IDirect3DDevice_vtbl)); + return CONTAINING_RECORD(iface, IDirect3DDeviceImpl, IDirect3DDevice_iface); } -static inline IDirect3DDeviceImpl *device_from_device2(IDirect3DDevice2 *iface) +static inline IDirect3DDeviceImpl *impl_from_IDirect3DDevice2(IDirect3DDevice2 *iface) { - return (IDirect3DDeviceImpl *)((char*)iface - FIELD_OFFSET(IDirect3DDeviceImpl, IDirect3DDevice2_vtbl)); + return CONTAINING_RECORD(iface, IDirect3DDeviceImpl, IDirect3DDevice2_iface); } -static inline IDirect3DDeviceImpl *device_from_device3(IDirect3DDevice3 *iface) +static inline IDirect3DDeviceImpl *impl_from_IDirect3DDevice3(IDirect3DDevice3 *iface) { - return (IDirect3DDeviceImpl *)((char*)iface - FIELD_OFFSET(IDirect3DDeviceImpl, IDirect3DDevice3_vtbl)); + return CONTAINING_RECORD(iface, IDirect3DDeviceImpl, IDirect3DDevice3_iface); } -/* Structures */ -struct EnumTextureFormatsCBS +static inline IDirect3DDeviceImpl *impl_from_IDirect3DDevice7(IDirect3DDevice7 *iface) { - LPD3DENUMTEXTUREFORMATSCALLBACK cbv2; - LPD3DENUMPIXELFORMATSCALLBACK cbv7; - void *Context; -}; + return CONTAINING_RECORD(iface, IDirect3DDeviceImpl, IDirect3DDevice7_iface); +} -/* Structure for EnumZBufferFormats */ -struct EnumZBufferFormatsData -{ - LPD3DENUMPIXELFORMATSCALLBACK Callback; - void *Context; -}; +IDirect3DDeviceImpl *unsafe_impl_from_IDirect3DDevice(IDirect3DDevice *iface) DECLSPEC_HIDDEN; +IDirect3DDeviceImpl *unsafe_impl_from_IDirect3DDevice2(IDirect3DDevice2 *iface) DECLSPEC_HIDDEN; +IDirect3DDeviceImpl *unsafe_impl_from_IDirect3DDevice3(IDirect3DDevice3 *iface) DECLSPEC_HIDDEN; +IDirect3DDeviceImpl *unsafe_impl_from_IDirect3DDevice7(IDirect3DDevice7 *iface) DECLSPEC_HIDDEN; -/***************************************************************************** - * IDirectDrawClipper implementation structure - *****************************************************************************/ -struct IDirectDrawClipperImpl +struct ddraw_clipper { - /* IUnknown fields */ - const IDirectDrawClipperVtbl *lpVtbl; + IDirectDrawClipper IDirectDrawClipper_iface; LONG ref; - - struct wined3d_clipper *wineD3DClipper; + HWND window; + HRGN region; BOOL initialized; }; -HRESULT ddraw_clipper_init(IDirectDrawClipperImpl *clipper) DECLSPEC_HIDDEN; +HRESULT ddraw_clipper_init(struct ddraw_clipper *clipper) DECLSPEC_HIDDEN; +struct ddraw_clipper *unsafe_impl_from_IDirectDrawClipper(IDirectDrawClipper *iface) DECLSPEC_HIDDEN; /***************************************************************************** * IDirectDrawPalette implementation structure @@ -378,7 +376,7 @@ HRESULT ddraw_clipper_init(IDirectDrawClipperImpl *clipper) DECLSPEC_HIDDEN; struct IDirectDrawPaletteImpl { /* IUnknown fields */ - const IDirectDrawPaletteVtbl *lpVtbl; + IDirectDrawPalette IDirectDrawPalette_iface; LONG ref; struct wined3d_palette *wineD3DPalette; @@ -387,6 +385,13 @@ struct IDirectDrawPaletteImpl IUnknown *ifaceToRelease; }; +static inline IDirectDrawPaletteImpl *impl_from_IDirectDrawPalette(IDirectDrawPalette *iface) +{ + return CONTAINING_RECORD(iface, IDirectDrawPaletteImpl, IDirectDrawPalette_iface); +} + +IDirectDrawPaletteImpl *unsafe_impl_from_IDirectDrawPalette(IDirectDrawPalette *iface) DECLSPEC_HIDDEN; + HRESULT ddraw_palette_init(IDirectDrawPaletteImpl *palette, IDirectDrawImpl *ddraw, DWORD flags, PALETTEENTRY *entries) DECLSPEC_HIDDEN; @@ -403,7 +408,7 @@ struct object_creation_info ******************************************************************************/ struct IDirect3DLightImpl { - const IDirect3DLightVtbl *lpVtbl; + IDirect3DLight IDirect3DLight_iface; LONG ref; /* IDirect3DLight fields */ @@ -424,15 +429,16 @@ struct IDirect3DLightImpl void light_activate(IDirect3DLightImpl *light) DECLSPEC_HIDDEN; void light_deactivate(IDirect3DLightImpl *light) DECLSPEC_HIDDEN; void d3d_light_init(IDirect3DLightImpl *light, IDirectDrawImpl *ddraw) DECLSPEC_HIDDEN; +IDirect3DLightImpl *unsafe_impl_from_IDirect3DLight(IDirect3DLight *iface) DECLSPEC_HIDDEN; /****************************************************************************** * IDirect3DMaterial implementation structure - Wraps to D3D7 ******************************************************************************/ struct IDirect3DMaterialImpl { - const IDirect3DMaterial3Vtbl *lpVtbl; - const IDirect3DMaterial2Vtbl *IDirect3DMaterial2_vtbl; - const IDirect3DMaterialVtbl *IDirect3DMaterial_vtbl; + IDirect3DMaterial3 IDirect3DMaterial3_iface; + IDirect3DMaterial2 IDirect3DMaterial2_iface; + IDirect3DMaterial IDirect3DMaterial_iface; LONG ref; /* IDirect3DMaterial2 fields */ @@ -445,14 +451,14 @@ struct IDirect3DMaterialImpl /* Helper functions */ void material_activate(IDirect3DMaterialImpl* This) DECLSPEC_HIDDEN; -void d3d_material_init(IDirect3DMaterialImpl *material, IDirectDrawImpl *ddraw) DECLSPEC_HIDDEN; +IDirect3DMaterialImpl *d3d_material_create(IDirectDrawImpl *ddraw) DECLSPEC_HIDDEN; /***************************************************************************** * IDirect3DViewport - Wraps to D3D7 *****************************************************************************/ struct IDirect3DViewportImpl { - const IDirect3DViewport3Vtbl *lpVtbl; + IDirect3DViewport3 IDirect3DViewport3_iface; LONG ref; /* IDirect3DViewport fields */ @@ -479,6 +485,10 @@ struct IDirect3DViewportImpl IDirect3DMaterialImpl *background; }; +IDirect3DViewportImpl *unsafe_impl_from_IDirect3DViewport3(IDirect3DViewport3 *iface) DECLSPEC_HIDDEN; +IDirect3DViewportImpl *unsafe_impl_from_IDirect3DViewport2(IDirect3DViewport2 *iface) DECLSPEC_HIDDEN; +IDirect3DViewportImpl *unsafe_impl_from_IDirect3DViewport(IDirect3DViewport *iface) DECLSPEC_HIDDEN; + /* Helper functions */ void viewport_activate(IDirect3DViewportImpl* This, BOOL ignore_lights) DECLSPEC_HIDDEN; void d3d_viewport_init(IDirect3DViewportImpl *viewport, IDirectDrawImpl *ddraw) DECLSPEC_HIDDEN; @@ -488,10 +498,8 @@ void d3d_viewport_init(IDirect3DViewportImpl *viewport, IDirectDrawImpl *ddraw) *****************************************************************************/ struct IDirect3DExecuteBufferImpl { - /* IUnknown */ - const IDirect3DExecuteBufferVtbl *lpVtbl; - LONG ref; - + IDirect3DExecuteBuffer IDirect3DExecuteBuffer_iface; + LONG ref; /* IDirect3DExecuteBuffer fields */ IDirectDrawImpl *ddraw; IDirect3DDeviceImpl *d3ddev; @@ -512,6 +520,7 @@ struct IDirect3DExecuteBufferImpl HRESULT d3d_execute_buffer_init(IDirect3DExecuteBufferImpl *execute_buffer, IDirect3DDeviceImpl *device, D3DEXECUTEBUFFERDESC *desc) DECLSPEC_HIDDEN; +IDirect3DExecuteBufferImpl *unsafe_impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface) DECLSPEC_HIDDEN; /* The execute function */ HRESULT d3d_execute_buffer_execute(IDirect3DExecuteBufferImpl *execute_buffer, @@ -522,10 +531,9 @@ HRESULT d3d_execute_buffer_execute(IDirect3DExecuteBufferImpl *execute_buffer, *****************************************************************************/ struct IDirect3DVertexBufferImpl { - /*** IUnknown Methods ***/ - const IDirect3DVertexBuffer7Vtbl *lpVtbl; - const IDirect3DVertexBufferVtbl *IDirect3DVertexBuffer_vtbl; - LONG ref; + IDirect3DVertexBuffer7 IDirect3DVertexBuffer7_iface; + IDirect3DVertexBuffer IDirect3DVertexBuffer_iface; + LONG ref; /*** WineD3D and ddraw links ***/ struct wined3d_buffer *wineD3DVertexBuffer; @@ -537,14 +545,10 @@ struct IDirect3DVertexBufferImpl DWORD fvf; }; -HRESULT d3d_vertex_buffer_init(IDirect3DVertexBufferImpl *buffer, - IDirectDrawImpl *ddraw, D3DVERTEXBUFFERDESC *desc) DECLSPEC_HIDDEN; - -static inline IDirect3DVertexBufferImpl *vb_from_vb1(IDirect3DVertexBuffer *iface) -{ - return (IDirect3DVertexBufferImpl *)((char*)iface - - FIELD_OFFSET(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer_vtbl)); -} +HRESULT d3d_vertex_buffer_create(IDirect3DVertexBufferImpl **vertex_buf, IDirectDrawImpl *ddraw, + D3DVERTEXBUFFERDESC *desc) DECLSPEC_HIDDEN; +IDirect3DVertexBufferImpl *unsafe_impl_from_IDirect3DVertexBuffer(IDirect3DVertexBuffer *iface) DECLSPEC_HIDDEN; +IDirect3DVertexBufferImpl *unsafe_impl_from_IDirect3DVertexBuffer7(IDirect3DVertexBuffer7 *iface) DECLSPEC_HIDDEN; /***************************************************************************** * Helper functions from utils.c @@ -564,6 +568,8 @@ void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps) DECLSPEC_HIDDEN; DWORD get_flexible_vertex_size(DWORD d3dvtVertexType) DECLSPEC_HIDDEN; void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in) DECLSPEC_HIDDEN; void DDRAW_dump_cooperativelevel(DWORD cooplevel) DECLSPEC_HIDDEN; +void DDSD_to_DDSD2(const DDSURFACEDESC *in, DDSURFACEDESC2 *out) DECLSPEC_HIDDEN; +void DDSD2_to_DDSD(const DDSURFACEDESC2 *in, DDSURFACEDESC *out) DECLSPEC_HIDDEN; /* This only needs to be here as long the processvertices functionality of * IDirect3DExecuteBuffer isn't in WineD3D */ @@ -592,10 +598,11 @@ typedef struct #define DD_STRUCT_COPY_BYSIZE_(to,from,from_size) \ do { \ DWORD __size = (to)->dwSize; \ - DWORD __copysize = min(__size, from_size); \ + DWORD __resetsize = min(__size, sizeof(*to)); \ + DWORD __copysize = min(__resetsize, from_size); \ assert(to != from); \ memcpy(to, from, __copysize); \ - memset((char*)(to) + __copysize, 0, __size - __copysize); \ + memset((char*)(to) + __copysize, 0, __resetsize - __copysize); \ (to)->dwSize = __size; /* restore size */ \ } while (0) diff --git a/reactos/dll/directx/wine/ddraw/device.c b/reactos/dll/directx/wine/ddraw/device.c index ad5edfe9019..680f60f3934 100644 --- a/reactos/dll/directx/wine/ddraw/device.c +++ b/reactos/dll/directx/wine/ddraw/device.c @@ -101,7 +101,7 @@ IDirect3DDeviceImpl_7_QueryInterface(IDirect3DDevice7 *iface, REFIID refiid, void **obj) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(refiid), obj); @@ -163,15 +163,15 @@ IDirect3DDeviceImpl_7_QueryInterface(IDirect3DDevice7 *iface, /* Direct3DDevice */ else if ( IsEqualGUID( &IID_IDirect3DDevice , refiid ) ) { - *obj = &This->IDirect3DDevice_vtbl; + *obj = &This->IDirect3DDevice_iface; TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj); } else if ( IsEqualGUID( &IID_IDirect3DDevice2 , refiid ) ) { - *obj = &This->IDirect3DDevice2_vtbl; + *obj = &This->IDirect3DDevice2_iface; TRACE("(%p) Returning IDirect3DDevice2 interface at %p\n", This, *obj); } else if ( IsEqualGUID( &IID_IDirect3DDevice3 , refiid ) ) { - *obj = &This->IDirect3DDevice3_vtbl; + *obj = &This->IDirect3DDevice3_iface; TRACE("(%p) Returning IDirect3DDevice3 interface at %p\n", This, *obj); } else if ( IsEqualGUID( &IID_IDirect3DDevice7 , refiid ) ) { @@ -179,6 +179,13 @@ IDirect3DDeviceImpl_7_QueryInterface(IDirect3DDevice7 *iface, TRACE("(%p) Returning IDirect3DDevice7 interface at %p\n", This, *obj); } + /* DirectDrawSurface */ + else if (IsEqualGUID(&IID_IDirectDrawSurface, refiid) && This->from_surface) + { + *obj = &This->target->IDirectDrawSurface_iface; + TRACE("Returning IDirectDrawSurface interface %p.\n", *obj); + } + /* Unknown interface */ else { @@ -194,25 +201,28 @@ IDirect3DDeviceImpl_7_QueryInterface(IDirect3DDevice7 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_3_QueryInterface(IDirect3DDevice3 *iface, REFIID riid, void **obj) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj); - return IDirect3DDevice7_QueryInterface((IDirect3DDevice7 *)device_from_device3(iface), riid, obj); + return IDirect3DDevice7_QueryInterface(&This->IDirect3DDevice7_iface, riid, obj); } static HRESULT WINAPI IDirect3DDeviceImpl_2_QueryInterface(IDirect3DDevice2 *iface, REFIID riid, void **obj) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj); - return IDirect3DDevice7_QueryInterface((IDirect3DDevice7 *)device_from_device2(iface), riid, obj); + return IDirect3DDevice7_QueryInterface(&This->IDirect3DDevice7_iface, riid, obj); } static HRESULT WINAPI IDirect3DDeviceImpl_1_QueryInterface(IDirect3DDevice *iface, REFIID riid, void **obp) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obp); - return IDirect3DDevice7_QueryInterface((IDirect3DDevice7 *)device_from_device1(iface), riid, obp); + return IDirect3DDevice7_QueryInterface(&This->IDirect3DDevice7_iface, riid, obp); } /***************************************************************************** @@ -230,7 +240,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_1_QueryInterface(IDirect3DDevice *ifac static ULONG WINAPI IDirect3DDeviceImpl_7_AddRef(IDirect3DDevice7 *iface) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); ULONG ref = InterlockedIncrement(&This->ref); TRACE("%p increasing refcount to %u.\n", This, ref); @@ -240,23 +250,26 @@ IDirect3DDeviceImpl_7_AddRef(IDirect3DDevice7 *iface) static ULONG WINAPI IDirect3DDeviceImpl_3_AddRef(IDirect3DDevice3 *iface) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); TRACE("iface %p.\n", iface); - return IDirect3DDevice7_AddRef((IDirect3DDevice7 *)device_from_device3(iface)); + return IDirect3DDevice7_AddRef(&This->IDirect3DDevice7_iface); } static ULONG WINAPI IDirect3DDeviceImpl_2_AddRef(IDirect3DDevice2 *iface) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p.\n", iface); - return IDirect3DDevice7_AddRef((IDirect3DDevice7 *)device_from_device2(iface)); + return IDirect3DDevice7_AddRef(&This->IDirect3DDevice7_iface); } static ULONG WINAPI IDirect3DDeviceImpl_1_AddRef(IDirect3DDevice *iface) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); TRACE("iface %p.\n", iface); - return IDirect3DDevice7_AddRef((IDirect3DDevice7 *)device_from_device1(iface)); + return IDirect3DDevice7_AddRef(&This->IDirect3DDevice7_iface); } /***************************************************************************** @@ -274,7 +287,7 @@ static ULONG WINAPI IDirect3DDeviceImpl_1_AddRef(IDirect3DDevice *iface) static ULONG WINAPI IDirect3DDeviceImpl_7_Release(IDirect3DDevice7 *iface) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); ULONG ref = InterlockedDecrement(&This->ref); TRACE("%p decreasing refcount to %u.\n", This, ref); @@ -287,7 +300,7 @@ IDirect3DDeviceImpl_7_Release(IDirect3DDevice7 *iface) { DWORD i; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); /* There is no need to unset any resources here, wined3d will take * care of that on Uninit3D(). */ @@ -298,7 +311,7 @@ IDirect3DDeviceImpl_7_Release(IDirect3DDevice7 *iface) /* Set the device up to render to the front buffer since the back * buffer will vanish soon. */ wined3d_device_set_render_target(This->wined3d_device, 0, - This->ddraw->d3d_target->wined3d_surface, TRUE); + This->ddraw->wined3d_frontbuffer, TRUE); /* Release the WineD3DDevice. This won't destroy it. */ if (!wined3d_device_decref(This->wined3d_device)) @@ -327,7 +340,7 @@ IDirect3DDeviceImpl_7_Release(IDirect3DDevice7 *iface) { /* No FIXME here because this might happen because of sloppy applications. */ WARN("Leftover matrix handle %#x (%p), deleting.\n", i + 1, entry->object); - IDirect3DDevice_DeleteMatrix((IDirect3DDevice *)&This->IDirect3DDevice_vtbl, i + 1); + IDirect3DDevice_DeleteMatrix(&This->IDirect3DDevice_iface, i + 1); break; } @@ -355,19 +368,18 @@ IDirect3DDeviceImpl_7_Release(IDirect3DDevice7 *iface) ddraw_handle_table_destroy(&This->handle_table); - TRACE("Releasing target %p %p\n", This->target, This->ddraw->d3d_target); + TRACE("Releasing target %p.\n", This->target); /* Release the render target and the WineD3D render target * (See IDirect3D7::CreateDevice for more comments on this) */ - IDirectDrawSurface7_Release((IDirectDrawSurface7 *)This->target); - IDirectDrawSurface7_Release((IDirectDrawSurface7 *)This->ddraw->d3d_target); + IDirectDrawSurface7_Release(&This->target->IDirectDrawSurface7_iface); TRACE("Target release done\n"); This->ddraw->d3ddevice = NULL; /* Now free the structure */ HeapFree(GetProcessHeap(), 0, This); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); } TRACE("Done\n"); @@ -376,23 +388,26 @@ IDirect3DDeviceImpl_7_Release(IDirect3DDevice7 *iface) static ULONG WINAPI IDirect3DDeviceImpl_3_Release(IDirect3DDevice3 *iface) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); TRACE("iface %p.\n", iface); - return IDirect3DDevice7_Release((IDirect3DDevice7 *)device_from_device3(iface)); + return IDirect3DDevice7_Release(&This->IDirect3DDevice7_iface); } static ULONG WINAPI IDirect3DDeviceImpl_2_Release(IDirect3DDevice2 *iface) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p.\n", iface); - return IDirect3DDevice7_Release((IDirect3DDevice7 *)device_from_device2(iface)); + return IDirect3DDevice7_Release(&This->IDirect3DDevice7_iface); } static ULONG WINAPI IDirect3DDeviceImpl_1_Release(IDirect3DDevice *iface) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); TRACE("iface %p.\n", iface); - return IDirect3DDevice7_Release((IDirect3DDevice7 *)device_from_device1(iface)); + return IDirect3DDevice7_Release(&This->IDirect3DDevice7_iface); } /***************************************************************************** @@ -446,13 +461,19 @@ static HRESULT IDirect3DDeviceImpl_7_GetCaps(IDirect3DDevice7 *iface, D3DDEVICEDESC7 *Desc) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); D3DDEVICEDESC OldDesc; TRACE("iface %p, device_desc %p.\n", iface, Desc); + if (!Desc) + { + WARN("Desc is NULL, returning DDERR_INVALIDPARAMS.\n"); + return DDERR_INVALIDPARAMS; + } + /* Call the same function used by IDirect3D, this saves code */ - return IDirect3DImpl_GetCaps(This->ddraw->wineD3D, &OldDesc, Desc); + return IDirect3DImpl_GetCaps(This->ddraw->wined3d, &OldDesc, Desc); } static HRESULT WINAPI @@ -492,38 +513,83 @@ IDirect3DDeviceImpl_7_GetCaps_FPUPreserve(IDirect3DDevice7 *iface, * D3DERR_* if a problem occurs. See WineD3D * *****************************************************************************/ + +/* There are 3 versions of D3DDEVICEDESC. All 3 share the same name because + * Microsoft just expanded the existing structure without naming them + * D3DDEVICEDESC2 and D3DDEVICEDESC3. Which version is used have depends + * on the version of the DirectX SDK. DirectX 6+ and Wine use the latest + * one with 252 bytes. + * + * All 3 versions are allowed as parameters and only the specified amount of + * bytes is written. + * + * Note that Direct3D7 and earlier are not available in native Win64 + * ddraw.dll builds, so possible size differences between 32 bit and + * 64 bit are a non-issue. + */ +static inline BOOL check_d3ddevicedesc_size(DWORD size) +{ + if (size == FIELD_OFFSET(D3DDEVICEDESC, dwMinTextureWidth) /* 172 */ + || size == FIELD_OFFSET(D3DDEVICEDESC, dwMaxTextureRepeat) /* 204 */ + || size == sizeof(D3DDEVICEDESC) /* 252 */) return TRUE; + return FALSE; +} + static HRESULT WINAPI IDirect3DDeviceImpl_3_GetCaps(IDirect3DDevice3 *iface, D3DDEVICEDESC *HWDesc, D3DDEVICEDESC *HelDesc) { - IDirect3DDeviceImpl *This = device_from_device3(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); + D3DDEVICEDESC oldDesc; D3DDEVICEDESC7 newDesc; HRESULT hr; TRACE("iface %p, hw_desc %p, hel_desc %p.\n", iface, HWDesc, HelDesc); - hr = IDirect3DImpl_GetCaps(This->ddraw->wineD3D, HWDesc, &newDesc); + if (!HWDesc) + { + WARN("HWDesc is NULL, returning DDERR_INVALIDPARAMS.\n"); + return DDERR_INVALIDPARAMS; + } + if (!check_d3ddevicedesc_size(HWDesc->dwSize)) + { + WARN("HWDesc->dwSize is %u, returning DDERR_INVALIDPARAMS.\n", HWDesc->dwSize); + return DDERR_INVALIDPARAMS; + } + if (!HelDesc) + { + WARN("HelDesc is NULL, returning DDERR_INVALIDPARAMS.\n"); + return DDERR_INVALIDPARAMS; + } + if (!check_d3ddevicedesc_size(HelDesc->dwSize)) + { + WARN("HelDesc->dwSize is %u, returning DDERR_INVALIDPARAMS.\n", HelDesc->dwSize); + return DDERR_INVALIDPARAMS; + } + + hr = IDirect3DImpl_GetCaps(This->ddraw->wined3d, &oldDesc, &newDesc); if(hr != D3D_OK) return hr; - *HelDesc = *HWDesc; + DD_STRUCT_COPY_BYSIZE(HWDesc, &oldDesc); + DD_STRUCT_COPY_BYSIZE(HelDesc, &oldDesc); return D3D_OK; } static HRESULT WINAPI IDirect3DDeviceImpl_2_GetCaps(IDirect3DDevice2 *iface, D3DDEVICEDESC *D3DHWDevDesc, D3DDEVICEDESC *D3DHELDevDesc) { - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, hw_desc %p, hel_desc %p.\n", iface, D3DHWDevDesc, D3DHELDevDesc); - return IDirect3DDevice3_GetCaps((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, D3DHWDevDesc, D3DHELDevDesc); + return IDirect3DDevice3_GetCaps(&This->IDirect3DDevice3_iface, D3DHWDevDesc, D3DHELDevDesc); } static HRESULT WINAPI IDirect3DDeviceImpl_1_GetCaps(IDirect3DDevice *iface, D3DDEVICEDESC *D3DHWDevDesc, D3DDEVICEDESC *D3DHELDevDesc) { - IDirect3DDeviceImpl *This = device_from_device1(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); TRACE("iface %p, hw_desc %p, hel_desc %p.\n", iface, D3DHWDevDesc, D3DHELDevDesc); - return IDirect3DDevice3_GetCaps((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, D3DHWDevDesc, D3DHELDevDesc); + return IDirect3DDevice3_GetCaps(&This->IDirect3DDevice3_iface, D3DHWDevDesc, D3DHELDevDesc); } /***************************************************************************** @@ -543,14 +609,14 @@ IDirect3DDeviceImpl_2_SwapTextureHandles(IDirect3DDevice2 *iface, IDirect3DTexture2 *Tex1, IDirect3DTexture2 *Tex2) { - IDirect3DDeviceImpl *This = device_from_device2(iface); - IDirectDrawSurfaceImpl *surf1 = surface_from_texture2(Tex1); - IDirectDrawSurfaceImpl *surf2 = surface_from_texture2(Tex2); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); + IDirectDrawSurfaceImpl *surf1 = unsafe_impl_from_IDirect3DTexture2(Tex1); + IDirectDrawSurfaceImpl *surf2 = unsafe_impl_from_IDirect3DTexture2(Tex2); DWORD h1, h2; TRACE("iface %p, tex1 %p, tex2 %p.\n", iface, Tex1, Tex2); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); h1 = surf1->Handle - 1; h2 = surf2->Handle - 1; @@ -559,7 +625,7 @@ IDirect3DDeviceImpl_2_SwapTextureHandles(IDirect3DDevice2 *iface, surf2->Handle = h1 + 1; surf1->Handle = h2 + 1; - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } @@ -567,15 +633,15 @@ IDirect3DDeviceImpl_2_SwapTextureHandles(IDirect3DDevice2 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_1_SwapTextureHandles(IDirect3DDevice *iface, IDirect3DTexture *D3DTex1, IDirect3DTexture *D3DTex2) { - IDirect3DDeviceImpl *This = device_from_device1(iface); - IDirectDrawSurfaceImpl *surf1 = surface_from_texture1(D3DTex1); - IDirectDrawSurfaceImpl *surf2 = surface_from_texture1(D3DTex2); - IDirect3DTexture2 *t1 = surf1 ? (IDirect3DTexture2 *)&surf1->IDirect3DTexture2_vtbl : NULL; - IDirect3DTexture2 *t2 = surf2 ? (IDirect3DTexture2 *)&surf2->IDirect3DTexture2_vtbl : NULL; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); + IDirectDrawSurfaceImpl *surf1 = unsafe_impl_from_IDirect3DTexture(D3DTex1); + IDirectDrawSurfaceImpl *surf2 = unsafe_impl_from_IDirect3DTexture(D3DTex2); + IDirect3DTexture2 *t1 = surf1 ? &surf1->IDirect3DTexture2_iface : NULL; + IDirect3DTexture2 *t2 = surf2 ? &surf2->IDirect3DTexture2_iface : NULL; TRACE("iface %p, tex1 %p, tex2 %p.\n", iface, D3DTex1, D3DTex2); - return IDirect3DDevice2_SwapTextureHandles((IDirect3DDevice2 *)&This->IDirect3DDevice2_vtbl, t1, t2); + return IDirect3DDevice2_SwapTextureHandles(&This->IDirect3DDevice2_iface, t1, t2); } /***************************************************************************** @@ -617,20 +683,20 @@ IDirect3DDeviceImpl_3_GetStats(IDirect3DDevice3 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_2_GetStats(IDirect3DDevice2 *iface, D3DSTATS *Stats) { - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, stats %p.\n", iface, Stats); - return IDirect3DDevice3_GetStats((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, Stats); + return IDirect3DDevice3_GetStats(&This->IDirect3DDevice3_iface, Stats); } static HRESULT WINAPI IDirect3DDeviceImpl_1_GetStats(IDirect3DDevice *iface, D3DSTATS *Stats) { - IDirect3DDeviceImpl *This = device_from_device1(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); TRACE("iface %p, stats %p.\n", iface, Stats); - return IDirect3DDevice3_GetStats((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, Stats); + return IDirect3DDevice3_GetStats(&This->IDirect3DDevice3_iface, Stats); } /***************************************************************************** @@ -659,7 +725,7 @@ IDirect3DDeviceImpl_1_CreateExecuteBuffer(IDirect3DDevice *iface, IDirect3DExecuteBuffer **ExecuteBuffer, IUnknown *UnkOuter) { - IDirect3DDeviceImpl *This = device_from_device1(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); IDirect3DExecuteBufferImpl* object; HRESULT hr; @@ -685,7 +751,7 @@ IDirect3DDeviceImpl_1_CreateExecuteBuffer(IDirect3DDevice *iface, return hr; } - *ExecuteBuffer = (IDirect3DExecuteBuffer *)object; + *ExecuteBuffer = &object->IDirect3DExecuteBuffer_iface; TRACE(" Returning IDirect3DExecuteBuffer at %p, implementation is at %p\n", *ExecuteBuffer, object); @@ -707,26 +773,23 @@ IDirect3DDeviceImpl_1_CreateExecuteBuffer(IDirect3DDevice *iface, * D3D_OK on success * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DDeviceImpl_1_Execute(IDirect3DDevice *iface, - IDirect3DExecuteBuffer *ExecuteBuffer, - IDirect3DViewport *Viewport, - DWORD Flags) +static HRESULT WINAPI IDirect3DDeviceImpl_1_Execute(IDirect3DDevice *iface, + IDirect3DExecuteBuffer *ExecuteBuffer, IDirect3DViewport *Viewport, DWORD Flags) { - IDirect3DDeviceImpl *This = device_from_device1(iface); - IDirect3DExecuteBufferImpl *Direct3DExecuteBufferImpl = (IDirect3DExecuteBufferImpl *)ExecuteBuffer; - IDirect3DViewportImpl *Direct3DViewportImpl = (IDirect3DViewportImpl *)Viewport; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); + IDirect3DExecuteBufferImpl *buffer = unsafe_impl_from_IDirect3DExecuteBuffer(ExecuteBuffer); + IDirect3DViewportImpl *Direct3DViewportImpl = unsafe_impl_from_IDirect3DViewport(Viewport); HRESULT hr; TRACE("iface %p, buffer %p, viewport %p, flags %#x.\n", iface, ExecuteBuffer, Viewport, Flags); - if(!Direct3DExecuteBufferImpl) + if(!buffer) return DDERR_INVALIDPARAMS; /* Execute... */ - EnterCriticalSection(&ddraw_cs); - hr = d3d_execute_buffer_execute(Direct3DExecuteBufferImpl, This, Direct3DViewportImpl); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); + hr = d3d_execute_buffer_execute(buffer, This, Direct3DViewportImpl); + wined3d_mutex_unlock(); return hr; } @@ -752,8 +815,8 @@ static HRESULT WINAPI IDirect3DDeviceImpl_3_AddViewport(IDirect3DDevice3 *iface, IDirect3DViewport3 *Viewport) { - IDirect3DDeviceImpl *This = device_from_device3(iface); - IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Viewport; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); + IDirect3DViewportImpl *vp = unsafe_impl_from_IDirect3DViewport3(Viewport); TRACE("iface %p, viewport %p.\n", iface, Viewport); @@ -761,11 +824,11 @@ IDirect3DDeviceImpl_3_AddViewport(IDirect3DDevice3 *iface, if(!vp) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); list_add_head(&This->viewport_list, &vp->entry); vp->active_device = This; /* Viewport must be usable for Clear() after AddViewport, so set active_device here. */ - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } @@ -773,23 +836,23 @@ IDirect3DDeviceImpl_3_AddViewport(IDirect3DDevice3 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_2_AddViewport(IDirect3DDevice2 *iface, IDirect3DViewport2 *Direct3DViewport2) { - IDirect3DDeviceImpl *This = device_from_device2(iface); - IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Direct3DViewport2; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); + IDirect3DViewportImpl *vp = unsafe_impl_from_IDirect3DViewport2(Direct3DViewport2); TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport2); - return IDirect3DDevice3_AddViewport((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, (IDirect3DViewport3 *)vp); + return IDirect3DDevice3_AddViewport(&This->IDirect3DDevice3_iface, &vp->IDirect3DViewport3_iface); } static HRESULT WINAPI IDirect3DDeviceImpl_1_AddViewport(IDirect3DDevice *iface, IDirect3DViewport *Direct3DViewport) { - IDirect3DDeviceImpl *This = device_from_device1(iface); - IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Direct3DViewport; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); + IDirect3DViewportImpl *vp = unsafe_impl_from_IDirect3DViewport(Direct3DViewport); TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport); - return IDirect3DDevice3_AddViewport((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, (IDirect3DViewport3 *)vp); + return IDirect3DDevice3_AddViewport(&This->IDirect3DDevice3_iface, &vp->IDirect3DViewport3_iface); } /***************************************************************************** @@ -810,47 +873,48 @@ static HRESULT WINAPI IDirect3DDeviceImpl_1_AddViewport(IDirect3DDevice *iface, *****************************************************************************/ static HRESULT WINAPI IDirect3DDeviceImpl_3_DeleteViewport(IDirect3DDevice3 *iface, IDirect3DViewport3 *viewport) { - IDirect3DDeviceImpl *device = device_from_device3(iface); - IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)viewport; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); + IDirect3DViewportImpl *vp = unsafe_impl_from_IDirect3DViewport3(viewport); TRACE("iface %p, viewport %p.\n", iface, viewport); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); - if (vp->active_device != device) + if (vp->active_device != This) { WARN("Viewport %p active device is %p.\n", vp, vp->active_device); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } vp->active_device = NULL; list_remove(&vp->entry); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } static HRESULT WINAPI IDirect3DDeviceImpl_2_DeleteViewport(IDirect3DDevice2 *iface, IDirect3DViewport2 *Direct3DViewport2) { - IDirect3DDeviceImpl *This = device_from_device2(iface); - IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Direct3DViewport2; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); + IDirect3DViewportImpl *vp = unsafe_impl_from_IDirect3DViewport2(Direct3DViewport2); TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport2); - return IDirect3DDevice3_DeleteViewport((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, (IDirect3DViewport3 *)vp); + return IDirect3DDevice3_DeleteViewport(&This->IDirect3DDevice3_iface, &vp->IDirect3DViewport3_iface); } static HRESULT WINAPI IDirect3DDeviceImpl_1_DeleteViewport(IDirect3DDevice *iface, IDirect3DViewport *Direct3DViewport) { - IDirect3DDeviceImpl *This = device_from_device1(iface); - IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Direct3DViewport; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); + IDirect3DViewportImpl *vp = unsafe_impl_from_IDirect3DViewport(Direct3DViewport); TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport); - return IDirect3DDevice3_DeleteViewport((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, (IDirect3DViewport3 *)vp); + return IDirect3DDevice3_DeleteViewport(&This->IDirect3DDevice3_iface, &vp->IDirect3DViewport3_iface); } /***************************************************************************** @@ -877,8 +941,9 @@ IDirect3DDeviceImpl_3_NextViewport(IDirect3DDevice3 *iface, IDirect3DViewport3 **lplpDirect3DViewport3, DWORD Flags) { - IDirect3DDeviceImpl *This = device_from_device3(iface); - IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Viewport3; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); + IDirect3DViewportImpl *vp = unsafe_impl_from_IDirect3DViewport3(Viewport3); + IDirect3DViewportImpl *next; struct list *entry; TRACE("iface %p, viewport %p, next %p, flags %#x.\n", @@ -891,7 +956,7 @@ IDirect3DDeviceImpl_3_NextViewport(IDirect3DDevice3 *iface, } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); switch (Flags) { case D3DNEXT_NEXT: @@ -909,32 +974,36 @@ IDirect3DDeviceImpl_3_NextViewport(IDirect3DDevice3 *iface, default: WARN("Invalid flags %#x.\n", Flags); *lplpDirect3DViewport3 = NULL; - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } if (entry) - *lplpDirect3DViewport3 = (IDirect3DViewport3 *)LIST_ENTRY(entry, IDirect3DViewportImpl, entry); + { + next = LIST_ENTRY(entry, IDirect3DViewportImpl, entry); + *lplpDirect3DViewport3 = &next->IDirect3DViewport3_iface; + } else *lplpDirect3DViewport3 = NULL; - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } static HRESULT WINAPI IDirect3DDeviceImpl_2_NextViewport(IDirect3DDevice2 *iface, IDirect3DViewport2 *Viewport2, IDirect3DViewport2 **lplpDirect3DViewport2, DWORD Flags) { - IDirect3DDeviceImpl *This = device_from_device2(iface); - IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Viewport2; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); + IDirect3DViewportImpl *vp = unsafe_impl_from_IDirect3DViewport2(Viewport2); IDirect3DViewport3 *res; HRESULT hr; TRACE("iface %p, viewport %p, next %p, flags %#x.\n", iface, Viewport2, lplpDirect3DViewport2, Flags); - hr = IDirect3DDevice3_NextViewport((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, - (IDirect3DViewport3 *)vp, &res, Flags); + hr = IDirect3DDevice3_NextViewport(&This->IDirect3DDevice3_iface, + &vp->IDirect3DViewport3_iface, &res, Flags); *lplpDirect3DViewport2 = (IDirect3DViewport2 *)res; return hr; } @@ -942,16 +1011,16 @@ static HRESULT WINAPI IDirect3DDeviceImpl_2_NextViewport(IDirect3DDevice2 *iface static HRESULT WINAPI IDirect3DDeviceImpl_1_NextViewport(IDirect3DDevice *iface, IDirect3DViewport *Viewport, IDirect3DViewport **lplpDirect3DViewport, DWORD Flags) { - IDirect3DDeviceImpl *This = device_from_device1(iface); - IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Viewport; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); + IDirect3DViewportImpl *vp = unsafe_impl_from_IDirect3DViewport(Viewport); IDirect3DViewport3 *res; HRESULT hr; TRACE("iface %p, viewport %p, next %p, flags %#x.\n", iface, Viewport, lplpDirect3DViewport, Flags); - hr = IDirect3DDevice3_NextViewport((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, - (IDirect3DViewport3 *)vp, &res, Flags); + hr = IDirect3DDevice3_NextViewport(&This->IDirect3DDevice3_iface, + &vp->IDirect3DViewport3_iface, &res, Flags); *lplpDirect3DViewport = (IDirect3DViewport *)res; return hr; } @@ -1040,24 +1109,22 @@ IDirect3DDeviceImpl_7_EnumTextureFormats(IDirect3DDevice7 *iface, LPD3DENUMPIXELFORMATSCALLBACK Callback, void *Arg) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); + struct wined3d_display_mode mode; HRESULT hr; - WINED3DDISPLAYMODE mode; unsigned int i; static const enum wined3d_format_id FormatList[] = { - /* 32 bit */ - WINED3DFMT_B8G8R8A8_UNORM, - WINED3DFMT_B8G8R8X8_UNORM, - /* 24 bit */ - WINED3DFMT_B8G8R8_UNORM, - /* 16 Bit */ + /* 16 bit */ + WINED3DFMT_B5G5R5X1_UNORM, WINED3DFMT_B5G5R5A1_UNORM, WINED3DFMT_B4G4R4A4_UNORM, WINED3DFMT_B5G6R5_UNORM, - WINED3DFMT_B5G5R5X1_UNORM, - /* 8 Bit */ + /* 32 bit */ + WINED3DFMT_B8G8R8X8_UNORM, + WINED3DFMT_B8G8R8A8_UNORM, + /* 8 bit */ WINED3DFMT_B2G3R3_UNORM, WINED3DFMT_P8_UINT, /* FOURCC codes */ @@ -1081,21 +1148,21 @@ IDirect3DDeviceImpl_7_EnumTextureFormats(IDirect3DDevice7 *iface, if(!Callback) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); memset(&mode, 0, sizeof(mode)); hr = wined3d_device_get_display_mode(This->ddraw->wined3d_device, 0, &mode); if (FAILED(hr)) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); WARN("Cannot get the current adapter format\n"); return hr; } for (i = 0; i < sizeof(FormatList) / sizeof(*FormatList); ++i) { - hr = wined3d_check_device_format(This->ddraw->wineD3D, WINED3DADAPTER_DEFAULT, WINED3DDEVTYPE_HAL, - mode.Format, 0, WINED3DRTYPE_TEXTURE, FormatList[i], SURFACE_OPENGL); + hr = wined3d_check_device_format(This->ddraw->wined3d, WINED3DADAPTER_DEFAULT, WINED3D_DEVICE_TYPE_HAL, + mode.format_id, 0, WINED3D_RTYPE_TEXTURE, FormatList[i], SURFACE_OPENGL); if (hr == D3D_OK) { DDPIXELFORMAT pformat; @@ -1109,7 +1176,7 @@ IDirect3DDeviceImpl_7_EnumTextureFormats(IDirect3DDevice7 *iface, if(hr != DDENUMRET_OK) { TRACE("Format enumeration cancelled by application\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } } @@ -1117,9 +1184,9 @@ IDirect3DDeviceImpl_7_EnumTextureFormats(IDirect3DDevice7 *iface, for (i = 0; i < sizeof(BumpFormatList) / sizeof(*BumpFormatList); ++i) { - hr = wined3d_check_device_format(This->ddraw->wineD3D, WINED3DADAPTER_DEFAULT, - WINED3DDEVTYPE_HAL, mode.Format, WINED3DUSAGE_QUERY_LEGACYBUMPMAP, - WINED3DRTYPE_TEXTURE, BumpFormatList[i], SURFACE_OPENGL); + hr = wined3d_check_device_format(This->ddraw->wined3d, WINED3DADAPTER_DEFAULT, + WINED3D_DEVICE_TYPE_HAL, mode.format_id, WINED3DUSAGE_QUERY_LEGACYBUMPMAP, + WINED3D_RTYPE_TEXTURE, BumpFormatList[i], SURFACE_OPENGL); if (hr == D3D_OK) { DDPIXELFORMAT pformat; @@ -1133,13 +1200,14 @@ IDirect3DDeviceImpl_7_EnumTextureFormats(IDirect3DDevice7 *iface, if(hr != DDENUMRET_OK) { TRACE("Format enumeration cancelled by application\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } } } TRACE("End of enumeration\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } @@ -1169,11 +1237,11 @@ IDirect3DDeviceImpl_7_EnumTextureFormats_FPUPreserve(IDirect3DDevice7 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_3_EnumTextureFormats(IDirect3DDevice3 *iface, LPD3DENUMPIXELFORMATSCALLBACK Callback, void *Arg) { - IDirect3DDeviceImpl *This = device_from_device3(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); TRACE("iface %p, callback %p, context %p.\n", iface, Callback, Arg); - return IDirect3DDevice7_EnumTextureFormats((IDirect3DDevice7 *)This, Callback, Arg); + return IDirect3DDevice7_EnumTextureFormats(&This->IDirect3DDevice7_iface, Callback, Arg); } /***************************************************************************** @@ -1191,24 +1259,22 @@ IDirect3DDeviceImpl_2_EnumTextureFormats(IDirect3DDevice2 *iface, LPD3DENUMTEXTUREFORMATSCALLBACK Callback, void *Arg) { - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); + struct wined3d_display_mode mode; HRESULT hr; unsigned int i; - WINED3DDISPLAYMODE mode; static const enum wined3d_format_id FormatList[] = { - /* 32 bit */ - WINED3DFMT_B8G8R8A8_UNORM, - WINED3DFMT_B8G8R8X8_UNORM, - /* 24 bit */ - WINED3DFMT_B8G8R8_UNORM, - /* 16 Bit */ + /* 16 bit */ + WINED3DFMT_B5G5R5X1_UNORM, WINED3DFMT_B5G5R5A1_UNORM, WINED3DFMT_B4G4R4A4_UNORM, WINED3DFMT_B5G6R5_UNORM, - WINED3DFMT_B5G5R5X1_UNORM, - /* 8 Bit */ + /* 32 bit */ + WINED3DFMT_B8G8R8X8_UNORM, + WINED3DFMT_B8G8R8A8_UNORM, + /* 8 bit */ WINED3DFMT_B2G3R3_UNORM, WINED3DFMT_P8_UINT, /* FOURCC codes - Not in this version*/ @@ -1219,21 +1285,21 @@ IDirect3DDeviceImpl_2_EnumTextureFormats(IDirect3DDevice2 *iface, if(!Callback) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); memset(&mode, 0, sizeof(mode)); hr = wined3d_device_get_display_mode(This->ddraw->wined3d_device, 0, &mode); if (FAILED(hr)) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); WARN("Cannot get the current adapter format\n"); return hr; } for (i = 0; i < sizeof(FormatList) / sizeof(*FormatList); ++i) { - hr = wined3d_check_device_format(This->ddraw->wineD3D, 0, WINED3DDEVTYPE_HAL, - mode.Format, 0, WINED3DRTYPE_TEXTURE, FormatList[i], SURFACE_OPENGL); + hr = wined3d_check_device_format(This->ddraw->wined3d, 0, WINED3D_DEVICE_TYPE_HAL, + mode.format_id, 0, WINED3D_RTYPE_TEXTURE, FormatList[i], SURFACE_OPENGL); if (hr == D3D_OK) { DDSURFACEDESC sdesc; @@ -1250,24 +1316,25 @@ IDirect3DDeviceImpl_2_EnumTextureFormats(IDirect3DDevice2 *iface, if(hr != DDENUMRET_OK) { TRACE("Format enumeration cancelled by application\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } } } TRACE("End of enumeration\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } static HRESULT WINAPI IDirect3DDeviceImpl_1_EnumTextureFormats(IDirect3DDevice *iface, LPD3DENUMTEXTUREFORMATSCALLBACK Callback, void *Arg) { - IDirect3DDeviceImpl *This = device_from_device1(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); TRACE("iface %p, callback %p, context %p.\n", iface, Callback, Arg); - return IDirect3DDevice2_EnumTextureFormats((IDirect3DDevice2 *)&This->IDirect3DDevice2_vtbl, Callback, Arg); + return IDirect3DDevice2_EnumTextureFormats(&This->IDirect3DDevice2_iface, Callback, Arg); } /***************************************************************************** @@ -1289,7 +1356,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_1_EnumTextureFormats(IDirect3DDevice * static HRESULT WINAPI IDirect3DDeviceImpl_1_CreateMatrix(IDirect3DDevice *iface, D3DMATRIXHANDLE *D3DMatHandle) { - IDirect3DDeviceImpl *This = device_from_device1(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); D3DMATRIX *Matrix; DWORD h; @@ -1305,14 +1372,14 @@ IDirect3DDeviceImpl_1_CreateMatrix(IDirect3DDevice *iface, D3DMATRIXHANDLE *D3DM return DDERR_OUTOFMEMORY; } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); h = ddraw_allocate_handle(&This->handle_table, Matrix, DDRAW_HANDLE_MATRIX); if (h == DDRAW_INVALID_HANDLE) { ERR("Failed to allocate a matrix handle.\n"); HeapFree(GetProcessHeap(), 0, Matrix); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_OUTOFMEMORY; } @@ -1320,7 +1387,8 @@ IDirect3DDeviceImpl_1_CreateMatrix(IDirect3DDevice *iface, D3DMATRIXHANDLE *D3DM TRACE(" returning matrix handle %d\n", *D3DMatHandle); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } @@ -1347,20 +1415,20 @@ IDirect3DDeviceImpl_1_SetMatrix(IDirect3DDevice *iface, D3DMATRIXHANDLE D3DMatHandle, D3DMATRIX *D3DMatrix) { - IDirect3DDeviceImpl *This = device_from_device1(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); D3DMATRIX *m; TRACE("iface %p, matrix_handle %#x, matrix %p.\n", iface, D3DMatHandle, D3DMatrix); if (!D3DMatrix) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); m = ddraw_get_object(&This->handle_table, D3DMatHandle - 1, DDRAW_HANDLE_MATRIX); if (!m) { WARN("Invalid matrix handle.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } @@ -1370,15 +1438,19 @@ IDirect3DDeviceImpl_1_SetMatrix(IDirect3DDevice *iface, *m = *D3DMatrix; if (D3DMatHandle == This->world) - wined3d_device_set_transform(This->wined3d_device, WINED3DTS_WORLDMATRIX(0), (WINED3DMATRIX *)D3DMatrix); + wined3d_device_set_transform(This->wined3d_device, + WINED3D_TS_WORLD_MATRIX(0), (struct wined3d_matrix *)D3DMatrix); if (D3DMatHandle == This->view) - wined3d_device_set_transform(This->wined3d_device, WINED3DTS_VIEW, (WINED3DMATRIX *)D3DMatrix); + wined3d_device_set_transform(This->wined3d_device, + WINED3D_TS_VIEW, (struct wined3d_matrix *)D3DMatrix); if (D3DMatHandle == This->proj) - wined3d_device_set_transform(This->wined3d_device, WINED3DTS_PROJECTION, (WINED3DMATRIX *)D3DMatrix); + wined3d_device_set_transform(This->wined3d_device, + WINED3D_TS_PROJECTION, (struct wined3d_matrix *)D3DMatrix); + + wined3d_mutex_unlock(); - LeaveCriticalSection(&ddraw_cs); return D3D_OK; } @@ -1403,26 +1475,27 @@ IDirect3DDeviceImpl_1_GetMatrix(IDirect3DDevice *iface, D3DMATRIXHANDLE D3DMatHandle, D3DMATRIX *D3DMatrix) { - IDirect3DDeviceImpl *This = device_from_device1(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); D3DMATRIX *m; TRACE("iface %p, matrix_handle %#x, matrix %p.\n", iface, D3DMatHandle, D3DMatrix); if (!D3DMatrix) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); m = ddraw_get_object(&This->handle_table, D3DMatHandle - 1, DDRAW_HANDLE_MATRIX); if (!m) { WARN("Invalid matrix handle.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } *D3DMatrix = *m; - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } @@ -1445,22 +1518,22 @@ static HRESULT WINAPI IDirect3DDeviceImpl_1_DeleteMatrix(IDirect3DDevice *iface, D3DMATRIXHANDLE D3DMatHandle) { - IDirect3DDeviceImpl *This = device_from_device1(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); D3DMATRIX *m; TRACE("iface %p, matrix_handle %#x.\n", iface, D3DMatHandle); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); m = ddraw_free_handle(&This->handle_table, D3DMatHandle - 1, DDRAW_HANDLE_MATRIX); if (!m) { WARN("Invalid matrix handle.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); HeapFree(GetProcessHeap(), 0, m); @@ -1484,14 +1557,15 @@ IDirect3DDeviceImpl_1_DeleteMatrix(IDirect3DDevice *iface, static HRESULT IDirect3DDeviceImpl_7_BeginScene(IDirect3DDevice7 *iface) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p.\n", iface); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_device_begin_scene(This->wined3d_device); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + if(hr == WINED3D_OK) return D3D_OK; else return D3DERR_SCENE_IN_SCENE; /* TODO: Other possible causes of failure */ } @@ -1517,23 +1591,26 @@ IDirect3DDeviceImpl_7_BeginScene_FPUPreserve(IDirect3DDevice7 *iface) static HRESULT WINAPI IDirect3DDeviceImpl_3_BeginScene(IDirect3DDevice3 *iface) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); TRACE("iface %p.\n", iface); - return IDirect3DDevice7_BeginScene((IDirect3DDevice7 *)device_from_device3(iface)); + return IDirect3DDevice7_BeginScene(&This->IDirect3DDevice7_iface); } static HRESULT WINAPI IDirect3DDeviceImpl_2_BeginScene(IDirect3DDevice2 *iface) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p.\n", iface); - return IDirect3DDevice7_BeginScene((IDirect3DDevice7 *)device_from_device2(iface)); + return IDirect3DDevice7_BeginScene(&This->IDirect3DDevice7_iface); } static HRESULT WINAPI IDirect3DDeviceImpl_1_BeginScene(IDirect3DDevice *iface) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); TRACE("iface %p.\n", iface); - return IDirect3DDevice7_BeginScene((IDirect3DDevice7 *)device_from_device1(iface)); + return IDirect3DDevice7_BeginScene(&This->IDirect3DDevice7_iface); } /***************************************************************************** @@ -1553,14 +1630,15 @@ static HRESULT WINAPI IDirect3DDeviceImpl_1_BeginScene(IDirect3DDevice *iface) static HRESULT IDirect3DDeviceImpl_7_EndScene(IDirect3DDevice7 *iface) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p.\n", iface); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_device_end_scene(This->wined3d_device); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + if(hr == WINED3D_OK) return D3D_OK; else return D3DERR_SCENE_NOT_IN_SCENE; } @@ -1586,23 +1664,26 @@ IDirect3DDeviceImpl_7_EndScene_FPUPreserve(IDirect3DDevice7 *iface) static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDeviceImpl_3_EndScene(IDirect3DDevice3 *iface) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); TRACE("iface %p.\n", iface); - return IDirect3DDevice7_EndScene((IDirect3DDevice7 *)device_from_device3(iface)); + return IDirect3DDevice7_EndScene(&This->IDirect3DDevice7_iface); } static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDeviceImpl_2_EndScene(IDirect3DDevice2 *iface) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p.\n", iface); - return IDirect3DDevice7_EndScene((IDirect3DDevice7 *)device_from_device2(iface)); + return IDirect3DDevice7_EndScene(&This->IDirect3DDevice7_iface); } static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDeviceImpl_1_EndScene(IDirect3DDevice *iface) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); TRACE("iface %p.\n", iface); - return IDirect3DDevice7_EndScene((IDirect3DDevice7 *)device_from_device1(iface)); + return IDirect3DDevice7_EndScene(&This->IDirect3DDevice7_iface); } /***************************************************************************** @@ -1623,7 +1704,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_7_GetDirect3D(IDirect3DDevice7 *iface, IDirect3D7 **Direct3D7) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); TRACE("iface %p, d3d %p.\n", iface, Direct3D7); @@ -1640,7 +1721,7 @@ IDirect3DDeviceImpl_7_GetDirect3D(IDirect3DDevice7 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_3_GetDirect3D(IDirect3DDevice3 *iface, IDirect3D3 **Direct3D3) { - IDirect3DDeviceImpl *This = device_from_device3(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); TRACE("iface %p, d3d %p.\n", iface, Direct3D3); @@ -1656,7 +1737,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_3_GetDirect3D(IDirect3DDevice3 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_2_GetDirect3D(IDirect3DDevice2 *iface, IDirect3D2 **Direct3D2) { - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, d3d %p.\n", iface, Direct3D2); @@ -1672,7 +1753,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_2_GetDirect3D(IDirect3DDevice2 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_1_GetDirect3D(IDirect3DDevice *iface, IDirect3D **Direct3D) { - IDirect3DDeviceImpl *This = device_from_device1(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice(iface); TRACE("iface %p, d3d %p.\n", iface, Direct3D); @@ -1705,23 +1786,23 @@ static HRESULT WINAPI IDirect3DDeviceImpl_3_SetCurrentViewport(IDirect3DDevice3 *iface, IDirect3DViewport3 *Direct3DViewport3) { - IDirect3DDeviceImpl *This = device_from_device3(iface); - IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Direct3DViewport3; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); + IDirect3DViewportImpl *vp = unsafe_impl_from_IDirect3DViewport3(Direct3DViewport3); TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport3); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); /* Do nothing if the specified viewport is the same as the current one */ if (This->current_viewport == vp ) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } if (vp->active_device != This) { WARN("Viewport %p active device is %p.\n", vp, vp->active_device); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } @@ -1729,8 +1810,8 @@ IDirect3DDeviceImpl_3_SetCurrentViewport(IDirect3DDevice3 *iface, if (This->current_viewport) { TRACE("ViewportImpl is at %p, interface is at %p\n", This->current_viewport, - (IDirect3DViewport3 *)This->current_viewport); - IDirect3DViewport3_Release((IDirect3DViewport3 *)This->current_viewport); + &This->current_viewport->IDirect3DViewport3_iface); + IDirect3DViewport3_Release(&This->current_viewport->IDirect3DViewport3_iface); } IDirect3DViewport3_AddRef(Direct3DViewport3); @@ -1740,20 +1821,21 @@ IDirect3DDeviceImpl_3_SetCurrentViewport(IDirect3DDevice3 *iface, /* Activate this viewport */ viewport_activate(This->current_viewport, FALSE); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } static HRESULT WINAPI IDirect3DDeviceImpl_2_SetCurrentViewport(IDirect3DDevice2 *iface, IDirect3DViewport2 *Direct3DViewport2) { - IDirect3DDeviceImpl *This = device_from_device2(iface); - IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Direct3DViewport2; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); + IDirect3DViewportImpl *vp = unsafe_impl_from_IDirect3DViewport2(Direct3DViewport2); TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport2); - return IDirect3DDevice3_SetCurrentViewport((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, - (IDirect3DViewport3 *)vp); + return IDirect3DDevice3_SetCurrentViewport(&This->IDirect3DDevice3_iface, + &vp->IDirect3DViewport3_iface); } /***************************************************************************** @@ -1775,34 +1857,35 @@ static HRESULT WINAPI IDirect3DDeviceImpl_3_GetCurrentViewport(IDirect3DDevice3 *iface, IDirect3DViewport3 **Direct3DViewport3) { - IDirect3DDeviceImpl *This = device_from_device3(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport3); if(!Direct3DViewport3) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); - *Direct3DViewport3 = (IDirect3DViewport3 *)This->current_viewport; + wined3d_mutex_lock(); + *Direct3DViewport3 = &This->current_viewport->IDirect3DViewport3_iface; /* AddRef the returned viewport */ if(*Direct3DViewport3) IDirect3DViewport3_AddRef(*Direct3DViewport3); TRACE(" returning interface %p\n", *Direct3DViewport3); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } static HRESULT WINAPI IDirect3DDeviceImpl_2_GetCurrentViewport(IDirect3DDevice2 *iface, IDirect3DViewport2 **Direct3DViewport2) { - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); HRESULT hr; TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport2); - hr = IDirect3DDevice3_GetCurrentViewport((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, + hr = IDirect3DDevice3_GetCurrentViewport(&This->IDirect3DDevice3_iface, (IDirect3DViewport3 **)Direct3DViewport2); if(hr != D3D_OK) return hr; return D3D_OK; @@ -1826,40 +1909,47 @@ static HRESULT WINAPI IDirect3DDeviceImpl_2_GetCurrentViewport(IDirect3DDevice2 * D3D_OK on success, for details see IWineD3DDevice::SetRenderTarget * *****************************************************************************/ +static HRESULT d3d_device_set_render_target(IDirect3DDeviceImpl *This, IDirectDrawSurfaceImpl *Target) +{ + HRESULT hr; + + wined3d_mutex_lock(); + + if(This->target == Target) + { + TRACE("No-op SetRenderTarget operation, not doing anything\n"); + wined3d_mutex_unlock(); + return D3D_OK; + } + This->target = Target; + hr = wined3d_device_set_render_target(This->wined3d_device, 0, + Target ? Target->wined3d_surface : NULL, FALSE); + if(hr != D3D_OK) + { + wined3d_mutex_unlock(); + return hr; + } + IDirect3DDeviceImpl_UpdateDepthStencil(This); + + wined3d_mutex_unlock(); + + return D3D_OK; +} + static HRESULT IDirect3DDeviceImpl_7_SetRenderTarget(IDirect3DDevice7 *iface, IDirectDrawSurface7 *NewTarget, DWORD Flags) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; - IDirectDrawSurfaceImpl *Target = (IDirectDrawSurfaceImpl *)NewTarget; - HRESULT hr; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); + IDirectDrawSurfaceImpl *Target = unsafe_impl_from_IDirectDrawSurface7(NewTarget); TRACE("iface %p, target %p, flags %#x.\n", iface, NewTarget, Flags); - - EnterCriticalSection(&ddraw_cs); /* Flags: Not used */ - if(This->target == Target) - { - TRACE("No-op SetRenderTarget operation, not doing anything\n"); - LeaveCriticalSection(&ddraw_cs); - return D3D_OK; - } - - hr = wined3d_device_set_render_target(This->wined3d_device, 0, - Target ? Target->wined3d_surface : NULL, FALSE); - if(hr != D3D_OK) - { - LeaveCriticalSection(&ddraw_cs); - return hr; - } IDirectDrawSurface7_AddRef(NewTarget); - IDirectDrawSurface7_Release((IDirectDrawSurface7 *)This->target); - This->target = Target; - IDirect3DDeviceImpl_UpdateDepthStencil(This); - LeaveCriticalSection(&ddraw_cs); - return D3D_OK; + IDirectDrawSurface7_Release(&This->target->IDirectDrawSurface7_iface); + return d3d_device_set_render_target(This, Target); } static HRESULT WINAPI @@ -1888,23 +1978,27 @@ IDirect3DDeviceImpl_7_SetRenderTarget_FPUPreserve(IDirect3DDevice7 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_3_SetRenderTarget(IDirect3DDevice3 *iface, IDirectDrawSurface4 *NewRenderTarget, DWORD Flags) { - IDirect3DDeviceImpl *This = device_from_device3(iface); - IDirectDrawSurfaceImpl *Target = (IDirectDrawSurfaceImpl *)NewRenderTarget; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); + IDirectDrawSurfaceImpl *Target = unsafe_impl_from_IDirectDrawSurface4(NewRenderTarget); TRACE("iface %p, target %p, flags %#x.\n", iface, NewRenderTarget, Flags); - return IDirect3DDevice7_SetRenderTarget((IDirect3DDevice7 *)This, (IDirectDrawSurface7 *)Target, Flags); + IDirectDrawSurface4_AddRef(NewRenderTarget); + IDirectDrawSurface4_Release(&This->target->IDirectDrawSurface4_iface); + return d3d_device_set_render_target(This, Target); } static HRESULT WINAPI IDirect3DDeviceImpl_2_SetRenderTarget(IDirect3DDevice2 *iface, IDirectDrawSurface *NewRenderTarget, DWORD Flags) { - IDirect3DDeviceImpl *This = device_from_device2(iface); - IDirectDrawSurfaceImpl *Target = (IDirectDrawSurfaceImpl *)NewRenderTarget; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); + IDirectDrawSurfaceImpl *Target = unsafe_impl_from_IDirectDrawSurface(NewRenderTarget); TRACE("iface %p, target %p, flags %#x.\n", iface, NewRenderTarget, Flags); - return IDirect3DDevice7_SetRenderTarget((IDirect3DDevice7 *)This, (IDirectDrawSurface7 *)Target, Flags); + IDirectDrawSurface_AddRef(NewRenderTarget); + IDirectDrawSurface_Release(&This->target->IDirectDrawSurface_iface); + return d3d_device_set_render_target(This, Target); } /***************************************************************************** @@ -1928,46 +2022,62 @@ static HRESULT WINAPI IDirect3DDeviceImpl_7_GetRenderTarget(IDirect3DDevice7 *iface, IDirectDrawSurface7 **RenderTarget) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); TRACE("iface %p, target %p.\n", iface, RenderTarget); if(!RenderTarget) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); - *RenderTarget = (IDirectDrawSurface7 *)This->target; + wined3d_mutex_lock(); + *RenderTarget = &This->target->IDirectDrawSurface7_iface; IDirectDrawSurface7_AddRef(*RenderTarget); + wined3d_mutex_unlock(); - LeaveCriticalSection(&ddraw_cs); return D3D_OK; } static HRESULT WINAPI IDirect3DDeviceImpl_3_GetRenderTarget(IDirect3DDevice3 *iface, IDirectDrawSurface4 **RenderTarget) { - IDirect3DDeviceImpl *This = device_from_device3(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); + IDirectDrawSurface7 *RenderTarget7; + IDirectDrawSurfaceImpl *RenderTargetImpl; HRESULT hr; TRACE("iface %p, target %p.\n", iface, RenderTarget); - hr = IDirect3DDevice7_GetRenderTarget((IDirect3DDevice7 *)This, (IDirectDrawSurface7 **)RenderTarget); + if(!RenderTarget) + return DDERR_INVALIDPARAMS; + + hr = IDirect3DDevice7_GetRenderTarget(&This->IDirect3DDevice7_iface, &RenderTarget7); if(hr != D3D_OK) return hr; + RenderTargetImpl = impl_from_IDirectDrawSurface7(RenderTarget7); + *RenderTarget = &RenderTargetImpl->IDirectDrawSurface4_iface; + IDirectDrawSurface4_AddRef(*RenderTarget); + IDirectDrawSurface7_Release(RenderTarget7); return D3D_OK; } static HRESULT WINAPI IDirect3DDeviceImpl_2_GetRenderTarget(IDirect3DDevice2 *iface, IDirectDrawSurface **RenderTarget) { - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); + IDirectDrawSurface7 *RenderTarget7; + IDirectDrawSurfaceImpl *RenderTargetImpl; HRESULT hr; TRACE("iface %p, target %p.\n", iface, RenderTarget); - hr = IDirect3DDevice7_GetRenderTarget((IDirect3DDevice7 *)This, (IDirectDrawSurface7 **)RenderTarget); + if(!RenderTarget) + return DDERR_INVALIDPARAMS; + + hr = IDirect3DDevice7_GetRenderTarget(&This->IDirect3DDevice7_iface, &RenderTarget7); if(hr != D3D_OK) return hr; - *RenderTarget = *RenderTarget ? - (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)*RenderTarget)->IDirectDrawSurface3_vtbl : NULL; + RenderTargetImpl = impl_from_IDirectDrawSurface7(RenderTarget7); + *RenderTarget = &RenderTargetImpl->IDirectDrawSurface_iface; + IDirectDrawSurface_AddRef(*RenderTarget); + IDirectDrawSurface7_Release(RenderTarget7); return D3D_OK; } @@ -1995,18 +2105,18 @@ IDirect3DDeviceImpl_3_Begin(IDirect3DDevice3 *iface, DWORD VertexTypeDesc, DWORD Flags) { - IDirect3DDeviceImpl *This = device_from_device3(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); TRACE("iface %p, primitive_type %#x, FVF %#x, flags %#x.\n", iface, PrimitiveType, VertexTypeDesc, Flags); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); This->primitive_type = PrimitiveType; This->vertex_type = VertexTypeDesc; This->render_flags = Flags; This->vertex_size = get_flexible_vertex_size(This->vertex_type); This->nb_vertices = 0; - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } @@ -2015,7 +2125,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_2_Begin(IDirect3DDevice2 *iface, D3DPR D3DVERTEXTYPE dwVertexTypeDesc, DWORD dwFlags) { DWORD FVF; - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, primitive_type %#x, vertex_type %#x, flags %#x.\n", iface, d3dpt, dwVertexTypeDesc, dwFlags); @@ -2030,7 +2140,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_2_Begin(IDirect3DDevice2 *iface, D3DPR return DDERR_INVALIDPARAMS; /* Should never happen */ }; - return IDirect3DDevice3_Begin((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, d3dpt, FVF, dwFlags); + return IDirect3DDevice3_Begin(&This->IDirect3DDevice3_iface, d3dpt, FVF, dwFlags); } /***************************************************************************** @@ -2072,7 +2182,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_2_BeginIndexed(IDirect3DDevice2 *iface void *lpvVertices, DWORD dwNumVertices, DWORD dwFlags) { DWORD FVF; - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, primitive_type %#x, vertex_type %#x, vertices %p, vertex_count %u, flags %#x stub!\n", iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwNumVertices, dwFlags); @@ -2087,7 +2197,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_2_BeginIndexed(IDirect3DDevice2 *iface return DDERR_INVALIDPARAMS; /* Should never happen */ }; - return IDirect3DDevice3_BeginIndexed((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, + return IDirect3DDevice3_BeginIndexed(&This->IDirect3DDevice3_iface, d3dptPrimitiveType, FVF, lpvVertices, dwNumVertices, dwFlags); } @@ -2112,14 +2222,14 @@ static HRESULT WINAPI IDirect3DDeviceImpl_3_Vertex(IDirect3DDevice3 *iface, void *Vertex) { - IDirect3DDeviceImpl *This = device_from_device3(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); TRACE("iface %p, vertex %p.\n", iface, Vertex); if(!Vertex) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if ((This->nb_vertices+1)*This->vertex_size > This->buffer_size) { BYTE *old_buffer; @@ -2134,18 +2244,18 @@ IDirect3DDeviceImpl_3_Vertex(IDirect3DDevice3 *iface, } CopyMemory(This->vertex_buffer + This->nb_vertices++ * This->vertex_size, Vertex, This->vertex_size); + wined3d_mutex_unlock(); - LeaveCriticalSection(&ddraw_cs); return D3D_OK; } static HRESULT WINAPI IDirect3DDeviceImpl_2_Vertex(IDirect3DDevice2 *iface, void *lpVertexType) { - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, vertex %p.\n", iface, lpVertexType); - return IDirect3DDevice3_Vertex((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, lpVertexType); + return IDirect3DDevice3_Vertex(&This->IDirect3DDevice3_iface, lpVertexType); } /***************************************************************************** @@ -2172,11 +2282,11 @@ IDirect3DDeviceImpl_3_Index(IDirect3DDevice3 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_2_Index(IDirect3DDevice2 *iface, WORD wVertexIndex) { - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, index %#x.\n", iface, wVertexIndex); - return IDirect3DDevice3_Index((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, wVertexIndex); + return IDirect3DDevice3_Index(&This->IDirect3DDevice3_iface, wVertexIndex); } /***************************************************************************** @@ -2201,21 +2311,21 @@ static HRESULT WINAPI IDirect3DDeviceImpl_3_End(IDirect3DDevice3 *iface, DWORD Flags) { - IDirect3DDeviceImpl *This = device_from_device3(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); TRACE("iface %p, flags %#x.\n", iface, Flags); - return IDirect3DDevice7_DrawPrimitive((IDirect3DDevice7 *)This, This->primitive_type, + return IDirect3DDevice7_DrawPrimitive(&This->IDirect3DDevice7_iface, This->primitive_type, This->vertex_type, This->vertex_buffer, This->nb_vertices, This->render_flags); } static HRESULT WINAPI IDirect3DDeviceImpl_2_End(IDirect3DDevice2 *iface, DWORD dwFlags) { - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, flags %#x.\n", iface, dwFlags); - return IDirect3DDevice3_End((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, dwFlags); + return IDirect3DDevice3_End(&This->IDirect3DDevice3_iface, dwFlags); } /***************************************************************************** @@ -2235,14 +2345,10 @@ static HRESULT WINAPI IDirect3DDeviceImpl_2_End(IDirect3DDevice2 *iface, DWORD d * DDERR_INVALIDPARAMS if Value == NULL * *****************************************************************************/ -static const float zbias_factor = -0.000005f; - -static HRESULT -IDirect3DDeviceImpl_7_GetRenderState(IDirect3DDevice7 *iface, - D3DRENDERSTATETYPE RenderStateType, - DWORD *Value) +static HRESULT IDirect3DDeviceImpl_7_GetRenderState(IDirect3DDevice7 *iface, + D3DRENDERSTATETYPE RenderStateType, DWORD *Value) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p, state %#x, value %p.\n", iface, RenderStateType, Value); @@ -2250,21 +2356,21 @@ IDirect3DDeviceImpl_7_GetRenderState(IDirect3DDevice7 *iface, if(!Value) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); switch(RenderStateType) { case D3DRENDERSTATE_TEXTUREMAG: { - WINED3DTEXTUREFILTERTYPE tex_mag; + enum wined3d_texture_filter_type tex_mag; - hr = wined3d_device_get_sampler_state(This->wined3d_device, 0, WINED3DSAMP_MAGFILTER, &tex_mag); + hr = wined3d_device_get_sampler_state(This->wined3d_device, 0, WINED3D_SAMP_MAG_FILTER, &tex_mag); switch (tex_mag) { - case WINED3DTEXF_POINT: + case WINED3D_TEXF_POINT: *Value = D3DFILTER_NEAREST; break; - case WINED3DTEXF_LINEAR: + case WINED3D_TEXF_LINEAR: *Value = D3DFILTER_LINEAR; break; default: @@ -2276,31 +2382,31 @@ IDirect3DDeviceImpl_7_GetRenderState(IDirect3DDevice7 *iface, case D3DRENDERSTATE_TEXTUREMIN: { - WINED3DTEXTUREFILTERTYPE tex_min; - WINED3DTEXTUREFILTERTYPE tex_mip; + enum wined3d_texture_filter_type tex_min; + enum wined3d_texture_filter_type tex_mip; hr = wined3d_device_get_sampler_state(This->wined3d_device, - 0, WINED3DSAMP_MINFILTER, &tex_min); + 0, WINED3D_SAMP_MIN_FILTER, &tex_min); if (FAILED(hr)) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } hr = wined3d_device_get_sampler_state(This->wined3d_device, - 0, WINED3DSAMP_MIPFILTER, &tex_mip); + 0, WINED3D_SAMP_MIP_FILTER, &tex_mip); switch (tex_min) { - case WINED3DTEXF_POINT: + case WINED3D_TEXF_POINT: switch (tex_mip) { - case WINED3DTEXF_NONE: + case WINED3D_TEXF_NONE: *Value = D3DFILTER_NEAREST; break; - case WINED3DTEXF_POINT: + case WINED3D_TEXF_POINT: *Value = D3DFILTER_MIPNEAREST; break; - case WINED3DTEXF_LINEAR: + case WINED3D_TEXF_LINEAR: *Value = D3DFILTER_LINEARMIPNEAREST; break; default: @@ -2309,16 +2415,16 @@ IDirect3DDeviceImpl_7_GetRenderState(IDirect3DDevice7 *iface, break; } break; - case WINED3DTEXF_LINEAR: + case WINED3D_TEXF_LINEAR: switch (tex_mip) { - case WINED3DTEXF_NONE: + case WINED3D_TEXF_NONE: *Value = D3DFILTER_LINEAR; break; - case WINED3DTEXF_POINT: + case WINED3D_TEXF_POINT: *Value = D3DFILTER_MIPLINEAR; break; - case WINED3DTEXF_LINEAR: + case WINED3D_TEXF_LINEAR: *Value = D3DFILTER_LINEARMIPLINEAR; break; default: @@ -2338,11 +2444,11 @@ IDirect3DDeviceImpl_7_GetRenderState(IDirect3DDevice7 *iface, case D3DRENDERSTATE_TEXTUREADDRESS: case D3DRENDERSTATE_TEXTUREADDRESSU: hr = wined3d_device_get_sampler_state(This->wined3d_device, - 0, WINED3DSAMP_ADDRESSU, Value); + 0, WINED3D_SAMP_ADDRESS_U, Value); break; case D3DRENDERSTATE_TEXTUREADDRESSV: hr = wined3d_device_get_sampler_state(This->wined3d_device, - 0, WINED3DSAMP_ADDRESSV, Value); + 0, WINED3D_SAMP_ADDRESS_V, Value); break; case D3DRENDERSTATE_BORDERCOLOR: @@ -2357,18 +2463,8 @@ IDirect3DDeviceImpl_7_GetRenderState(IDirect3DDevice7 *iface, break; case D3DRENDERSTATE_ZBIAS: - { - union - { - DWORD d; - float f; - } wined3d_value; - - hr = wined3d_device_get_render_state(This->wined3d_device, WINED3DRS_DEPTHBIAS, &wined3d_value.d); - if (SUCCEEDED(hr)) - *Value = wined3d_value.f / zbias_factor; + hr = wined3d_device_get_render_state(This->wined3d_device, WINED3D_RS_DEPTHBIAS, Value); break; - } default: if (RenderStateType >= D3DRENDERSTATE_STIPPLEPATTERN00 @@ -2381,7 +2477,8 @@ IDirect3DDeviceImpl_7_GetRenderState(IDirect3DDevice7 *iface, } hr = wined3d_device_get_render_state(This->wined3d_device, RenderStateType, Value); } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -2413,7 +2510,7 @@ IDirect3DDeviceImpl_3_GetRenderState(IDirect3DDevice3 *iface, D3DRENDERSTATETYPE dwRenderStateType, DWORD *lpdwRenderState) { - IDirect3DDeviceImpl *This = device_from_device3(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); HRESULT hr; TRACE("iface %p, state %#x, value %p.\n", iface, dwRenderStateType, lpdwRenderState); @@ -2427,8 +2524,7 @@ IDirect3DDeviceImpl_3_GetRenderState(IDirect3DDevice3 *iface, struct wined3d_texture *tex = NULL; *lpdwRenderState = 0; - EnterCriticalSection(&ddraw_cs); - + wined3d_mutex_lock(); hr = wined3d_device_get_texture(This->wined3d_device, 0, &tex); if (SUCCEEDED(hr) && tex) { @@ -2438,8 +2534,7 @@ IDirect3DDeviceImpl_3_GetRenderState(IDirect3DDevice3 *iface, if (parent) *lpdwRenderState = parent->Handle; wined3d_texture_decref(tex); } - - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } @@ -2451,32 +2546,29 @@ IDirect3DDeviceImpl_3_GetRenderState(IDirect3DDevice3 *iface, DWORD colorop, colorarg1, colorarg2; DWORD alphaop, alphaarg1, alphaarg2; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); This->legacyTextureBlending = TRUE; - wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3DTSS_COLOROP, &colorop); - wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3DTSS_COLORARG1, &colorarg1); - wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3DTSS_COLORARG2, &colorarg2); - wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3DTSS_ALPHAOP, &alphaop); - wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3DTSS_ALPHAARG1, &alphaarg1); - wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3DTSS_ALPHAARG2, &alphaarg2); + wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3D_TSS_COLOR_OP, &colorop); + wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3D_TSS_COLOR_ARG1, &colorarg1); + wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3D_TSS_COLOR_ARG2, &colorarg2); + wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3D_TSS_ALPHA_OP, &alphaop); + wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3D_TSS_ALPHA_ARG1, &alphaarg1); + wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3D_TSS_ALPHA_ARG2, &alphaarg2); - if (colorop == WINED3DTOP_SELECTARG1 && colorarg1 == WINED3DTA_TEXTURE && - alphaop == WINED3DTOP_SELECTARG1 && alphaarg1 == WINED3DTA_TEXTURE) - { + if (colorop == WINED3D_TOP_SELECT_ARG1 && colorarg1 == WINED3DTA_TEXTURE + && alphaop == WINED3D_TOP_SELECT_ARG1 && alphaarg1 == WINED3DTA_TEXTURE) *lpdwRenderState = D3DTBLEND_DECAL; - } - else if (colorop == WINED3DTOP_SELECTARG1 && colorarg1 == WINED3DTA_TEXTURE && - alphaop == WINED3DTOP_MODULATE && alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT) - { + else if (colorop == WINED3D_TOP_SELECT_ARG1 && colorarg1 == WINED3DTA_TEXTURE + && alphaop == WINED3D_TOP_MODULATE + && alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT) *lpdwRenderState = D3DTBLEND_DECALALPHA; - } - else if (colorop == WINED3DTOP_MODULATE && colorarg1 == WINED3DTA_TEXTURE && colorarg2 == WINED3DTA_CURRENT && - alphaop == WINED3DTOP_MODULATE && alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT) - { + else if (colorop == WINED3D_TOP_MODULATE + && colorarg1 == WINED3DTA_TEXTURE && colorarg2 == WINED3DTA_CURRENT + && alphaop == WINED3D_TOP_MODULATE + && alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT) *lpdwRenderState = D3DTBLEND_MODULATEALPHA; - } else { struct wined3d_texture *tex = NULL; @@ -2503,34 +2595,33 @@ IDirect3DDeviceImpl_3_GetRenderState(IDirect3DDevice3 *iface, wined3d_texture_decref(tex); } - if (!(colorop == WINED3DTOP_MODULATE && colorarg1 == WINED3DTA_TEXTURE && colorarg2 == WINED3DTA_CURRENT && - alphaop == (tex_alpha ? WINED3DTOP_SELECTARG1 : WINED3DTOP_SELECTARG2) && - alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT)) - { - ERR("Unexpected texture stage state setup, returning D3DTBLEND_MODULATE - likely erroneous\n"); - } + if (!(colorop == WINED3D_TOP_MODULATE + && colorarg1 == WINED3DTA_TEXTURE && colorarg2 == WINED3DTA_CURRENT + && alphaop == (tex_alpha ? WINED3D_TOP_SELECT_ARG1 : WINED3D_TOP_SELECT_ARG2) + && alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT)) + ERR("Unexpected texture stage state setup, returning D3DTBLEND_MODULATE - likely erroneous.\n"); *lpdwRenderState = D3DTBLEND_MODULATE; } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } default: - return IDirect3DDevice7_GetRenderState((IDirect3DDevice7 *)This, dwRenderStateType, lpdwRenderState); + return IDirect3DDevice7_GetRenderState(&This->IDirect3DDevice7_iface, dwRenderStateType, lpdwRenderState); } } static HRESULT WINAPI IDirect3DDeviceImpl_2_GetRenderState(IDirect3DDevice2 *iface, D3DRENDERSTATETYPE dwRenderStateType, DWORD *lpdwRenderState) { - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, state %#x, value %p.\n", iface, dwRenderStateType, lpdwRenderState); - return IDirect3DDevice3_GetRenderState((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, + return IDirect3DDevice3_GetRenderState(&This->IDirect3DDevice3_iface, dwRenderStateType, lpdwRenderState); } @@ -2556,12 +2647,12 @@ IDirect3DDeviceImpl_7_SetRenderState(IDirect3DDevice7 *iface, D3DRENDERSTATETYPE RenderStateType, DWORD Value) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p, state %#x, value %#x.\n", iface, RenderStateType, Value); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); /* Some render states need special care */ switch(RenderStateType) { @@ -2580,87 +2671,87 @@ IDirect3DDeviceImpl_7_SetRenderState(IDirect3DDevice7 *iface, */ case D3DRENDERSTATE_TEXTUREMAG: { - WINED3DTEXTUREFILTERTYPE tex_mag; + enum wined3d_texture_filter_type tex_mag; switch (Value) { case D3DFILTER_NEAREST: case D3DFILTER_MIPNEAREST: case D3DFILTER_LINEARMIPNEAREST: - tex_mag = WINED3DTEXF_POINT; + tex_mag = WINED3D_TEXF_POINT; break; case D3DFILTER_LINEAR: case D3DFILTER_MIPLINEAR: case D3DFILTER_LINEARMIPLINEAR: - tex_mag = WINED3DTEXF_LINEAR; + tex_mag = WINED3D_TEXF_LINEAR; break; default: - tex_mag = WINED3DTEXF_POINT; + tex_mag = WINED3D_TEXF_POINT; ERR("Unhandled texture mag %d !\n",Value); break; } - hr = wined3d_device_set_sampler_state(This->wined3d_device, 0, WINED3DSAMP_MAGFILTER, tex_mag); + hr = wined3d_device_set_sampler_state(This->wined3d_device, 0, WINED3D_SAMP_MAG_FILTER, tex_mag); break; } case D3DRENDERSTATE_TEXTUREMIN: { - WINED3DTEXTUREFILTERTYPE tex_min; - WINED3DTEXTUREFILTERTYPE tex_mip; + enum wined3d_texture_filter_type tex_min; + enum wined3d_texture_filter_type tex_mip; - switch ((D3DTEXTUREFILTER) Value) + switch ((D3DTEXTUREFILTER)Value) { case D3DFILTER_NEAREST: - tex_min = WINED3DTEXF_POINT; - tex_mip = WINED3DTEXF_NONE; + tex_min = WINED3D_TEXF_POINT; + tex_mip = WINED3D_TEXF_NONE; break; case D3DFILTER_LINEAR: - tex_min = WINED3DTEXF_LINEAR; - tex_mip = WINED3DTEXF_NONE; + tex_min = WINED3D_TEXF_LINEAR; + tex_mip = WINED3D_TEXF_NONE; break; case D3DFILTER_MIPNEAREST: - tex_min = WINED3DTEXF_POINT; - tex_mip = WINED3DTEXF_POINT; + tex_min = WINED3D_TEXF_POINT; + tex_mip = WINED3D_TEXF_POINT; break; case D3DFILTER_MIPLINEAR: - tex_min = WINED3DTEXF_LINEAR; - tex_mip = WINED3DTEXF_POINT; + tex_min = WINED3D_TEXF_LINEAR; + tex_mip = WINED3D_TEXF_POINT; break; case D3DFILTER_LINEARMIPNEAREST: - tex_min = WINED3DTEXF_POINT; - tex_mip = WINED3DTEXF_LINEAR; + tex_min = WINED3D_TEXF_POINT; + tex_mip = WINED3D_TEXF_LINEAR; break; case D3DFILTER_LINEARMIPLINEAR: - tex_min = WINED3DTEXF_LINEAR; - tex_mip = WINED3DTEXF_LINEAR; + tex_min = WINED3D_TEXF_LINEAR; + tex_mip = WINED3D_TEXF_LINEAR; break; default: ERR("Unhandled texture min %d !\n",Value); - tex_min = WINED3DTEXF_POINT; - tex_mip = WINED3DTEXF_NONE; + tex_min = WINED3D_TEXF_POINT; + tex_mip = WINED3D_TEXF_NONE; break; } wined3d_device_set_sampler_state(This->wined3d_device, - 0, WINED3DSAMP_MIPFILTER, tex_mip); + 0, WINED3D_SAMP_MIP_FILTER, tex_mip); hr = wined3d_device_set_sampler_state(This->wined3d_device, - 0, WINED3DSAMP_MINFILTER, tex_min); + 0, WINED3D_SAMP_MIN_FILTER, tex_min); break; } case D3DRENDERSTATE_TEXTUREADDRESS: wined3d_device_set_sampler_state(This->wined3d_device, - 0, WINED3DSAMP_ADDRESSV, Value); + 0, WINED3D_SAMP_ADDRESS_V, Value); /* Drop through */ case D3DRENDERSTATE_TEXTUREADDRESSU: hr = wined3d_device_set_sampler_state(This->wined3d_device, - 0, WINED3DSAMP_ADDRESSU, Value); + 0, WINED3D_SAMP_ADDRESS_U, Value); break; case D3DRENDERSTATE_TEXTUREADDRESSV: hr = wined3d_device_set_sampler_state(This->wined3d_device, - 0, WINED3DSAMP_ADDRESSV, Value); + 0, WINED3D_SAMP_ADDRESS_V, Value); break; case D3DRENDERSTATE_BORDERCOLOR: @@ -2677,16 +2768,8 @@ IDirect3DDeviceImpl_7_SetRenderState(IDirect3DDevice7 *iface, break; case D3DRENDERSTATE_ZBIAS: - { - union - { - DWORD d; - float f; - } wined3d_value; - wined3d_value.f = Value * zbias_factor; - hr = wined3d_device_set_render_state(This->wined3d_device, WINED3DRS_DEPTHBIAS, wined3d_value.d); + hr = wined3d_device_set_render_state(This->wined3d_device, WINED3D_RS_DEPTHBIAS, Value); break; - } default: if (RenderStateType >= D3DRENDERSTATE_STIPPLEPATTERN00 @@ -2701,7 +2784,8 @@ IDirect3DDeviceImpl_7_SetRenderState(IDirect3DDevice7 *iface, hr = wined3d_device_set_render_state(This->wined3d_device, RenderStateType, Value); break; } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -2753,11 +2837,11 @@ IDirect3DDeviceImpl_3_SetRenderState(IDirect3DDevice3 *iface, unless some broken game will be found that cares. */ HRESULT hr; - IDirect3DDeviceImpl *This = device_from_device3(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); TRACE("iface %p, state %#x, value %#x.\n", iface, RenderStateType, Value); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); switch(RenderStateType) { @@ -2779,7 +2863,7 @@ IDirect3DDeviceImpl_3_SetRenderState(IDirect3DDevice3 *iface, break; } - hr = IDirect3DDevice3_SetTexture(iface, 0, (IDirect3DTexture2 *)&surf->IDirect3DTexture2_vtbl); + hr = IDirect3DDevice3_SetTexture(iface, 0, &surf->IDirect3DTexture2_iface); break; } @@ -2816,74 +2900,74 @@ IDirect3DDeviceImpl_3_SetRenderState(IDirect3DDevice3 *iface, if (tex_alpha) wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1); + 0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG1); else wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG2); + 0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG2); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE); + 0, WINED3D_TSS_ALPHA_ARG1, WINED3DTA_TEXTURE); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_ALPHAARG2, WINED3DTA_CURRENT); + 0, WINED3D_TSS_ALPHA_ARG2, WINED3DTA_CURRENT); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE); + 0, WINED3D_TSS_COLOR_ARG1, WINED3DTA_TEXTURE); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_COLORARG2, WINED3DTA_CURRENT); + 0, WINED3D_TSS_COLOR_ARG2, WINED3DTA_CURRENT); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_COLOROP, WINED3DTOP_MODULATE); + 0, WINED3D_TSS_COLOR_OP, WINED3D_TOP_MODULATE); break; } case D3DTBLEND_ADD: wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_COLOROP, WINED3DTOP_ADD); + 0, WINED3D_TSS_COLOR_OP, WINED3D_TOP_ADD); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE); + 0, WINED3D_TSS_COLOR_ARG1, WINED3DTA_TEXTURE); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_COLORARG2, WINED3DTA_CURRENT); + 0, WINED3D_TSS_COLOR_ARG2, WINED3DTA_CURRENT); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG2); + 0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG2); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_ALPHAARG2, WINED3DTA_CURRENT); + 0, WINED3D_TSS_ALPHA_ARG2, WINED3DTA_CURRENT); break; case D3DTBLEND_MODULATEALPHA: wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE); + 0, WINED3D_TSS_COLOR_ARG1, WINED3DTA_TEXTURE); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE); + 0, WINED3D_TSS_ALPHA_ARG1, WINED3DTA_TEXTURE); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_COLORARG2, WINED3DTA_CURRENT); + 0, WINED3D_TSS_COLOR_ARG2, WINED3DTA_CURRENT); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_ALPHAARG2, WINED3DTA_CURRENT); + 0, WINED3D_TSS_ALPHA_ARG2, WINED3DTA_CURRENT); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_COLOROP, WINED3DTOP_MODULATE); + 0, WINED3D_TSS_COLOR_OP, WINED3D_TOP_MODULATE); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_ALPHAOP, WINED3DTOP_MODULATE); + 0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_MODULATE); break; case D3DTBLEND_COPY: case D3DTBLEND_DECAL: wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE); + 0, WINED3D_TSS_COLOR_ARG1, WINED3DTA_TEXTURE); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE); + 0, WINED3D_TSS_ALPHA_ARG1, WINED3DTA_TEXTURE); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_COLOROP, WINED3DTOP_SELECTARG1); + 0, WINED3D_TSS_COLOR_OP, WINED3D_TOP_SELECT_ARG1); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1); + 0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG1); break; case D3DTBLEND_DECALALPHA: wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_COLOROP, WINED3DTOP_BLENDTEXTUREALPHA); + 0, WINED3D_TSS_COLOR_OP, WINED3D_TOP_BLEND_TEXTURE_ALPHA); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE); + 0, WINED3D_TSS_COLOR_ARG1, WINED3DTA_TEXTURE); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_COLORARG2, WINED3DTA_CURRENT); + 0, WINED3D_TSS_COLOR_ARG2, WINED3DTA_CURRENT); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG2); + 0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG2); wined3d_device_set_texture_stage_state(This->wined3d_device, - 0, WINED3DTSS_ALPHAARG2, WINED3DTA_CURRENT); + 0, WINED3D_TSS_ALPHA_ARG2, WINED3DTA_CURRENT); break; default: @@ -2895,11 +2979,10 @@ IDirect3DDeviceImpl_3_SetRenderState(IDirect3DDevice3 *iface, } default: - hr = IDirect3DDevice7_SetRenderState((IDirect3DDevice7 *)This, RenderStateType, Value); + hr = IDirect3DDevice7_SetRenderState(&This->IDirect3DDevice7_iface, RenderStateType, Value); break; } - - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } @@ -2907,11 +2990,11 @@ IDirect3DDeviceImpl_3_SetRenderState(IDirect3DDevice3 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_2_SetRenderState(IDirect3DDevice2 *iface, D3DRENDERSTATETYPE RenderStateType, DWORD Value) { - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, state %#x, value %#x.\n", iface, RenderStateType, Value); - return IDirect3DDevice3_SetRenderState((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, RenderStateType, Value); + return IDirect3DDevice3_SetRenderState(&This->IDirect3DDevice3_iface, RenderStateType, Value); } /***************************************************************************** @@ -2937,7 +3020,7 @@ IDirect3DDeviceImpl_3_SetLightState(IDirect3DDevice3 *iface, D3DLIGHTSTATETYPE LightStateType, DWORD Value) { - IDirect3DDeviceImpl *This = device_from_device3(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); HRESULT hr; TRACE("iface %p, state %#x, value %#x.\n", iface, LightStateType, Value); @@ -2948,14 +3031,14 @@ IDirect3DDeviceImpl_3_SetLightState(IDirect3DDevice3 *iface, return DDERR_INVALIDPARAMS; } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if (LightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */) { IDirect3DMaterialImpl *m = ddraw_get_object(&This->handle_table, Value - 1, DDRAW_HANDLE_MATERIAL); if (!m) { WARN("Invalid material handle.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } @@ -2977,7 +3060,7 @@ IDirect3DDeviceImpl_3_SetLightState(IDirect3DDevice3 *iface, break; default: ERR("Unknown color model!\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } } @@ -3006,27 +3089,27 @@ IDirect3DDeviceImpl_3_SetLightState(IDirect3DDevice3 *iface, break; default: ERR("Unknown D3DLIGHTSTATETYPE %d.\n", LightStateType); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } - hr = IDirect3DDevice7_SetRenderState((IDirect3DDevice7 *)This, rs, Value); - LeaveCriticalSection(&ddraw_cs); + hr = IDirect3DDevice7_SetRenderState(&This->IDirect3DDevice7_iface, rs, Value); + wined3d_mutex_unlock(); return hr; } + wined3d_mutex_unlock(); - LeaveCriticalSection(&ddraw_cs); return D3D_OK; } static HRESULT WINAPI IDirect3DDeviceImpl_2_SetLightState(IDirect3DDevice2 *iface, D3DLIGHTSTATETYPE LightStateType, DWORD Value) { - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, state %#x, value %#x.\n", iface, LightStateType, Value); - return IDirect3DDevice3_SetLightState((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, LightStateType, Value); + return IDirect3DDevice3_SetLightState(&This->IDirect3DDevice3_iface, LightStateType, Value); } /***************************************************************************** @@ -3052,7 +3135,7 @@ IDirect3DDeviceImpl_3_GetLightState(IDirect3DDevice3 *iface, D3DLIGHTSTATETYPE LightStateType, DWORD *Value) { - IDirect3DDeviceImpl *This = device_from_device3(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); HRESULT hr; TRACE("iface %p, state %#x, value %p.\n", iface, LightStateType, Value); @@ -3066,7 +3149,7 @@ IDirect3DDeviceImpl_3_GetLightState(IDirect3DDevice3 *iface, if(!Value) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if (LightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */) { *Value = This->material; @@ -3100,27 +3183,27 @@ IDirect3DDeviceImpl_3_GetLightState(IDirect3DDevice3 *iface, break; default: ERR("Unknown D3DLIGHTSTATETYPE %d.\n", LightStateType); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } - hr = IDirect3DDevice7_GetRenderState((IDirect3DDevice7 *)This, rs, Value); - LeaveCriticalSection(&ddraw_cs); + hr = IDirect3DDevice7_GetRenderState(&This->IDirect3DDevice7_iface, rs, Value); + wined3d_mutex_unlock(); return hr; } + wined3d_mutex_unlock(); - LeaveCriticalSection(&ddraw_cs); return D3D_OK; } static HRESULT WINAPI IDirect3DDeviceImpl_2_GetLightState(IDirect3DDevice2 *iface, D3DLIGHTSTATETYPE LightStateType, DWORD *Value) { - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, state %#x, value %p.\n", iface, LightStateType, Value); - return IDirect3DDevice3_GetLightState((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, LightStateType, Value); + return IDirect3DDevice3_GetLightState(&This->IDirect3DDevice3_iface, LightStateType, Value); } /***************************************************************************** @@ -3149,28 +3232,38 @@ IDirect3DDeviceImpl_7_SetTransform(IDirect3DDevice7 *iface, D3DTRANSFORMSTATETYPE TransformStateType, D3DMATRIX *Matrix) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); D3DTRANSFORMSTATETYPE type; HRESULT hr; TRACE("iface %p, state %#x, matrix %p.\n", iface, TransformStateType, Matrix); - switch(TransformStateType) + switch (TransformStateType) { - case D3DTRANSFORMSTATE_WORLD : type = WINED3DTS_WORLDMATRIX(0); break; - case D3DTRANSFORMSTATE_WORLD1: type = WINED3DTS_WORLDMATRIX(1); break; - case D3DTRANSFORMSTATE_WORLD2: type = WINED3DTS_WORLDMATRIX(2); break; - case D3DTRANSFORMSTATE_WORLD3: type = WINED3DTS_WORLDMATRIX(3); break; - default: type = TransformStateType; + case D3DTRANSFORMSTATE_WORLD: + type = WINED3D_TS_WORLD_MATRIX(0); + break; + case D3DTRANSFORMSTATE_WORLD1: + type = WINED3D_TS_WORLD_MATRIX(1); + break; + case D3DTRANSFORMSTATE_WORLD2: + type = WINED3D_TS_WORLD_MATRIX(2); + break; + case D3DTRANSFORMSTATE_WORLD3: + type = WINED3D_TS_WORLD_MATRIX(3); + break; + default: + type = TransformStateType; } if (!Matrix) return DDERR_INVALIDPARAMS; - /* Note: D3DMATRIX is compatible with WINED3DMATRIX */ - EnterCriticalSection(&ddraw_cs); - hr = wined3d_device_set_transform(This->wined3d_device, type, (WINED3DMATRIX *)Matrix); - LeaveCriticalSection(&ddraw_cs); + /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */ + wined3d_mutex_lock(); + hr = wined3d_device_set_transform(This->wined3d_device, type, (struct wined3d_matrix *)Matrix); + wined3d_mutex_unlock(); + return hr; } @@ -3198,23 +3291,42 @@ IDirect3DDeviceImpl_7_SetTransform_FPUPreserve(IDirect3DDevice7 *iface, } static HRESULT WINAPI IDirect3DDeviceImpl_3_SetTransform(IDirect3DDevice3 *iface, - D3DTRANSFORMSTATETYPE TransformStateType, D3DMATRIX *D3DMatrix) + D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix) { - IDirect3DDeviceImpl *This = device_from_device3(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); - TRACE("iface %p, state %#x, matrix %p.\n", iface, TransformStateType, D3DMatrix); + TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix); - return IDirect3DDevice7_SetTransform((IDirect3DDevice7 *)This, TransformStateType, D3DMatrix); + if (!matrix) + return DDERR_INVALIDPARAMS; + + if (state == D3DTRANSFORMSTATE_PROJECTION) + { + D3DMATRIX projection; + HRESULT hr; + + wined3d_mutex_lock(); + multiply_matrix(&projection, &This->legacy_clipspace, matrix); + hr = wined3d_device_set_transform(This->wined3d_device, + WINED3D_TS_PROJECTION, (struct wined3d_matrix *)&projection); + if (SUCCEEDED(hr)) + This->legacy_projection = *matrix; + wined3d_mutex_unlock(); + + return hr; + } + + return IDirect3DDevice7_SetTransform(&This->IDirect3DDevice7_iface, state, matrix); } static HRESULT WINAPI IDirect3DDeviceImpl_2_SetTransform(IDirect3DDevice2 *iface, D3DTRANSFORMSTATETYPE TransformStateType, D3DMATRIX *D3DMatrix) { - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, state %#x, matrix %p.\n", iface, TransformStateType, D3DMatrix); - return IDirect3DDevice7_SetTransform((IDirect3DDevice7 *)This, TransformStateType, D3DMatrix); + return IDirect3DDevice7_SetTransform(&This->IDirect3DDevice7_iface, TransformStateType, D3DMatrix); } /***************************************************************************** @@ -3239,7 +3351,7 @@ IDirect3DDeviceImpl_7_GetTransform(IDirect3DDevice7 *iface, D3DTRANSFORMSTATETYPE TransformStateType, D3DMATRIX *Matrix) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); D3DTRANSFORMSTATETYPE type; HRESULT hr; @@ -3247,20 +3359,30 @@ IDirect3DDeviceImpl_7_GetTransform(IDirect3DDevice7 *iface, switch(TransformStateType) { - case D3DTRANSFORMSTATE_WORLD : type = WINED3DTS_WORLDMATRIX(0); break; - case D3DTRANSFORMSTATE_WORLD1: type = WINED3DTS_WORLDMATRIX(1); break; - case D3DTRANSFORMSTATE_WORLD2: type = WINED3DTS_WORLDMATRIX(2); break; - case D3DTRANSFORMSTATE_WORLD3: type = WINED3DTS_WORLDMATRIX(3); break; - default: type = TransformStateType; + case D3DTRANSFORMSTATE_WORLD: + type = WINED3D_TS_WORLD_MATRIX(0); + break; + case D3DTRANSFORMSTATE_WORLD1: + type = WINED3D_TS_WORLD_MATRIX(1); + break; + case D3DTRANSFORMSTATE_WORLD2: + type = WINED3D_TS_WORLD_MATRIX(2); + break; + case D3DTRANSFORMSTATE_WORLD3: + type = WINED3D_TS_WORLD_MATRIX(3); + break; + default: + type = TransformStateType; } if(!Matrix) return DDERR_INVALIDPARAMS; - /* Note: D3DMATRIX is compatible with WINED3DMATRIX */ - EnterCriticalSection(&ddraw_cs); - hr = wined3d_device_get_transform(This->wined3d_device, type, (WINED3DMATRIX *)Matrix); - LeaveCriticalSection(&ddraw_cs); + /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */ + wined3d_mutex_lock(); + hr = wined3d_device_get_transform(This->wined3d_device, type, (struct wined3d_matrix *)Matrix); + wined3d_mutex_unlock(); + return hr; } @@ -3288,23 +3410,34 @@ IDirect3DDeviceImpl_7_GetTransform_FPUPreserve(IDirect3DDevice7 *iface, } static HRESULT WINAPI IDirect3DDeviceImpl_3_GetTransform(IDirect3DDevice3 *iface, - D3DTRANSFORMSTATETYPE TransformStateType, D3DMATRIX *D3DMatrix) + D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix) { - IDirect3DDeviceImpl *This = device_from_device3(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); - TRACE("iface %p, state %#x, matrix %p.\n", iface, TransformStateType, D3DMatrix); + TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix); - return IDirect3DDevice7_GetTransform((IDirect3DDevice7 *)This, TransformStateType, D3DMatrix); + if (!matrix) + return DDERR_INVALIDPARAMS; + + if (state == D3DTRANSFORMSTATE_PROJECTION) + { + wined3d_mutex_lock(); + *matrix = This->legacy_projection; + wined3d_mutex_unlock(); + return DD_OK; + } + + return IDirect3DDevice7_GetTransform(&This->IDirect3DDevice7_iface, state, matrix); } static HRESULT WINAPI IDirect3DDeviceImpl_2_GetTransform(IDirect3DDevice2 *iface, D3DTRANSFORMSTATETYPE TransformStateType, D3DMATRIX *D3DMatrix) { - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, state %#x, matrix %p.\n", iface, TransformStateType, D3DMatrix); - return IDirect3DDevice7_GetTransform((IDirect3DDevice7 *)This, TransformStateType, D3DMatrix); + return IDirect3DDevice7_GetTransform(&This->IDirect3DDevice7_iface, TransformStateType, D3DMatrix); } /***************************************************************************** @@ -3330,7 +3463,7 @@ IDirect3DDeviceImpl_7_MultiplyTransform(IDirect3DDevice7 *iface, D3DTRANSFORMSTATETYPE TransformStateType, D3DMATRIX *D3DMatrix) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; D3DTRANSFORMSTATETYPE type; @@ -3338,18 +3471,28 @@ IDirect3DDeviceImpl_7_MultiplyTransform(IDirect3DDevice7 *iface, switch(TransformStateType) { - case D3DTRANSFORMSTATE_WORLD : type = WINED3DTS_WORLDMATRIX(0); break; - case D3DTRANSFORMSTATE_WORLD1: type = WINED3DTS_WORLDMATRIX(1); break; - case D3DTRANSFORMSTATE_WORLD2: type = WINED3DTS_WORLDMATRIX(2); break; - case D3DTRANSFORMSTATE_WORLD3: type = WINED3DTS_WORLDMATRIX(3); break; - default: type = TransformStateType; + case D3DTRANSFORMSTATE_WORLD: + type = WINED3D_TS_WORLD_MATRIX(0); + break; + case D3DTRANSFORMSTATE_WORLD1: + type = WINED3D_TS_WORLD_MATRIX(1); + break; + case D3DTRANSFORMSTATE_WORLD2: + type = WINED3D_TS_WORLD_MATRIX(2); + break; + case D3DTRANSFORMSTATE_WORLD3: + type = WINED3D_TS_WORLD_MATRIX(3); + break; + default: + type = TransformStateType; } - /* Note: D3DMATRIX is compatible with WINED3DMATRIX */ - EnterCriticalSection(&ddraw_cs); + /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */ + wined3d_mutex_lock(); hr = wined3d_device_multiply_transform(This->wined3d_device, - type, (WINED3DMATRIX *)D3DMatrix); - LeaveCriticalSection(&ddraw_cs); + type, (struct wined3d_matrix *)D3DMatrix); + wined3d_mutex_unlock(); + return hr; } @@ -3377,23 +3520,40 @@ IDirect3DDeviceImpl_7_MultiplyTransform_FPUPreserve(IDirect3DDevice7 *iface, } static HRESULT WINAPI IDirect3DDeviceImpl_3_MultiplyTransform(IDirect3DDevice3 *iface, - D3DTRANSFORMSTATETYPE TransformStateType, D3DMATRIX *D3DMatrix) + D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix) { - IDirect3DDeviceImpl *This = device_from_device3(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); - TRACE("iface %p, state %#x, matrix %p.\n", iface, TransformStateType, D3DMatrix); + TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix); - return IDirect3DDevice7_MultiplyTransform((IDirect3DDevice7 *)This, TransformStateType, D3DMatrix); + if (state == D3DTRANSFORMSTATE_PROJECTION) + { + D3DMATRIX projection, tmp; + HRESULT hr; + + wined3d_mutex_lock(); + multiply_matrix(&tmp, &This->legacy_projection, matrix); + multiply_matrix(&projection, &This->legacy_clipspace, &tmp); + hr = wined3d_device_set_transform(This->wined3d_device, + WINED3D_TS_PROJECTION, (struct wined3d_matrix *)&projection); + if (SUCCEEDED(hr)) + This->legacy_projection = tmp; + wined3d_mutex_unlock(); + + return hr; + } + + return IDirect3DDevice7_MultiplyTransform(&This->IDirect3DDevice7_iface, state, matrix); } static HRESULT WINAPI IDirect3DDeviceImpl_2_MultiplyTransform(IDirect3DDevice2 *iface, D3DTRANSFORMSTATETYPE TransformStateType, D3DMATRIX *D3DMatrix) { - IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, state %#x, matrix %p.\n", iface, TransformStateType, D3DMatrix); - return IDirect3DDevice7_MultiplyTransform((IDirect3DDevice7 *)This, TransformStateType, D3DMatrix); + return IDirect3DDevice7_MultiplyTransform(&This->IDirect3DDevice7_iface, TransformStateType, D3DMatrix); } /***************************************************************************** @@ -3425,7 +3585,7 @@ IDirect3DDeviceImpl_7_DrawPrimitive(IDirect3DDevice7 *iface, DWORD VertexCount, DWORD Flags) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); UINT stride; HRESULT hr; @@ -3439,18 +3599,19 @@ IDirect3DDeviceImpl_7_DrawPrimitive(IDirect3DDevice7 *iface, stride = get_flexible_vertex_size(VertexType); /* Set the FVF */ - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_device_set_vertex_declaration(This->wined3d_device, ddraw_find_decl(This->ddraw, VertexType)); if(hr != D3D_OK) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } /* This method translates to the user pointer draw of WineD3D */ wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType); hr = wined3d_device_draw_primitive_up(This->wined3d_device, VertexCount, Vertices, stride); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -3487,10 +3648,11 @@ static HRESULT WINAPI IDirect3DDeviceImpl_3_DrawPrimitive(IDirect3DDevice3 *ifac D3DPRIMITIVETYPE PrimitiveType, DWORD VertexType, void *Vertices, DWORD VertexCount, DWORD Flags) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); TRACE("iface %p, primitive_type %#x, FVF %#x, vertices %p, vertex_count %u, flags %#x.\n", iface, PrimitiveType, VertexType, Vertices, VertexCount, Flags); - return IDirect3DDevice7_DrawPrimitive((IDirect3DDevice7 *)device_from_device3(iface), + return IDirect3DDevice7_DrawPrimitive(&This->IDirect3DDevice7_iface, PrimitiveType, VertexType, Vertices, VertexCount, Flags); } @@ -3498,6 +3660,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_2_DrawPrimitive(IDirect3DDevice2 *ifac D3DPRIMITIVETYPE PrimitiveType, D3DVERTEXTYPE VertexType, void *Vertices, DWORD VertexCount, DWORD Flags) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); DWORD FVF; TRACE("iface %p, primitive_type %#x, vertex_type %#x, vertices %p, vertex_count %u, flags %#x.\n", @@ -3513,7 +3676,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_2_DrawPrimitive(IDirect3DDevice2 *ifac return DDERR_INVALIDPARAMS; /* Should never happen */ } - return IDirect3DDevice7_DrawPrimitive((IDirect3DDevice7 *)device_from_device2(iface), + return IDirect3DDevice7_DrawPrimitive(&This->IDirect3DDevice7_iface, PrimitiveType, FVF, Vertices, VertexCount, Flags); } @@ -3551,26 +3714,27 @@ IDirect3DDeviceImpl_7_DrawIndexedPrimitive(IDirect3DDevice7 *iface, DWORD IndexCount, DWORD Flags) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p, primitive_type %#x, FVF %#x, vertices %p, vertex_count %u, indices %p, index_count %u, flags %#x.\n", iface, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags); /* Set the D3DDevice's FVF */ - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_device_set_vertex_declaration(This->wined3d_device, ddraw_find_decl(This->ddraw, VertexType)); if(FAILED(hr)) { ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType); hr = wined3d_device_draw_indexed_primitive_up(This->wined3d_device, IndexCount, Indices, WINED3DFMT_R16_UINT, Vertices, get_flexible_vertex_size(VertexType)); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -3611,10 +3775,11 @@ static HRESULT WINAPI IDirect3DDeviceImpl_3_DrawIndexedPrimitive(IDirect3DDevice D3DPRIMITIVETYPE PrimitiveType, DWORD VertexType, void *Vertices, DWORD VertexCount, WORD *Indices, DWORD IndexCount, DWORD Flags) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); TRACE("iface %p, primitive_type %#x, FVF %#x, vertices %p, vertex_count %u, indices %p, index_count %u, flags %#x.\n", iface, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags); - return IDirect3DDevice7_DrawIndexedPrimitive((IDirect3DDevice7 *)device_from_device3(iface), + return IDirect3DDevice7_DrawIndexedPrimitive(&This->IDirect3DDevice7_iface, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags); } @@ -3622,6 +3787,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_2_DrawIndexedPrimitive(IDirect3DDevice D3DPRIMITIVETYPE PrimitiveType, D3DVERTEXTYPE VertexType, void *Vertices, DWORD VertexCount, WORD *Indices, DWORD IndexCount, DWORD Flags) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); DWORD FVF; TRACE("iface %p, primitive_type %#x, vertex_type %#x, vertices %p, vertex_count %u, indices %p, index_count %u, flags %#x.\n", @@ -3637,7 +3803,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_2_DrawIndexedPrimitive(IDirect3DDevice return DDERR_INVALIDPARAMS; /* Should never happen */ } - return IDirect3DDevice7_DrawIndexedPrimitive((IDirect3DDevice7 *)device_from_device2(iface), + return IDirect3DDevice7_DrawIndexedPrimitive(&This->IDirect3DDevice7_iface, PrimitiveType, FVF, Vertices, VertexCount, Indices, IndexCount, Flags); } @@ -3673,17 +3839,19 @@ IDirect3DDeviceImpl_7_SetClipStatus(IDirect3DDevice7 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_3_SetClipStatus(IDirect3DDevice3 *iface, D3DCLIPSTATUS *ClipStatus) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); TRACE("iface %p, clip_status %p.\n", iface, ClipStatus); - return IDirect3DDevice7_SetClipStatus((IDirect3DDevice7 *)device_from_device3(iface), ClipStatus); + return IDirect3DDevice7_SetClipStatus(&This->IDirect3DDevice7_iface, ClipStatus); } static HRESULT WINAPI IDirect3DDeviceImpl_2_SetClipStatus(IDirect3DDevice2 *iface, D3DCLIPSTATUS *ClipStatus) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, clip_status %p.\n", iface, ClipStatus); - return IDirect3DDevice7_SetClipStatus((IDirect3DDevice7 *)device_from_device2(iface), ClipStatus); + return IDirect3DDevice7_SetClipStatus(&This->IDirect3DDevice7_iface, ClipStatus); } /***************************************************************************** @@ -3712,17 +3880,19 @@ IDirect3DDeviceImpl_7_GetClipStatus(IDirect3DDevice7 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_3_GetClipStatus(IDirect3DDevice3 *iface, D3DCLIPSTATUS *ClipStatus) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); TRACE("iface %p, clip_status %p.\n", iface, ClipStatus); - return IDirect3DDevice7_GetClipStatus((IDirect3DDevice7 *)device_from_device3(iface), ClipStatus); + return IDirect3DDevice7_GetClipStatus(&This->IDirect3DDevice7_iface, ClipStatus); } static HRESULT WINAPI IDirect3DDeviceImpl_2_GetClipStatus(IDirect3DDevice2 *iface, D3DCLIPSTATUS *ClipStatus) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice2(iface); TRACE("iface %p, clip_status %p.\n", iface, ClipStatus); - return IDirect3DDevice7_GetClipStatus((IDirect3DDevice7 *)device_from_device2(iface), ClipStatus); + return IDirect3DDevice7_GetClipStatus(&This->IDirect3DDevice7_iface, ClipStatus); } /***************************************************************************** @@ -3754,15 +3924,15 @@ IDirect3DDeviceImpl_7_DrawPrimitiveStrided(IDirect3DDevice7 *iface, DWORD VertexCount, DWORD Flags) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; - WineDirect3DVertexStridedData WineD3DStrided; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); + struct wined3d_strided_data wined3d_strided; DWORD i; HRESULT hr; TRACE("iface %p, primitive_type %#x, FVF %#x, strided_data %p, vertex_count %u, flags %#x.\n", iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags); - memset(&WineD3DStrided, 0, sizeof(WineD3DStrided)); + memset(&wined3d_strided, 0, sizeof(wined3d_strided)); /* Get the strided data right. the wined3d structure is a bit bigger * Watch out: The contents of the strided data are determined by the fvf, * not by the members set in D3DDrawPrimStrideData. So it's valid @@ -3771,58 +3941,62 @@ IDirect3DDeviceImpl_7_DrawPrimitiveStrided(IDirect3DDevice7 *iface, */ if(VertexType & D3DFVF_POSITION_MASK) { - WineD3DStrided.position.format = WINED3DFMT_R32G32B32_FLOAT; - WineD3DStrided.position.lpData = D3DDrawPrimStrideData->position.lpvData; - WineD3DStrided.position.dwStride = D3DDrawPrimStrideData->position.dwStride; + wined3d_strided.position.format = WINED3DFMT_R32G32B32_FLOAT; + wined3d_strided.position.data = D3DDrawPrimStrideData->position.lpvData; + wined3d_strided.position.stride = D3DDrawPrimStrideData->position.dwStride; if (VertexType & D3DFVF_XYZRHW) { - WineD3DStrided.position.format = WINED3DFMT_R32G32B32A32_FLOAT; - WineD3DStrided.position_transformed = TRUE; - } else - WineD3DStrided.position_transformed = FALSE; - } - - if(VertexType & D3DFVF_NORMAL) - { - WineD3DStrided.normal.format = WINED3DFMT_R32G32B32_FLOAT; - WineD3DStrided.normal.lpData = D3DDrawPrimStrideData->normal.lpvData; - WineD3DStrided.normal.dwStride = D3DDrawPrimStrideData->normal.dwStride; - } - - if(VertexType & D3DFVF_DIFFUSE) - { - WineD3DStrided.diffuse.format = WINED3DFMT_B8G8R8A8_UNORM; - WineD3DStrided.diffuse.lpData = D3DDrawPrimStrideData->diffuse.lpvData; - WineD3DStrided.diffuse.dwStride = D3DDrawPrimStrideData->diffuse.dwStride; - } - - if(VertexType & D3DFVF_SPECULAR) - { - WineD3DStrided.specular.format = WINED3DFMT_B8G8R8A8_UNORM; - WineD3DStrided.specular.lpData = D3DDrawPrimStrideData->specular.lpvData; - WineD3DStrided.specular.dwStride = D3DDrawPrimStrideData->specular.dwStride; - } - - for( i = 0; i < GET_TEXCOUNT_FROM_FVF(VertexType); i++) - { - switch(GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i)) + wined3d_strided.position.format = WINED3DFMT_R32G32B32A32_FLOAT; + wined3d_strided.position_transformed = TRUE; + } + else { - case 1: WineD3DStrided.texCoords[i].format = WINED3DFMT_R32_FLOAT; break; - case 2: WineD3DStrided.texCoords[i].format = WINED3DFMT_R32G32_FLOAT; break; - case 3: WineD3DStrided.texCoords[i].format = WINED3DFMT_R32G32B32_FLOAT; break; - case 4: WineD3DStrided.texCoords[i].format = WINED3DFMT_R32G32B32A32_FLOAT; break; + wined3d_strided.position_transformed = FALSE; + } + } + + if (VertexType & D3DFVF_NORMAL) + { + wined3d_strided.normal.format = WINED3DFMT_R32G32B32_FLOAT; + wined3d_strided.normal.data = D3DDrawPrimStrideData->normal.lpvData; + wined3d_strided.normal.stride = D3DDrawPrimStrideData->normal.dwStride; + } + + if (VertexType & D3DFVF_DIFFUSE) + { + wined3d_strided.diffuse.format = WINED3DFMT_B8G8R8A8_UNORM; + wined3d_strided.diffuse.data = D3DDrawPrimStrideData->diffuse.lpvData; + wined3d_strided.diffuse.stride = D3DDrawPrimStrideData->diffuse.dwStride; + } + + if (VertexType & D3DFVF_SPECULAR) + { + wined3d_strided.specular.format = WINED3DFMT_B8G8R8A8_UNORM; + wined3d_strided.specular.data = D3DDrawPrimStrideData->specular.lpvData; + wined3d_strided.specular.stride = D3DDrawPrimStrideData->specular.dwStride; + } + + for (i = 0; i < GET_TEXCOUNT_FROM_FVF(VertexType); ++i) + { + switch (GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i)) + { + case 1: wined3d_strided.tex_coords[i].format = WINED3DFMT_R32_FLOAT; break; + case 2: wined3d_strided.tex_coords[i].format = WINED3DFMT_R32G32_FLOAT; break; + case 3: wined3d_strided.tex_coords[i].format = WINED3DFMT_R32G32B32_FLOAT; break; + case 4: wined3d_strided.tex_coords[i].format = WINED3DFMT_R32G32B32A32_FLOAT; break; default: ERR("Unexpected texture coordinate size %d\n", GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i)); } - WineD3DStrided.texCoords[i].lpData = D3DDrawPrimStrideData->textureCoords[i].lpvData; - WineD3DStrided.texCoords[i].dwStride = D3DDrawPrimStrideData->textureCoords[i].dwStride; + wined3d_strided.tex_coords[i].data = D3DDrawPrimStrideData->textureCoords[i].lpvData; + wined3d_strided.tex_coords[i].stride = D3DDrawPrimStrideData->textureCoords[i].dwStride; } /* WineD3D doesn't need the FVF here */ - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType); - hr = wined3d_device_draw_primitive_strided(This->wined3d_device, VertexCount, &WineD3DStrided); - LeaveCriticalSection(&ddraw_cs); + hr = wined3d_device_draw_primitive_strided(This->wined3d_device, VertexCount, &wined3d_strided); + wined3d_mutex_unlock(); + return hr; } @@ -3859,10 +4033,12 @@ static HRESULT WINAPI IDirect3DDeviceImpl_3_DrawPrimitiveStrided(IDirect3DDevice D3DPRIMITIVETYPE PrimitiveType, DWORD VertexType, D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData, DWORD VertexCount, DWORD Flags) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); + TRACE("iface %p, primitive_type %#x, FVF %#x, strided_data %p, vertex_count %u, flags %#x.\n", iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags); - return IDirect3DDevice7_DrawPrimitiveStrided((IDirect3DDevice7 *)device_from_device3(iface), + return IDirect3DDevice7_DrawPrimitiveStrided(&This->IDirect3DDevice7_iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags); } @@ -3893,76 +4069,79 @@ IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided(IDirect3DDevice7 *iface, DWORD IndexCount, DWORD Flags) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; - WineDirect3DVertexStridedData WineD3DStrided; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); + struct wined3d_strided_data wined3d_strided; DWORD i; HRESULT hr; TRACE("iface %p, primitive_type %#x, FVF %#x, strided_data %p, vertex_count %u, indices %p, index_count %u, flags %#x.\n", iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags); - memset(&WineD3DStrided, 0, sizeof(WineD3DStrided)); + memset(&wined3d_strided, 0, sizeof(wined3d_strided)); /* Get the strided data right. the wined3d structure is a bit bigger * Watch out: The contents of the strided data are determined by the fvf, * not by the members set in D3DDrawPrimStrideData. So it's valid * to have diffuse.lpvData set to 0xdeadbeef if the diffuse flag is - * not set in the fvf. - */ - if(VertexType & D3DFVF_POSITION_MASK) + * not set in the fvf. */ + if (VertexType & D3DFVF_POSITION_MASK) { - WineD3DStrided.position.format = WINED3DFMT_R32G32B32_FLOAT; - WineD3DStrided.position.lpData = D3DDrawPrimStrideData->position.lpvData; - WineD3DStrided.position.dwStride = D3DDrawPrimStrideData->position.dwStride; + wined3d_strided.position.format = WINED3DFMT_R32G32B32_FLOAT; + wined3d_strided.position.data = D3DDrawPrimStrideData->position.lpvData; + wined3d_strided.position.stride = D3DDrawPrimStrideData->position.dwStride; if (VertexType & D3DFVF_XYZRHW) { - WineD3DStrided.position.format = WINED3DFMT_R32G32B32A32_FLOAT; - WineD3DStrided.position_transformed = TRUE; - } else - WineD3DStrided.position_transformed = FALSE; - } - - if(VertexType & D3DFVF_NORMAL) - { - WineD3DStrided.normal.format = WINED3DFMT_R32G32B32_FLOAT; - WineD3DStrided.normal.lpData = D3DDrawPrimStrideData->normal.lpvData; - WineD3DStrided.normal.dwStride = D3DDrawPrimStrideData->normal.dwStride; - } - - if(VertexType & D3DFVF_DIFFUSE) - { - WineD3DStrided.diffuse.format = WINED3DFMT_B8G8R8A8_UNORM; - WineD3DStrided.diffuse.lpData = D3DDrawPrimStrideData->diffuse.lpvData; - WineD3DStrided.diffuse.dwStride = D3DDrawPrimStrideData->diffuse.dwStride; - } - - if(VertexType & D3DFVF_SPECULAR) - { - WineD3DStrided.specular.format = WINED3DFMT_B8G8R8A8_UNORM; - WineD3DStrided.specular.lpData = D3DDrawPrimStrideData->specular.lpvData; - WineD3DStrided.specular.dwStride = D3DDrawPrimStrideData->specular.dwStride; - } - - for( i = 0; i < GET_TEXCOUNT_FROM_FVF(VertexType); i++) - { - switch(GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i)) + wined3d_strided.position.format = WINED3DFMT_R32G32B32A32_FLOAT; + wined3d_strided.position_transformed = TRUE; + } + else { - case 1: WineD3DStrided.texCoords[i].format = WINED3DFMT_R32_FLOAT; break; - case 2: WineD3DStrided.texCoords[i].format = WINED3DFMT_R32G32_FLOAT; break; - case 3: WineD3DStrided.texCoords[i].format = WINED3DFMT_R32G32B32_FLOAT; break; - case 4: WineD3DStrided.texCoords[i].format = WINED3DFMT_R32G32B32A32_FLOAT; break; + wined3d_strided.position_transformed = FALSE; + } + } + + if (VertexType & D3DFVF_NORMAL) + { + wined3d_strided.normal.format = WINED3DFMT_R32G32B32_FLOAT; + wined3d_strided.normal.data = D3DDrawPrimStrideData->normal.lpvData; + wined3d_strided.normal.stride = D3DDrawPrimStrideData->normal.dwStride; + } + + if (VertexType & D3DFVF_DIFFUSE) + { + wined3d_strided.diffuse.format = WINED3DFMT_B8G8R8A8_UNORM; + wined3d_strided.diffuse.data = D3DDrawPrimStrideData->diffuse.lpvData; + wined3d_strided.diffuse.stride = D3DDrawPrimStrideData->diffuse.dwStride; + } + + if (VertexType & D3DFVF_SPECULAR) + { + wined3d_strided.specular.format = WINED3DFMT_B8G8R8A8_UNORM; + wined3d_strided.specular.data = D3DDrawPrimStrideData->specular.lpvData; + wined3d_strided.specular.stride = D3DDrawPrimStrideData->specular.dwStride; + } + + for (i = 0; i < GET_TEXCOUNT_FROM_FVF(VertexType); ++i) + { + switch (GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i)) + { + case 1: wined3d_strided.tex_coords[i].format = WINED3DFMT_R32_FLOAT; break; + case 2: wined3d_strided.tex_coords[i].format = WINED3DFMT_R32G32_FLOAT; break; + case 3: wined3d_strided.tex_coords[i].format = WINED3DFMT_R32G32B32_FLOAT; break; + case 4: wined3d_strided.tex_coords[i].format = WINED3DFMT_R32G32B32A32_FLOAT; break; default: ERR("Unexpected texture coordinate size %d\n", GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i)); } - WineD3DStrided.texCoords[i].lpData = D3DDrawPrimStrideData->textureCoords[i].lpvData; - WineD3DStrided.texCoords[i].dwStride = D3DDrawPrimStrideData->textureCoords[i].dwStride; + wined3d_strided.tex_coords[i].data = D3DDrawPrimStrideData->textureCoords[i].lpvData; + wined3d_strided.tex_coords[i].stride = D3DDrawPrimStrideData->textureCoords[i].dwStride; } /* WineD3D doesn't need the FVF here */ - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType); hr = wined3d_device_draw_indexed_primitive_strided(This->wined3d_device, - IndexCount, &WineD3DStrided, VertexCount, Indices, WINED3DFMT_R16_UINT); - LeaveCriticalSection(&ddraw_cs); + IndexCount, &wined3d_strided, VertexCount, Indices, WINED3DFMT_R16_UINT); + wined3d_mutex_unlock(); + return hr; } @@ -4004,10 +4183,12 @@ static HRESULT WINAPI IDirect3DDeviceImpl_3_DrawIndexedPrimitiveStrided(IDirect3 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData, DWORD VertexCount, WORD *Indices, DWORD IndexCount, DWORD Flags) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); + TRACE("iface %p, primitive_type %#x, FVF %#x, strided_data %p, vertex_count %u, indices %p, index_count %u, flags %#x.\n", iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags); - return IDirect3DDevice7_DrawIndexedPrimitiveStrided((IDirect3DDevice7 *)device_from_device3(iface), + return IDirect3DDevice7_DrawIndexedPrimitiveStrided(&This->IDirect3DDevice7_iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags); } @@ -4038,8 +4219,8 @@ IDirect3DDeviceImpl_7_DrawPrimitiveVB(IDirect3DDevice7 *iface, DWORD NumVertices, DWORD Flags) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; - IDirect3DVertexBufferImpl *vb = (IDirect3DVertexBufferImpl *)D3DVertexBuf; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); + IDirect3DVertexBufferImpl *vb = unsafe_impl_from_IDirect3DVertexBuffer7(D3DVertexBuf); HRESULT hr; DWORD stride; @@ -4054,12 +4235,12 @@ IDirect3DDeviceImpl_7_DrawPrimitiveVB(IDirect3DDevice7 *iface, } stride = get_flexible_vertex_size(vb->fvf); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_device_set_vertex_declaration(This->wined3d_device, vb->wineD3DVertexDeclaration); if (FAILED(hr)) { ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } @@ -4068,14 +4249,15 @@ IDirect3DDeviceImpl_7_DrawPrimitiveVB(IDirect3DDevice7 *iface, if(hr != D3D_OK) { ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08x\n", This, hr); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } /* Now draw the primitives */ wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType); hr = wined3d_device_draw_primitive(This->wined3d_device, StartVertex, NumVertices); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -4112,13 +4294,14 @@ static HRESULT WINAPI IDirect3DDeviceImpl_3_DrawPrimitiveVB(IDirect3DDevice3 *if D3DPRIMITIVETYPE PrimitiveType, IDirect3DVertexBuffer *D3DVertexBuf, DWORD StartVertex, DWORD NumVertices, DWORD Flags) { - IDirect3DVertexBufferImpl *vb = D3DVertexBuf ? vb_from_vb1(D3DVertexBuf) : NULL; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); + IDirect3DVertexBufferImpl *vb = unsafe_impl_from_IDirect3DVertexBuffer(D3DVertexBuf); TRACE("iface %p, primitive_type %#x, vb %p, start_vertex %u, vertex_count %u, flags %#x.\n", iface, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Flags); - return IDirect3DDevice7_DrawPrimitiveVB((IDirect3DDevice7 *)device_from_device3(iface), - PrimitiveType, (IDirect3DVertexBuffer7 *)vb, StartVertex, NumVertices, Flags); + return IDirect3DDevice7_DrawPrimitiveVB(&This->IDirect3DDevice7_iface, + PrimitiveType, &vb->IDirect3DVertexBuffer7_iface, StartVertex, NumVertices, Flags); } @@ -4149,8 +4332,8 @@ IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface, DWORD IndexCount, DWORD Flags) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; - IDirect3DVertexBufferImpl *vb = (IDirect3DVertexBufferImpl *)D3DVertexBuf; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); + IDirect3DVertexBufferImpl *vb = unsafe_impl_from_IDirect3DVertexBuffer7(D3DVertexBuf); DWORD stride = get_flexible_vertex_size(vb->fvf); struct wined3d_resource *wined3d_resource; struct wined3d_resource_desc desc; @@ -4167,13 +4350,13 @@ IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface, * 4) Call IWineD3DDevice::DrawIndexedPrimitive */ - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_device_set_vertex_declaration(This->wined3d_device, vb->wineD3DVertexDeclaration); if (FAILED(hr)) { ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } @@ -4189,11 +4372,11 @@ IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface, TRACE("Growing index buffer to %u bytes\n", size); hr = wined3d_buffer_create_ib(This->wined3d_device, size, WINED3DUSAGE_DYNAMIC /* Usage */, - WINED3DPOOL_DEFAULT, NULL, &ddraw_null_wined3d_parent_ops, &buffer); + WINED3D_POOL_DEFAULT, NULL, &ddraw_null_wined3d_parent_ops, &buffer); if (FAILED(hr)) { ERR("(%p) IWineD3DDevice::CreateIndexBuffer failed with hr = %08x\n", This, hr); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } @@ -4210,7 +4393,7 @@ IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface, if (FAILED(hr)) { ERR("Failed to map buffer, hr %#x.\n", hr); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } memcpy(LockedIndices, Indices, IndexCount * sizeof(WORD)); @@ -4225,7 +4408,7 @@ IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface, if (FAILED(hr)) { ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08x\n", This, hr); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } @@ -4233,7 +4416,8 @@ IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface, wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType); hr = wined3d_device_draw_indexed_primitive(This->wined3d_device, 0, IndexCount); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -4274,13 +4458,15 @@ static HRESULT WINAPI IDirect3DDeviceImpl_3_DrawIndexedPrimitiveVB(IDirect3DDevi D3DPRIMITIVETYPE PrimitiveType, IDirect3DVertexBuffer *D3DVertexBuf, WORD *Indices, DWORD IndexCount, DWORD Flags) { - IDirect3DVertexBufferImpl *VB = vb_from_vb1(D3DVertexBuf); + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); + IDirect3DVertexBufferImpl *vb = unsafe_impl_from_IDirect3DVertexBuffer(D3DVertexBuf); TRACE("iface %p, primitive_type %#x, vb %p, indices %p, index_count %u, flags %#x.\n", iface, PrimitiveType, D3DVertexBuf, Indices, IndexCount, Flags); - return IDirect3DDevice7_DrawIndexedPrimitiveVB((IDirect3DDevice7 *)device_from_device3(iface), - PrimitiveType, (IDirect3DVertexBuffer7 *)VB, 0, IndexCount, Indices, IndexCount, Flags); + return IDirect3DDevice7_DrawIndexedPrimitiveVB(&This->IDirect3DDevice7_iface, + PrimitiveType, &vb->IDirect3DVertexBuffer7_iface, 0, IndexCount, Indices, IndexCount, + Flags); } /***************************************************************************** @@ -4397,10 +4583,12 @@ IDirect3DDeviceImpl_7_ComputeSphereVisibility(IDirect3DDevice7 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_3_ComputeSphereVisibility(IDirect3DDevice3 *iface, D3DVECTOR *Centers, D3DVALUE *Radii, DWORD NumSpheres, DWORD Flags, DWORD *ReturnValues) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); + TRACE("iface %p, centers %p, radii %p, sphere_count %u, flags %#x, return_values %p.\n", iface, Centers, Radii, NumSpheres, Flags, ReturnValues); - return IDirect3DDevice7_ComputeSphereVisibility((IDirect3DDevice7 *)device_from_device3(iface), + return IDirect3DDevice7_ComputeSphereVisibility(&This->IDirect3DDevice7_iface, Centers, Radii, NumSpheres, Flags, ReturnValues); } @@ -4428,7 +4616,7 @@ IDirect3DDeviceImpl_7_GetTexture(IDirect3DDevice7 *iface, DWORD Stage, IDirectDrawSurface7 **Texture) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); struct wined3d_texture *wined3d_texture; HRESULT hr; @@ -4440,18 +4628,20 @@ IDirect3DDeviceImpl_7_GetTexture(IDirect3DDevice7 *iface, return DDERR_INVALIDPARAMS; } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_device_get_texture(This->wined3d_device, Stage, &wined3d_texture); if (FAILED(hr) || !wined3d_texture) { *Texture = NULL; - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } *Texture = wined3d_texture_get_parent(wined3d_texture); IDirectDrawSurface7_AddRef(*Texture); - LeaveCriticalSection(&ddraw_cs); + wined3d_texture_decref(wined3d_texture); + wined3d_mutex_unlock(); + return hr; } @@ -4481,14 +4671,17 @@ IDirect3DDeviceImpl_7_GetTexture_FPUPreserve(IDirect3DDevice7 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_3_GetTexture(IDirect3DDevice3 *iface, DWORD Stage, IDirect3DTexture2 **Texture2) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); HRESULT ret; IDirectDrawSurface7 *ret_val; + IDirectDrawSurfaceImpl *ret_val_impl; TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, Texture2); - ret = IDirect3DDevice7_GetTexture((IDirect3DDevice7 *)device_from_device3(iface), Stage, &ret_val); + ret = IDirect3DDevice7_GetTexture(&This->IDirect3DDevice7_iface, Stage, &ret_val); - *Texture2 = ret_val ? (IDirect3DTexture2 *)&((IDirectDrawSurfaceImpl *)ret_val)->IDirect3DTexture2_vtbl : NULL; + ret_val_impl = unsafe_impl_from_IDirectDrawSurface7(ret_val); + *Texture2 = ret_val_impl ? &ret_val_impl->IDirect3DTexture2_iface : NULL; TRACE("Returning texture %p.\n", *Texture2); @@ -4516,17 +4709,18 @@ IDirect3DDeviceImpl_7_SetTexture(IDirect3DDevice7 *iface, DWORD Stage, IDirectDrawSurface7 *Texture) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; - IDirectDrawSurfaceImpl *surf = (IDirectDrawSurfaceImpl *)Texture; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); + IDirectDrawSurfaceImpl *surf = unsafe_impl_from_IDirectDrawSurface7(Texture); HRESULT hr; TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, Texture); /* Texture may be NULL here */ - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_device_set_texture(This->wined3d_device, Stage, surf ? surf->wined3d_texture : NULL); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -4558,19 +4752,19 @@ IDirect3DDeviceImpl_3_SetTexture(IDirect3DDevice3 *iface, DWORD Stage, IDirect3DTexture2 *Texture2) { - IDirect3DDeviceImpl *This = device_from_device3(iface); - IDirectDrawSurfaceImpl *tex = Texture2 ? surface_from_texture2(Texture2) : NULL; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); + IDirectDrawSurfaceImpl *tex = unsafe_impl_from_IDirect3DTexture2(Texture2); DWORD texmapblend; HRESULT hr; TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, Texture2); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if (This->legacyTextureBlending) IDirect3DDevice3_GetRenderState(iface, D3DRENDERSTATE_TEXTUREMAPBLEND, &texmapblend); - hr = IDirect3DDevice7_SetTexture((IDirect3DDevice7 *)This, Stage, (IDirectDrawSurface7 *)tex); + hr = IDirect3DDevice7_SetTexture(&This->IDirect3DDevice7_iface, Stage, &tex->IDirectDrawSurface7_iface); if (This->legacyTextureBlending && texmapblend == D3DTBLEND_MODULATE) { @@ -4601,12 +4795,14 @@ IDirect3DDeviceImpl_3_SetTexture(IDirect3DDevice3 *iface, /* Arg 1/2 are already set to WINED3DTA_TEXTURE/WINED3DTA_CURRENT in case of D3DTBLEND_MODULATE */ if (tex_alpha) - wined3d_device_set_texture_stage_state(This->wined3d_device, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1); + wined3d_device_set_texture_stage_state(This->wined3d_device, + 0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG1); else - wined3d_device_set_texture_stage_state(This->wined3d_device, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG2); + wined3d_device_set_texture_stage_state(This->wined3d_device, + 0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG2); } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } @@ -4614,35 +4810,35 @@ IDirect3DDeviceImpl_3_SetTexture(IDirect3DDevice3 *iface, static const struct tss_lookup { BOOL sampler_state; - DWORD state; + enum wined3d_texture_stage_state state; } tss_lookup[] = { - {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */ - {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */ - {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */ - {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */ - {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */ - {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */ - {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */ - {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */ - {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */ - {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */ - {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */ - {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */ - {TRUE, WINED3DSAMP_ADDRESSU}, /* 12, D3DTSS_ADDRESS */ - {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */ - {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */ - {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */ - {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */ - {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */ - {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */ - {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */ - {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */ - {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */ - {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */ - {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */ - {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */ + {FALSE, WINED3D_TSS_INVALID}, /* 0, unused */ + {FALSE, WINED3D_TSS_COLOR_OP}, /* 1, D3DTSS_COLOROP */ + {FALSE, WINED3D_TSS_COLOR_ARG1}, /* 2, D3DTSS_COLORARG1 */ + {FALSE, WINED3D_TSS_COLOR_ARG2}, /* 3, D3DTSS_COLORARG2 */ + {FALSE, WINED3D_TSS_ALPHA_OP}, /* 4, D3DTSS_ALPHAOP */ + {FALSE, WINED3D_TSS_ALPHA_ARG1}, /* 5, D3DTSS_ALPHAARG1 */ + {FALSE, WINED3D_TSS_ALPHA_ARG2}, /* 6, D3DTSS_ALPHAARG2 */ + {FALSE, WINED3D_TSS_BUMPENV_MAT00}, /* 7, D3DTSS_BUMPENVMAT00 */ + {FALSE, WINED3D_TSS_BUMPENV_MAT01}, /* 8, D3DTSS_BUMPENVMAT01 */ + {FALSE, WINED3D_TSS_BUMPENV_MAT10}, /* 9, D3DTSS_BUMPENVMAT10 */ + {FALSE, WINED3D_TSS_BUMPENV_MAT11}, /* 10, D3DTSS_BUMPENVMAT11 */ + {FALSE, WINED3D_TSS_TEXCOORD_INDEX}, /* 11, D3DTSS_TEXCOORDINDEX */ + {TRUE, WINED3D_SAMP_ADDRESS_U}, /* 12, D3DTSS_ADDRESS */ + {TRUE, WINED3D_SAMP_ADDRESS_U}, /* 13, D3DTSS_ADDRESSU */ + {TRUE, WINED3D_SAMP_ADDRESS_V}, /* 14, D3DTSS_ADDRESSV */ + {TRUE, WINED3D_SAMP_BORDER_COLOR}, /* 15, D3DTSS_BORDERCOLOR */ + {TRUE, WINED3D_SAMP_MAG_FILTER}, /* 16, D3DTSS_MAGFILTER */ + {TRUE, WINED3D_SAMP_MIN_FILTER}, /* 17, D3DTSS_MINFILTER */ + {TRUE, WINED3D_SAMP_MIP_FILTER}, /* 18, D3DTSS_MIPFILTER */ + {TRUE, WINED3D_SAMP_MIPMAP_LOD_BIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */ + {TRUE, WINED3D_SAMP_MAX_MIP_LEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */ + {TRUE, WINED3D_SAMP_MAX_ANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */ + {FALSE, WINED3D_TSS_BUMPENV_LSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */ + {FALSE, WINED3D_TSS_BUMPENV_LOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */ + {FALSE, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */ }; /***************************************************************************** @@ -4669,7 +4865,7 @@ IDirect3DDeviceImpl_7_GetTextureStageState(IDirect3DDevice7 *iface, D3DTEXTURESTAGESTATETYPE TexStageStateType, DWORD *State) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; const struct tss_lookup *l; @@ -4687,7 +4883,7 @@ IDirect3DDeviceImpl_7_GetTextureStageState(IDirect3DDevice7 *iface, l = &tss_lookup[TexStageStateType]; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if (l->sampler_state) { @@ -4700,9 +4896,15 @@ IDirect3DDeviceImpl_7_GetTextureStageState(IDirect3DDevice7 *iface, { switch(*State) { - case WINED3DTEXF_NONE: *State = D3DTFP_NONE; break; - case WINED3DTEXF_POINT: *State = D3DTFP_POINT; break; - case WINED3DTEXF_LINEAR: *State = D3DTFP_LINEAR; break; + case WINED3D_TEXF_NONE: + *State = D3DTFP_NONE; + break; + case WINED3D_TEXF_POINT: + *State = D3DTFP_POINT; + break; + case WINED3D_TEXF_LINEAR: + *State = D3DTFP_LINEAR; + break; default: ERR("Unexpected mipfilter value %#x\n", *State); *State = D3DTFP_NONE; @@ -4716,11 +4918,21 @@ IDirect3DDeviceImpl_7_GetTextureStageState(IDirect3DDevice7 *iface, { switch(*State) { - case WINED3DTEXF_POINT: *State = D3DTFG_POINT; break; - case WINED3DTEXF_LINEAR: *State = D3DTFG_LINEAR; break; - case WINED3DTEXF_ANISOTROPIC: *State = D3DTFG_ANISOTROPIC; break; - case WINED3DTEXF_FLATCUBIC: *State = D3DTFG_FLATCUBIC; break; - case WINED3DTEXF_GAUSSIANCUBIC: *State = D3DTFG_GAUSSIANCUBIC; break; + case WINED3D_TEXF_POINT: + *State = D3DTFG_POINT; + break; + case WINED3D_TEXF_LINEAR: + *State = D3DTFG_LINEAR; + break; + case WINED3D_TEXF_ANISOTROPIC: + *State = D3DTFG_ANISOTROPIC; + break; + case WINED3D_TEXF_FLAT_CUBIC: + *State = D3DTFG_FLATCUBIC; + break; + case WINED3D_TEXF_GAUSSIAN_CUBIC: + *State = D3DTFG_GAUSSIANCUBIC; + break; default: ERR("Unexpected wined3d mag filter value %#x\n", *State); *State = D3DTFG_POINT; @@ -4738,7 +4950,8 @@ IDirect3DDeviceImpl_7_GetTextureStageState(IDirect3DDevice7 *iface, hr = wined3d_device_get_texture_stage_state(This->wined3d_device, Stage, l->state, State); } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -4770,10 +4983,12 @@ IDirect3DDeviceImpl_7_GetTextureStageState_FPUPreserve(IDirect3DDevice7 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_3_GetTextureStageState(IDirect3DDevice3 *iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE TexStageStateType, DWORD *State) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); + TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, TexStageStateType, State); - return IDirect3DDevice7_GetTextureStageState((IDirect3DDevice7 *)device_from_device3(iface), + return IDirect3DDevice7_GetTextureStageState(&This->IDirect3DDevice7_iface, Stage, TexStageStateType, State); } @@ -4801,7 +5016,7 @@ IDirect3DDeviceImpl_7_SetTextureStageState(IDirect3DDevice7 *iface, D3DTEXTURESTAGESTATETYPE TexStageStateType, DWORD State) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); const struct tss_lookup *l; HRESULT hr; @@ -4816,7 +5031,7 @@ IDirect3DDeviceImpl_7_SetTextureStageState(IDirect3DDevice7 *iface, l = &tss_lookup[TexStageStateType]; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if (l->sampler_state) { @@ -4827,13 +5042,19 @@ IDirect3DDeviceImpl_7_SetTextureStageState(IDirect3DDevice7 *iface, { switch(State) { - case D3DTFP_NONE: State = WINED3DTEXF_NONE; break; - case D3DTFP_POINT: State = WINED3DTEXF_POINT; break; + case D3DTFP_NONE: + State = WINED3D_TEXF_NONE; + break; + case D3DTFP_POINT: + State = WINED3D_TEXF_POINT; + break; case 0: /* Unchecked */ - case D3DTFP_LINEAR: State = WINED3DTEXF_LINEAR; break; + case D3DTFP_LINEAR: + State = WINED3D_TEXF_LINEAR; + break; default: ERR("Unexpected mipfilter value %d\n", State); - State = WINED3DTEXF_NONE; + State = WINED3D_TEXF_NONE; break; } break; @@ -4844,21 +5065,31 @@ IDirect3DDeviceImpl_7_SetTextureStageState(IDirect3DDevice7 *iface, { switch(State) { - case D3DTFG_POINT: State = WINED3DTEXF_POINT; break; - case D3DTFG_LINEAR: State = WINED3DTEXF_LINEAR; break; - case D3DTFG_FLATCUBIC: State = WINED3DTEXF_FLATCUBIC; break; - case D3DTFG_GAUSSIANCUBIC: State = WINED3DTEXF_GAUSSIANCUBIC; break; - case D3DTFG_ANISOTROPIC: State = WINED3DTEXF_ANISOTROPIC; break; + case D3DTFG_POINT: + State = WINED3D_TEXF_POINT; + break; + case D3DTFG_LINEAR: + State = WINED3D_TEXF_LINEAR; + break; + case D3DTFG_FLATCUBIC: + State = WINED3D_TEXF_FLAT_CUBIC; + break; + case D3DTFG_GAUSSIANCUBIC: + State = WINED3D_TEXF_GAUSSIAN_CUBIC; + break; + case D3DTFG_ANISOTROPIC: + State = WINED3D_TEXF_ANISOTROPIC; + break; default: ERR("Unexpected d3d7 mag filter type %d\n", State); - State = WINED3DTEXF_POINT; + State = WINED3D_TEXF_POINT; break; } break; } case D3DTSS_ADDRESS: - wined3d_device_set_sampler_state(This->wined3d_device, Stage, WINED3DSAMP_ADDRESSV, State); + wined3d_device_set_sampler_state(This->wined3d_device, Stage, WINED3D_SAMP_ADDRESS_V, State); break; default: @@ -4872,7 +5103,8 @@ IDirect3DDeviceImpl_7_SetTextureStageState(IDirect3DDevice7 *iface, hr = wined3d_device_set_texture_stage_state(This->wined3d_device, Stage, l->state, State); } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -4904,10 +5136,12 @@ IDirect3DDeviceImpl_7_SetTextureStageState_FPUPreserve(IDirect3DDevice7 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_3_SetTextureStageState(IDirect3DDevice3 *iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE TexStageStateType, DWORD State) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); + TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, TexStageStateType, State); - return IDirect3DDevice7_SetTextureStageState((IDirect3DDevice7 *)device_from_device3(iface), + return IDirect3DDevice7_SetTextureStageState(&This->IDirect3DDevice7_iface, Stage, TexStageStateType, State); } @@ -4933,14 +5167,15 @@ static HRESULT IDirect3DDeviceImpl_7_ValidateDevice(IDirect3DDevice7 *iface, DWORD *NumPasses) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p, pass_count %p.\n", iface, NumPasses); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_device_validate_device(This->wined3d_device, NumPasses); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -4967,9 +5202,11 @@ IDirect3DDeviceImpl_7_ValidateDevice_FPUPreserve(IDirect3DDevice7 *iface, static HRESULT WINAPI IDirect3DDeviceImpl_3_ValidateDevice(IDirect3DDevice3 *iface, DWORD *Passes) { + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice3(iface); + TRACE("iface %p, pass_count %p.\n", iface, Passes); - return IDirect3DDevice7_ValidateDevice((IDirect3DDevice7 *)device_from_device3(iface), Passes); + return IDirect3DDevice7_ValidateDevice(&This->IDirect3DDevice7_iface, Passes); } /***************************************************************************** @@ -4993,24 +5230,26 @@ static HRESULT WINAPI IDirect3DDeviceImpl_3_ValidateDevice(IDirect3DDevice3 *ifa * For details, see IWineD3DDevice::Clear * *****************************************************************************/ -static HRESULT -IDirect3DDeviceImpl_7_Clear(IDirect3DDevice7 *iface, - DWORD Count, - D3DRECT *Rects, - DWORD Flags, - D3DCOLOR Color, - D3DVALUE Z, - DWORD Stencil) +static HRESULT IDirect3DDeviceImpl_7_Clear(IDirect3DDevice7 *iface, DWORD count, + D3DRECT *rects, DWORD flags, D3DCOLOR color, D3DVALUE z, DWORD stencil) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + const struct wined3d_color c = + { + ((color >> 16) & 0xff) / 255.0f, + ((color >> 8) & 0xff) / 255.0f, + (color & 0xff) / 255.0f, + ((color >> 24) & 0xff) / 255.0f, + }; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p, count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %#x.\n", - iface, Count, Rects, Flags, Color, Z, Stencil); + iface, count, rects, flags, color, z, stencil); + + wined3d_mutex_lock(); + hr = wined3d_device_clear(This->wined3d_device, count, (RECT *)rects, flags, &c, z, stencil); + wined3d_mutex_unlock(); - EnterCriticalSection(&ddraw_cs); - hr = wined3d_device_clear(This->wined3d_device, Count, (RECT *)Rects, Flags, Color, Z, Stencil); - LeaveCriticalSection(&ddraw_cs); return hr; } @@ -5066,7 +5305,7 @@ static HRESULT IDirect3DDeviceImpl_7_SetViewport(IDirect3DDevice7 *iface, D3DVIEWPORT7 *Data) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p, viewport %p.\n", iface, Data); @@ -5074,10 +5313,11 @@ IDirect3DDeviceImpl_7_SetViewport(IDirect3DDevice7 *iface, if(!Data) return DDERR_INVALIDPARAMS; - /* Note: D3DVIEWPORT7 is compatible with WINED3DVIEWPORT */ - EnterCriticalSection(&ddraw_cs); - hr = wined3d_device_set_viewport(This->wined3d_device, (WINED3DVIEWPORT *)Data); - LeaveCriticalSection(&ddraw_cs); + /* Note: D3DVIEWPORT7 is compatible with struct wined3d_viewport. */ + wined3d_mutex_lock(); + hr = wined3d_device_set_viewport(This->wined3d_device, (struct wined3d_viewport *)Data); + wined3d_mutex_unlock(); + return hr; } @@ -5122,7 +5362,7 @@ static HRESULT IDirect3DDeviceImpl_7_GetViewport(IDirect3DDevice7 *iface, D3DVIEWPORT7 *Data) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p, viewport %p.\n", iface, Data); @@ -5130,11 +5370,11 @@ IDirect3DDeviceImpl_7_GetViewport(IDirect3DDevice7 *iface, if(!Data) return DDERR_INVALIDPARAMS; - /* Note: D3DVIEWPORT7 is compatible with WINED3DVIEWPORT */ - EnterCriticalSection(&ddraw_cs); - hr = wined3d_device_get_viewport(This->wined3d_device, (WINED3DVIEWPORT *)Data); + /* Note: D3DVIEWPORT7 is compatible with struct wined3d_viewport. */ + wined3d_mutex_lock(); + hr = wined3d_device_get_viewport(This->wined3d_device, (struct wined3d_viewport *)Data); + wined3d_mutex_unlock(); - LeaveCriticalSection(&ddraw_cs); return hr_ddraw_from_wined3d(hr); } @@ -5179,16 +5419,18 @@ static HRESULT IDirect3DDeviceImpl_7_SetMaterial(IDirect3DDevice7 *iface, D3DMATERIAL7 *Mat) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p, material %p.\n", iface, Mat); if (!Mat) return DDERR_INVALIDPARAMS; - /* Note: D3DMATERIAL7 is compatible with WINED3DMATERIAL */ - EnterCriticalSection(&ddraw_cs); - hr = wined3d_device_set_material(This->wined3d_device, (WINED3DMATERIAL *)Mat); - LeaveCriticalSection(&ddraw_cs); + + wined3d_mutex_lock(); + /* Note: D3DMATERIAL7 is compatible with struct wined3d_material. */ + hr = wined3d_device_set_material(This->wined3d_device, (struct wined3d_material *)Mat); + wined3d_mutex_unlock(); + return hr_ddraw_from_wined3d(hr); } @@ -5233,15 +5475,16 @@ static HRESULT IDirect3DDeviceImpl_7_GetMaterial(IDirect3DDevice7 *iface, D3DMATERIAL7 *Mat) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p, material %p.\n", iface, Mat); - EnterCriticalSection(&ddraw_cs); - /* Note: D3DMATERIAL7 is compatible with WINED3DMATERIAL */ - hr = wined3d_device_get_material(This->wined3d_device, (WINED3DMATERIAL *)Mat); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); + /* Note: D3DMATERIAL7 is compatible with struct wined3d_material. */ + hr = wined3d_device_get_material(This->wined3d_device, (struct wined3d_material *)Mat); + wined3d_mutex_unlock(); + return hr_ddraw_from_wined3d(hr); } @@ -5287,15 +5530,16 @@ IDirect3DDeviceImpl_7_SetLight(IDirect3DDevice7 *iface, DWORD LightIndex, D3DLIGHT7 *Light) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p, light_idx %u, light %p.\n", iface, LightIndex, Light); - EnterCriticalSection(&ddraw_cs); - /* Note: D3DLIGHT7 is compatible with WINED3DLIGHT */ - hr = wined3d_device_set_light(This->wined3d_device, LightIndex, (WINED3DLIGHT *)Light); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); + /* Note: D3DLIGHT7 is compatible with struct wined3d_light. */ + hr = wined3d_device_set_light(This->wined3d_device, LightIndex, (struct wined3d_light *)Light); + wined3d_mutex_unlock(); + return hr_ddraw_from_wined3d(hr); } @@ -5341,17 +5585,17 @@ IDirect3DDeviceImpl_7_GetLight(IDirect3DDevice7 *iface, DWORD LightIndex, D3DLIGHT7 *Light) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT rc; TRACE("iface %p, light_idx %u, light %p.\n", iface, LightIndex, Light); - EnterCriticalSection(&ddraw_cs); - /* Note: D3DLIGHT7 is compatible with WINED3DLIGHT */ - rc = wined3d_device_get_light(This->wined3d_device, LightIndex, (WINED3DLIGHT *)Light); + wined3d_mutex_lock(); + /* Note: D3DLIGHT7 is compatible with struct wined3d_light. */ + rc = wined3d_device_get_light(This->wined3d_device, LightIndex, (struct wined3d_light *)Light); + wined3d_mutex_unlock(); /* Translate the result. WineD3D returns other values than D3D7 */ - LeaveCriticalSection(&ddraw_cs); return hr_ddraw_from_wined3d(rc); } @@ -5393,14 +5637,15 @@ IDirect3DDeviceImpl_7_GetLight_FPUPreserve(IDirect3DDevice7 *iface, static HRESULT IDirect3DDeviceImpl_7_BeginStateBlock(IDirect3DDevice7 *iface) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p.\n", iface); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_device_begin_stateblock(This->wined3d_device); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr_ddraw_from_wined3d(hr); } @@ -5444,7 +5689,7 @@ static HRESULT IDirect3DDeviceImpl_7_EndStateBlock(IDirect3DDevice7 *iface, DWORD *BlockHandle) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); struct wined3d_stateblock *wined3d_sb; HRESULT hr; DWORD h; @@ -5457,13 +5702,13 @@ IDirect3DDeviceImpl_7_EndStateBlock(IDirect3DDevice7 *iface, return DDERR_INVALIDPARAMS; } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_device_end_stateblock(This->wined3d_device, &wined3d_sb); if (FAILED(hr)) { WARN("Failed to end stateblock, hr %#x.\n", hr); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); *BlockHandle = 0; return hr_ddraw_from_wined3d(hr); } @@ -5473,12 +5718,12 @@ IDirect3DDeviceImpl_7_EndStateBlock(IDirect3DDevice7 *iface, { ERR("Failed to allocate a stateblock handle.\n"); wined3d_stateblock_decref(wined3d_sb); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); *BlockHandle = 0; return DDERR_OUTOFMEMORY; } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); *BlockHandle = h + 1; return hr_ddraw_from_wined3d(hr); @@ -5526,16 +5771,17 @@ static HRESULT IDirect3DDeviceImpl_7_PreLoad(IDirect3DDevice7 *iface, IDirectDrawSurface7 *Texture) { - IDirectDrawSurfaceImpl *surf = (IDirectDrawSurfaceImpl *)Texture; + IDirectDrawSurfaceImpl *surf = unsafe_impl_from_IDirectDrawSurface7(Texture); TRACE("iface %p, texture %p.\n", iface, Texture); if(!Texture) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); wined3d_surface_preload(surf->wined3d_surface); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } @@ -5577,24 +5823,23 @@ static HRESULT IDirect3DDeviceImpl_7_ApplyStateBlock(IDirect3DDevice7 *iface, DWORD BlockHandle) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); struct wined3d_stateblock *wined3d_sb; HRESULT hr; TRACE("iface %p, stateblock %#x.\n", iface, BlockHandle); - EnterCriticalSection(&ddraw_cs); - + wined3d_mutex_lock(); wined3d_sb = ddraw_get_object(&This->handle_table, BlockHandle - 1, DDRAW_HANDLE_STATEBLOCK); if (!wined3d_sb) { WARN("Invalid stateblock handle.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3DERR_INVALIDSTATEBLOCK; } hr = wined3d_stateblock_apply(wined3d_sb); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr_ddraw_from_wined3d(hr); } @@ -5640,24 +5885,24 @@ static HRESULT IDirect3DDeviceImpl_7_CaptureStateBlock(IDirect3DDevice7 *iface, DWORD BlockHandle) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); struct wined3d_stateblock *wined3d_sb; HRESULT hr; TRACE("iface %p, stateblock %#x.\n", iface, BlockHandle); - EnterCriticalSection(&ddraw_cs); - + wined3d_mutex_lock(); wined3d_sb = ddraw_get_object(&This->handle_table, BlockHandle - 1, DDRAW_HANDLE_STATEBLOCK); if (!wined3d_sb) { WARN("Invalid stateblock handle.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3DERR_INVALIDSTATEBLOCK; } hr = wined3d_stateblock_capture(wined3d_sb); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr_ddraw_from_wined3d(hr); } @@ -5701,19 +5946,19 @@ static HRESULT IDirect3DDeviceImpl_7_DeleteStateBlock(IDirect3DDevice7 *iface, DWORD BlockHandle) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); struct wined3d_stateblock *wined3d_sb; ULONG ref; TRACE("iface %p, stateblock %#x.\n", iface, BlockHandle); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); wined3d_sb = ddraw_free_handle(&This->handle_table, BlockHandle - 1, DDRAW_HANDLE_STATEBLOCK); if (!wined3d_sb) { WARN("Invalid stateblock handle.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3DERR_INVALIDSTATEBLOCK; } @@ -5722,7 +5967,8 @@ IDirect3DDeviceImpl_7_DeleteStateBlock(IDirect3DDevice7 *iface, ERR("Something is still holding stateblock %p (refcount %u).\n", wined3d_sb, ref); } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } @@ -5768,7 +6014,7 @@ IDirect3DDeviceImpl_7_CreateStateBlock(IDirect3DDevice7 *iface, D3DSTATEBLOCKTYPE Type, DWORD *BlockHandle) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); struct wined3d_stateblock *wined3d_sb; HRESULT hr; DWORD h; @@ -5786,14 +6032,14 @@ IDirect3DDeviceImpl_7_CreateStateBlock(IDirect3DDevice7 *iface, return DDERR_INVALIDPARAMS; } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); /* The D3DSTATEBLOCKTYPE enum is fine here. */ hr = wined3d_stateblock_create(This->wined3d_device, Type, &wined3d_sb); if (FAILED(hr)) { WARN("Failed to create stateblock, hr %#x.\n", hr); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr_ddraw_from_wined3d(hr); } @@ -5802,12 +6048,12 @@ IDirect3DDeviceImpl_7_CreateStateBlock(IDirect3DDevice7 *iface, { ERR("Failed to allocate stateblock handle.\n"); wined3d_stateblock_decref(wined3d_sb); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_OUTOFMEMORY; } *BlockHandle = h + 1; - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr_ddraw_from_wined3d(hr); } @@ -5862,24 +6108,24 @@ static BOOL is_mip_level_subset(IDirectDrawSurfaceImpl *dest, ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE; ddsd.ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL; - IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7 *)dest_level, &ddsd.ddsCaps, &temp); + IDirectDrawSurface7_GetAttachedSurface(&dest_level->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp); - if (dest_level != dest) IDirectDrawSurface7_Release((IDirectDrawSurface7 *)dest_level); + if (dest_level != dest) IDirectDrawSurface7_Release(&dest_level->IDirectDrawSurface7_iface); - dest_level = (IDirectDrawSurfaceImpl *)temp; + dest_level = unsafe_impl_from_IDirectDrawSurface7(temp); } ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE; ddsd.ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL; - IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7 *)src_level, &ddsd.ddsCaps, &temp); + IDirectDrawSurface7_GetAttachedSurface(&src_level->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp); - if (src_level != src) IDirectDrawSurface7_Release((IDirectDrawSurface7 *)src_level); + if (src_level != src) IDirectDrawSurface7_Release(&src_level->IDirectDrawSurface7_iface); - src_level = (IDirectDrawSurfaceImpl *)temp; + src_level = unsafe_impl_from_IDirectDrawSurface7(temp); } - if (src_level && src_level != src) IDirectDrawSurface7_Release((IDirectDrawSurface7 *)src_level); - if (dest_level && dest_level != dest) IDirectDrawSurface7_Release((IDirectDrawSurface7 *)dest_level); + if (src_level && src_level != src) IDirectDrawSurface7_Release(&src_level->IDirectDrawSurface7_iface); + if (dest_level && dest_level != dest) IDirectDrawSurface7_Release(&dest_level->IDirectDrawSurface7_iface); return !dest_level && levelFound; } @@ -5895,16 +6141,15 @@ static void copy_mipmap_chain(IDirect3DDeviceImpl *device, IDirectDrawSurface7 *temp; DDSURFACEDESC2 ddsd; POINT point; - RECT rect; + RECT src_rect; HRESULT hr; IDirectDrawPalette *pal = NULL, *pal_src = NULL; DWORD ckeyflag; DDCOLORKEY ddckey; - BOOL palette_missing = FALSE; /* Copy palette, if possible. */ - IDirectDrawSurface7_GetPalette((IDirectDrawSurface7 *)src, &pal_src); - IDirectDrawSurface7_GetPalette((IDirectDrawSurface7 *)dest, &pal); + IDirectDrawSurface7_GetPalette(&src->IDirectDrawSurface7_iface, &pal_src); + IDirectDrawSurface7_GetPalette(&dest->IDirectDrawSurface7_iface, &pal); if (pal_src != NULL && pal != NULL) { @@ -5914,23 +6159,17 @@ static void copy_mipmap_chain(IDirect3DDeviceImpl *device, IDirectDrawPalette_SetEntries(pal, 0, 0, 256, palent); } - if (dest->surface_desc.u4.ddpfPixelFormat.dwFlags & (DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2 | - DDPF_PALETTEINDEXED4 | DDPF_PALETTEINDEXED8 | DDPF_PALETTEINDEXEDTO8) && !pal) - { - palette_missing = TRUE; - } - if (pal) IDirectDrawPalette_Release(pal); if (pal_src) IDirectDrawPalette_Release(pal_src); /* Copy colorkeys, if present. */ for (ckeyflag = DDCKEY_DESTBLT; ckeyflag <= DDCKEY_SRCOVERLAY; ckeyflag <<= 1) { - hr = IDirectDrawSurface7_GetColorKey((IDirectDrawSurface7 *)src, ckeyflag, &ddckey); + hr = IDirectDrawSurface7_GetColorKey(&src->IDirectDrawSurface7_iface, ckeyflag, &ddckey); if (SUCCEEDED(hr)) { - IDirectDrawSurface7_SetColorKey((IDirectDrawSurface7 *)dest, ckeyflag, &ddckey); + IDirectDrawSurface7_SetColorKey(&dest->IDirectDrawSurface7_iface, ckeyflag, &ddckey); } } @@ -5938,57 +6177,49 @@ static void copy_mipmap_chain(IDirect3DDeviceImpl *device, dest_level = dest; point = *DestPoint; - rect = *SrcRect; + src_rect = *SrcRect; for (;src_level && dest_level;) { if (src_level->surface_desc.dwWidth == dest_level->surface_desc.dwWidth && src_level->surface_desc.dwHeight == dest_level->surface_desc.dwHeight) { - /* Try UpdateSurface that may perform a more direct OpenGL - * loading. But skip this if destination is paletted texture and - * has no palette. Some games like Sacrifice set palette after - * Load, and it is a waste of effort to try to load texture - * without palette and generates warnings in wined3d. */ - if (!palette_missing) - hr = wined3d_device_update_surface(device->wined3d_device, src_level->wined3d_surface, - &rect, dest_level->wined3d_surface, &point); + UINT src_w = src_rect.right - src_rect.left; + UINT src_h = src_rect.bottom - src_rect.top; + RECT dst_rect = {point.x, point.y, point.x + src_w, point.y + src_h}; - if (palette_missing || FAILED(hr)) - { - /* UpdateSurface may fail e.g. if dest is in system memory. Fall back to BltFast that is less strict. */ - wined3d_surface_bltfast(dest_level->wined3d_surface, point.x, point.y, - src_level->wined3d_surface, &rect, 0); - } + if (FAILED(hr = wined3d_surface_blt(dest_level->wined3d_surface, &dst_rect, + src_level->wined3d_surface, &src_rect, 0, NULL, WINED3D_TEXF_POINT))) + ERR("Blit failed, hr %#x.\n", hr); ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE; ddsd.ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL; - IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7 *)dest_level, &ddsd.ddsCaps, &temp); + IDirectDrawSurface7_GetAttachedSurface(&dest_level->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp); - if (dest_level != dest) IDirectDrawSurface7_Release((IDirectDrawSurface7 *)dest_level); + if (dest_level != dest) IDirectDrawSurface7_Release(&dest_level->IDirectDrawSurface7_iface); - dest_level = (IDirectDrawSurfaceImpl *)temp; + dest_level = unsafe_impl_from_IDirectDrawSurface7(temp); } ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE; ddsd.ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL; - IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7 *)src_level, &ddsd.ddsCaps, &temp); + IDirectDrawSurface7_GetAttachedSurface(&src_level->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp); - if (src_level != src) IDirectDrawSurface7_Release((IDirectDrawSurface7 *)src_level); + if (src_level != src) IDirectDrawSurface7_Release(&src_level->IDirectDrawSurface7_iface); - src_level = (IDirectDrawSurfaceImpl *)temp; + src_level = unsafe_impl_from_IDirectDrawSurface7(temp); point.x /= 2; point.y /= 2; - rect.top /= 2; - rect.left /= 2; - rect.right = (rect.right + 1) / 2; - rect.bottom = (rect.bottom + 1) / 2; + src_rect.top /= 2; + src_rect.left /= 2; + src_rect.right = (src_rect.right + 1) / 2; + src_rect.bottom = (src_rect.bottom + 1) / 2; } - if (src_level && src_level != src) IDirectDrawSurface7_Release((IDirectDrawSurface7 *)src_level); - if (dest_level && dest_level != dest) IDirectDrawSurface7_Release((IDirectDrawSurface7 *)dest_level); + if (src_level && src_level != src) IDirectDrawSurface7_Release(&src_level->IDirectDrawSurface7_iface); + if (dest_level && dest_level != dest) IDirectDrawSurface7_Release(&dest_level->IDirectDrawSurface7_iface); } /***************************************************************************** @@ -6024,9 +6255,9 @@ IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface, RECT *SrcRect, DWORD Flags) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; - IDirectDrawSurfaceImpl *dest = (IDirectDrawSurfaceImpl *)DestTex; - IDirectDrawSurfaceImpl *src = (IDirectDrawSurfaceImpl *)SrcTex; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); + IDirectDrawSurfaceImpl *dest = unsafe_impl_from_IDirectDrawSurface7(DestTex); + IDirectDrawSurfaceImpl *src = unsafe_impl_from_IDirectDrawSurface7(SrcTex); POINT destpoint; RECT srcrect; @@ -6036,7 +6267,7 @@ IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface, if( (!src) || (!dest) ) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if (SrcRect) srcrect = *SrcRect; else @@ -6064,7 +6295,7 @@ IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface, dest->surface_desc.dwWidth > src->surface_desc.dwWidth || dest->surface_desc.dwHeight > src->surface_desc.dwHeight) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } @@ -6072,7 +6303,7 @@ IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface, if (src->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_MIPMAPSUBLEVEL || dest->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_MIPMAPSUBLEVEL) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } @@ -6086,7 +6317,7 @@ IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface, if (!(dest->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP)) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } @@ -6109,7 +6340,7 @@ IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface, /* Destination mip levels must be subset of source mip levels. */ if (!is_mip_level_subset(dest_face, src_face)) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } } @@ -6122,15 +6353,15 @@ IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface, { ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE; ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | (src_face_flag << 1); - IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7 *)src, &ddsd.ddsCaps, &temp); + IDirectDrawSurface7_GetAttachedSurface(&src->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp); - if (src_face != src) IDirectDrawSurface7_Release((IDirectDrawSurface7 *)src_face); + if (src_face != src) IDirectDrawSurface7_Release(&src_face->IDirectDrawSurface7_iface); - src_face = (IDirectDrawSurfaceImpl *)temp; + src_face = unsafe_impl_from_IDirectDrawSurface7(temp); } else { - if (src_face != src) IDirectDrawSurface7_Release((IDirectDrawSurface7 *)src_face); + if (src_face != src) IDirectDrawSurface7_Release(&src_face->IDirectDrawSurface7_iface); src_face = NULL; } @@ -6140,15 +6371,15 @@ IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface, { ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE; ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | (dest_face_flag << 1); - IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7 *)dest, &ddsd.ddsCaps, &temp); + IDirectDrawSurface7_GetAttachedSurface(&dest->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp); - if (dest_face != dest) IDirectDrawSurface7_Release((IDirectDrawSurface7 *)dest_face); + if (dest_face != dest) IDirectDrawSurface7_Release(&dest_face->IDirectDrawSurface7_iface); - dest_face = (IDirectDrawSurfaceImpl *)temp; + dest_face = unsafe_impl_from_IDirectDrawSurface7(temp); } else { - if (dest_face != dest) IDirectDrawSurface7_Release((IDirectDrawSurface7 *)dest_face); + if (dest_face != dest) IDirectDrawSurface7_Release(&dest_face->IDirectDrawSurface7_iface); dest_face = NULL; } @@ -6159,18 +6390,18 @@ IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface, /* Native returns error if src faces are not subset of dest faces. */ if (src_face) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } } } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } else if (dest->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } @@ -6179,13 +6410,14 @@ IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface, /* Destination mip levels must be subset of source mip levels. */ if (!is_mip_level_subset(dest, src)) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } copy_mipmap_chain(This, dest, src, &destpoint, &srcrect); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } @@ -6239,14 +6471,15 @@ IDirect3DDeviceImpl_7_LightEnable(IDirect3DDevice7 *iface, DWORD LightIndex, BOOL Enable) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p, light_idx %u, enabled %#x.\n", iface, LightIndex, Enable); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_device_set_light_enable(This->wined3d_device, LightIndex, Enable); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr_ddraw_from_wined3d(hr); } @@ -6295,7 +6528,7 @@ IDirect3DDeviceImpl_7_GetLightEnable(IDirect3DDevice7 *iface, DWORD LightIndex, BOOL* Enable) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p, light_idx %u, enabled %p.\n", iface, LightIndex, Enable); @@ -6303,9 +6536,10 @@ IDirect3DDeviceImpl_7_GetLightEnable(IDirect3DDevice7 *iface, if(!Enable) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_device_get_light_enable(This->wined3d_device, LightIndex, Enable); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr_ddraw_from_wined3d(hr); } @@ -6354,7 +6588,7 @@ IDirect3DDeviceImpl_7_SetClipPlane(IDirect3DDevice7 *iface, DWORD Index, D3DVALUE* PlaneEquation) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p, idx %u, plane %p.\n", iface, Index, PlaneEquation); @@ -6362,9 +6596,10 @@ IDirect3DDeviceImpl_7_SetClipPlane(IDirect3DDevice7 *iface, if(!PlaneEquation) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_device_set_clip_plane(This->wined3d_device, Index, PlaneEquation); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -6411,7 +6646,7 @@ IDirect3DDeviceImpl_7_GetClipPlane(IDirect3DDevice7 *iface, DWORD Index, D3DVALUE* PlaneEquation) { - IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface; + IDirect3DDeviceImpl *This = impl_from_IDirect3DDevice7(iface); HRESULT hr; TRACE("iface %p, idx %u, plane %p.\n", iface, Index, PlaneEquation); @@ -6419,9 +6654,10 @@ IDirect3DDeviceImpl_7_GetClipPlane(IDirect3DDevice7 *iface, if(!PlaneEquation) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_device_get_clip_plane(This->wined3d_device, Index, PlaneEquation); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -6723,6 +6959,34 @@ static const struct IDirect3DDeviceVtbl d3d_device1_vtbl = IDirect3DDeviceImpl_1_GetDirect3D }; +IDirect3DDeviceImpl *unsafe_impl_from_IDirect3DDevice7(IDirect3DDevice7 *iface) +{ + if (!iface) return NULL; + assert((iface->lpVtbl == &d3d_device7_fpu_preserve_vtbl) || (iface->lpVtbl == &d3d_device7_fpu_setup_vtbl)); + return CONTAINING_RECORD(iface, IDirect3DDeviceImpl, IDirect3DDevice7_iface); +} + +IDirect3DDeviceImpl *unsafe_impl_from_IDirect3DDevice3(IDirect3DDevice3 *iface) +{ + if (!iface) return NULL; + assert(iface->lpVtbl == &d3d_device3_vtbl); + return CONTAINING_RECORD(iface, IDirect3DDeviceImpl, IDirect3DDevice3_iface); +} + +IDirect3DDeviceImpl *unsafe_impl_from_IDirect3DDevice2(IDirect3DDevice2 *iface) +{ + if (!iface) return NULL; + assert(iface->lpVtbl == &d3d_device2_vtbl); + return CONTAINING_RECORD(iface, IDirect3DDeviceImpl, IDirect3DDevice2_iface); +} + +IDirect3DDeviceImpl *unsafe_impl_from_IDirect3DDevice(IDirect3DDevice *iface) +{ + if (!iface) return NULL; + assert(iface->lpVtbl == &d3d_device1_vtbl); + return CONTAINING_RECORD(iface, IDirect3DDeviceImpl, IDirect3DDevice_iface); +} + /***************************************************************************** * IDirect3DDeviceImpl_UpdateDepthStencil * @@ -6733,41 +6997,47 @@ static const struct IDirect3DDeviceVtbl d3d_device1_vtbl = * The depth stencil state to set if creating the device * *****************************************************************************/ -WINED3DZBUFFERTYPE -IDirect3DDeviceImpl_UpdateDepthStencil(IDirect3DDeviceImpl *This) +enum wined3d_depth_buffer_type IDirect3DDeviceImpl_UpdateDepthStencil(IDirect3DDeviceImpl *This) { IDirectDrawSurface7 *depthStencil = NULL; IDirectDrawSurfaceImpl *dsi; static DDSCAPS2 depthcaps = { DDSCAPS_ZBUFFER, 0, 0, {0} }; - IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7 *)This->target, &depthcaps, &depthStencil); + IDirectDrawSurface7_GetAttachedSurface(&This->target->IDirectDrawSurface7_iface, &depthcaps, &depthStencil); if(!depthStencil) { TRACE("Setting wined3d depth stencil to NULL\n"); wined3d_device_set_depth_stencil(This->wined3d_device, NULL); - return WINED3DZB_FALSE; + return WINED3D_ZB_FALSE; } - dsi = (IDirectDrawSurfaceImpl *)depthStencil; + dsi = impl_from_IDirectDrawSurface7(depthStencil); TRACE("Setting wined3d depth stencil to %p (wined3d %p)\n", dsi, dsi->wined3d_surface); wined3d_device_set_depth_stencil(This->wined3d_device, dsi->wined3d_surface); IDirectDrawSurface7_Release(depthStencil); - return WINED3DZB_TRUE; + return WINED3D_ZB_TRUE; } HRESULT d3d_device_init(IDirect3DDeviceImpl *device, IDirectDrawImpl *ddraw, IDirectDrawSurfaceImpl *target) { + static const D3DMATRIX ident = + { + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f, + }; HRESULT hr; if (ddraw->cooperative_level & DDSCL_FPUPRESERVE) - device->lpVtbl = &d3d_device7_fpu_preserve_vtbl; + device->IDirect3DDevice7_iface.lpVtbl = &d3d_device7_fpu_preserve_vtbl; else - device->lpVtbl = &d3d_device7_fpu_setup_vtbl; + device->IDirect3DDevice7_iface.lpVtbl = &d3d_device7_fpu_setup_vtbl; - device->IDirect3DDevice3_vtbl = &d3d_device3_vtbl; - device->IDirect3DDevice2_vtbl = &d3d_device2_vtbl; - device->IDirect3DDevice_vtbl = &d3d_device1_vtbl; + device->IDirect3DDevice3_iface.lpVtbl = &d3d_device3_vtbl; + device->IDirect3DDevice2_iface.lpVtbl = &d3d_device2_vtbl; + device->IDirect3DDevice_iface.lpVtbl = &d3d_device1_vtbl; device->ref = 1; device->ddraw = ddraw; device->target = target; @@ -6780,10 +7050,12 @@ HRESULT d3d_device_init(IDirect3DDeviceImpl *device, IDirectDrawImpl *ddraw, IDi } device->legacyTextureBlending = FALSE; + device->legacy_projection = ident; + device->legacy_clipspace = ident; /* Create an index buffer, it's needed for indexed drawing */ hr = wined3d_buffer_create_ib(ddraw->wined3d_device, 0x40000 /* Length. Don't know how long it should be */, - WINED3DUSAGE_DYNAMIC /* Usage */, WINED3DPOOL_DEFAULT, NULL, + WINED3DUSAGE_DYNAMIC /* Usage */, WINED3D_POOL_DEFAULT, NULL, &ddraw_null_wined3d_parent_ops, &device->indexbuffer); if (FAILED(hr)) { @@ -6815,12 +7087,11 @@ HRESULT d3d_device_init(IDirect3DDeviceImpl *device, IDirectDrawImpl *ddraw, IDi * * In most cases, those surfaces are the same anyway, but this will simply * add another ref which is released when the device is destroyed. */ - IDirectDrawSurface7_AddRef((IDirectDrawSurface7 *)target); - IDirectDrawSurface7_AddRef((IDirectDrawSurface7 *)ddraw->d3d_target); + IDirectDrawSurface7_AddRef(&target->IDirectDrawSurface7_iface); ddraw->d3ddevice = device; - wined3d_device_set_render_state(ddraw->wined3d_device, WINED3DRS_ZENABLE, + wined3d_device_set_render_state(ddraw->wined3d_device, WINED3D_RS_ZENABLE, IDirect3DDeviceImpl_UpdateDepthStencil(device)); return D3D_OK; diff --git a/reactos/dll/directx/wine/ddraw/executebuffer.c b/reactos/dll/directx/wine/ddraw/executebuffer.c index 86a3aa9e581..74a4984e624 100644 --- a/reactos/dll/directx/wine/ddraw/executebuffer.c +++ b/reactos/dll/directx/wine/ddraw/executebuffer.c @@ -156,8 +156,8 @@ HRESULT d3d_execute_buffer_execute(IDirect3DExecuteBufferImpl *This, /* IDirect3DDevices have color keying always enabled - * enable it before drawing. This overwrites any ALPHA* * render state. */ - wined3d_device_set_render_state(lpDevice->wined3d_device, WINED3DRS_COLORKEYENABLE, 1); - IDirect3DDevice7_DrawIndexedPrimitive((IDirect3DDevice7 *)lpDevice, + wined3d_device_set_render_state(lpDevice->wined3d_device, WINED3D_RS_COLORKEYENABLE, 1); + IDirect3DDevice7_DrawIndexedPrimitive(&lpDevice->IDirect3DDevice7_iface, D3DPT_TRIANGLELIST, D3DFVF_TLVERTEX, tl_vx, 0, This->indices, count * 3, 0); } break; @@ -216,7 +216,7 @@ HRESULT d3d_execute_buffer_execute(IDirect3DExecuteBufferImpl *This, lpDevice->view = ci->u2.dwArg[0]; if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_PROJECTION) lpDevice->proj = ci->u2.dwArg[0]; - IDirect3DDevice7_SetTransform((IDirect3DDevice7 *)lpDevice, + IDirect3DDevice7_SetTransform(&lpDevice->IDirect3DDevice7_iface, ci->u1.dtstTransformStateType, m); } @@ -283,7 +283,7 @@ HRESULT d3d_execute_buffer_execute(IDirect3DExecuteBufferImpl *This, break; } - IDirect3DDevice7_SetRenderState((IDirect3DDevice7 *)lpDevice, rs, ci->u2.dwArg[0]); + IDirect3DDevice7_SetRenderState(&lpDevice->IDirect3DDevice7_iface, rs, ci->u2.dwArg[0]); } instr += size; @@ -292,7 +292,7 @@ HRESULT d3d_execute_buffer_execute(IDirect3DExecuteBufferImpl *This, case D3DOP_STATERENDER: { int i; - IDirect3DDevice2 *d3d_device2 = (IDirect3DDevice2 *)&lpDevice->IDirect3DDevice2_vtbl; + IDirect3DDevice2 *d3d_device2 = &lpDevice->IDirect3DDevice2_iface; TRACE("STATERENDER (%d)\n", count); for (i = 0; i < count; i++) { @@ -314,13 +314,13 @@ HRESULT d3d_execute_buffer_execute(IDirect3DExecuteBufferImpl *This, TRACE("PROCESSVERTICES (%d)\n", count); /* Get the transform and world matrix */ - /* Note: D3DMATRIX is compatible with WINED3DMATRIX */ + /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */ wined3d_device_get_transform(lpDevice->wined3d_device, - D3DTRANSFORMSTATE_VIEW, (WINED3DMATRIX *)&view_mat); + D3DTRANSFORMSTATE_VIEW, (struct wined3d_matrix *)&view_mat); wined3d_device_get_transform(lpDevice->wined3d_device, - D3DTRANSFORMSTATE_PROJECTION, (WINED3DMATRIX *)&proj_mat); + D3DTRANSFORMSTATE_PROJECTION, (struct wined3d_matrix *)&proj_mat); wined3d_device_get_transform(lpDevice->wined3d_device, - WINED3DTS_WORLDMATRIX(0), (WINED3DMATRIX *)&world_mat); + WINED3D_TS_WORLD_MATRIX(0), (struct wined3d_matrix *)&world_mat); for (i = 0; i < count; i++) { LPD3DPROCESSVERTICES ci = (LPD3DPROCESSVERTICES) instr; @@ -547,6 +547,11 @@ end_of_buffer: return D3D_OK; } +static inline IDirect3DExecuteBufferImpl *impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface) +{ + return CONTAINING_RECORD(iface, IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer_iface); +} + /***************************************************************************** * IDirect3DExecuteBuffer::QueryInterface * @@ -598,10 +603,9 @@ IDirect3DExecuteBufferImpl_QueryInterface(IDirect3DExecuteBuffer *iface, * The new refcount * *****************************************************************************/ -static ULONG WINAPI -IDirect3DExecuteBufferImpl_AddRef(IDirect3DExecuteBuffer *iface) +static ULONG WINAPI IDirect3DExecuteBufferImpl_AddRef(IDirect3DExecuteBuffer *iface) { - IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface; + IDirect3DExecuteBufferImpl *This = impl_from_IDirect3DExecuteBuffer(iface); ULONG ref = InterlockedIncrement(&This->ref); TRACE("%p increasing refcount to %u.\n", This, ref); @@ -618,10 +622,9 @@ IDirect3DExecuteBufferImpl_AddRef(IDirect3DExecuteBuffer *iface) * The new refcount * *****************************************************************************/ -static ULONG WINAPI -IDirect3DExecuteBufferImpl_Release(IDirect3DExecuteBuffer *iface) +static ULONG WINAPI IDirect3DExecuteBufferImpl_Release(IDirect3DExecuteBuffer *iface) { - IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface; + IDirect3DExecuteBufferImpl *This = impl_from_IDirect3DExecuteBuffer(iface); ULONG ref = InterlockedDecrement(&This->ref); TRACE("%p decreasing refcount to %u.\n", This, ref); @@ -669,11 +672,10 @@ static HRESULT WINAPI IDirect3DExecuteBufferImpl_Initialize(IDirect3DExecuteBuff * This implementation always returns D3D_OK * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DExecuteBufferImpl_Lock(IDirect3DExecuteBuffer *iface, - D3DEXECUTEBUFFERDESC *lpDesc) +static HRESULT WINAPI IDirect3DExecuteBufferImpl_Lock(IDirect3DExecuteBuffer *iface, + D3DEXECUTEBUFFERDESC *lpDesc) { - IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface; + IDirect3DExecuteBufferImpl *This = impl_from_IDirect3DExecuteBuffer(iface); DWORD dwSize; TRACE("iface %p, desc %p.\n", iface, lpDesc); @@ -719,11 +721,10 @@ static HRESULT WINAPI IDirect3DExecuteBufferImpl_Unlock(IDirect3DExecuteBuffer * * DDERR_OUTOFMEMORY if the vertex buffer allocation failed * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DExecuteBufferImpl_SetExecuteData(IDirect3DExecuteBuffer *iface, - D3DEXECUTEDATA *lpData) +static HRESULT WINAPI IDirect3DExecuteBufferImpl_SetExecuteData(IDirect3DExecuteBuffer *iface, + D3DEXECUTEDATA *lpData) { - IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface; + IDirect3DExecuteBufferImpl *This = impl_from_IDirect3DExecuteBuffer(iface); DWORD nbvert; TRACE("iface %p, data %p.\n", iface, lpData); @@ -755,11 +756,10 @@ IDirect3DExecuteBufferImpl_SetExecuteData(IDirect3DExecuteBuffer *iface, * D3D_OK on success * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DExecuteBufferImpl_GetExecuteData(IDirect3DExecuteBuffer *iface, - D3DEXECUTEDATA *lpData) +static HRESULT WINAPI IDirect3DExecuteBufferImpl_GetExecuteData(IDirect3DExecuteBuffer *iface, + D3DEXECUTEDATA *lpData) { - IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface; + IDirect3DExecuteBufferImpl *This = impl_from_IDirect3DExecuteBuffer(iface); DWORD dwSize; TRACE("iface %p, data %p.\n", iface, lpData); @@ -839,7 +839,7 @@ static const struct IDirect3DExecuteBufferVtbl d3d_execute_buffer_vtbl = HRESULT d3d_execute_buffer_init(IDirect3DExecuteBufferImpl *execute_buffer, IDirect3DDeviceImpl *device, D3DEXECUTEBUFFERDESC *desc) { - execute_buffer->lpVtbl = &d3d_execute_buffer_vtbl; + execute_buffer->IDirect3DExecuteBuffer_iface.lpVtbl = &d3d_execute_buffer_vtbl; execute_buffer->ref = 1; execute_buffer->d3ddev = device; @@ -870,3 +870,12 @@ HRESULT d3d_execute_buffer_init(IDirect3DExecuteBufferImpl *execute_buffer, return D3D_OK; } + +IDirect3DExecuteBufferImpl *unsafe_impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &d3d_execute_buffer_vtbl); + + return impl_from_IDirect3DExecuteBuffer(iface); +} diff --git a/reactos/dll/directx/wine/ddraw/light.c b/reactos/dll/directx/wine/ddraw/light.c index a6a3cad8b94..172ac23e6b1 100644 --- a/reactos/dll/directx/wine/ddraw/light.c +++ b/reactos/dll/directx/wine/ddraw/light.c @@ -41,7 +41,7 @@ static void light_update(IDirect3DLightImpl *light) if (!light->active_viewport || !light->active_viewport->active_device) return; device = light->active_viewport->active_device; - IDirect3DDevice7_SetLight((IDirect3DDevice7 *)device, light->dwLightIndex, &light->light7); + IDirect3DDevice7_SetLight(&device->IDirect3DDevice7_iface, light->dwLightIndex, &light->light7); } /***************************************************************************** @@ -62,7 +62,7 @@ void light_activate(IDirect3DLightImpl *light) light_update(light); if (!(light->light.dwFlags & D3DLIGHT_ACTIVE)) { - IDirect3DDevice7_LightEnable((IDirect3DDevice7 *)device, light->dwLightIndex, TRUE); + IDirect3DDevice7_LightEnable(&device->IDirect3DDevice7_iface, light->dwLightIndex, TRUE); light->light.dwFlags |= D3DLIGHT_ACTIVE; } } @@ -86,14 +86,15 @@ void light_deactivate(IDirect3DLightImpl *light) /* If was not active, activate it */ if (light->light.dwFlags & D3DLIGHT_ACTIVE) { - IDirect3DDevice7_LightEnable((IDirect3DDevice7 *)device, light->dwLightIndex, FALSE); + IDirect3DDevice7_LightEnable(&device->IDirect3DDevice7_iface, light->dwLightIndex, FALSE); light->light.dwFlags &= ~D3DLIGHT_ACTIVE; } } -/***************************************************************************** - * IUnknown Methods. - *****************************************************************************/ +static inline IDirect3DLightImpl *impl_from_IDirect3DLight(IDirect3DLight *iface) +{ + return CONTAINING_RECORD(iface, IDirect3DLightImpl, IDirect3DLight_iface); +} /***************************************************************************** * IDirect3DLight::QueryInterface @@ -116,19 +117,9 @@ static HRESULT WINAPI IDirect3DLightImpl_QueryInterface(IDirect3DLight *iface, R return E_NOINTERFACE; } -/***************************************************************************** - * IDirect3DLight::AddRef - * - * Increases the refcount by 1 - * - * Returns: - * The new refcount - * - *****************************************************************************/ -static ULONG WINAPI -IDirect3DLightImpl_AddRef(IDirect3DLight *iface) +static ULONG WINAPI IDirect3DLightImpl_AddRef(IDirect3DLight *iface) { - IDirect3DLightImpl *This = (IDirect3DLightImpl *)iface; + IDirect3DLightImpl *This = impl_from_IDirect3DLight(iface); ULONG ref = InterlockedIncrement(&This->ref); TRACE("%p increasing refcount to %u.\n", This, ref); @@ -136,20 +127,9 @@ IDirect3DLightImpl_AddRef(IDirect3DLight *iface) return ref; } -/***************************************************************************** - * IDirect3DLight::Release - * - * Reduces the refcount by one. If the refcount falls to 0, the object - * is destroyed - * - * Returns: - * The new refcount - * - *****************************************************************************/ -static ULONG WINAPI -IDirect3DLightImpl_Release(IDirect3DLight *iface) +static ULONG WINAPI IDirect3DLightImpl_Release(IDirect3DLight *iface) { - IDirect3DLightImpl *This = (IDirect3DLightImpl *)iface; + IDirect3DLightImpl *This = impl_from_IDirect3DLight(iface); ULONG ref = InterlockedDecrement(&This->ref); TRACE("%p decreasing refcount to %u.\n", This, ref); @@ -207,12 +187,10 @@ static const float zero_value[] = { 0.0, 0.0, 0.0, 0.0 }; -static HRESULT WINAPI -IDirect3DLightImpl_SetLight(IDirect3DLight *iface, - D3DLIGHT *lpLight) +static HRESULT WINAPI IDirect3DLightImpl_SetLight(IDirect3DLight *iface, D3DLIGHT *lpLight) { - IDirect3DLightImpl *This = (IDirect3DLightImpl *)iface; - LPD3DLIGHT7 light7 = &(This->light7); + IDirect3DLightImpl *This = impl_from_IDirect3DLight(iface); + LPD3DLIGHT7 light7 = &This->light7; TRACE("iface %p, light %p.\n", iface, lpLight); @@ -246,11 +224,12 @@ IDirect3DLightImpl_SetLight(IDirect3DLight *iface, light7->dvTheta = lpLight->dvTheta; light7->dvPhi = lpLight->dvPhi; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); memcpy(&This->light, lpLight, lpLight->dwSize); if (This->light.dwFlags & D3DLIGHT_ACTIVE) light_update(This); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } @@ -266,11 +245,9 @@ IDirect3DLightImpl_SetLight(IDirect3DLight *iface, * D3D_OK on success * DDERR_INVALIDPARAMS if Light is NULL *****************************************************************************/ -static HRESULT WINAPI -IDirect3DLightImpl_GetLight(IDirect3DLight *iface, - D3DLIGHT *lpLight) +static HRESULT WINAPI IDirect3DLightImpl_GetLight(IDirect3DLight *iface, D3DLIGHT *lpLight) { - IDirect3DLightImpl *This = (IDirect3DLightImpl *)iface; + IDirect3DLightImpl *This = impl_from_IDirect3DLight(iface); TRACE("iface %p, light %p.\n", iface, lpLight); @@ -280,9 +257,9 @@ IDirect3DLightImpl_GetLight(IDirect3DLight *iface, dump_light(&This->light); } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); memcpy(lpLight, &This->light, lpLight->dwSize); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DD_OK; } @@ -301,7 +278,16 @@ static const struct IDirect3DLightVtbl d3d_light_vtbl = void d3d_light_init(IDirect3DLightImpl *light, IDirectDrawImpl *ddraw) { - light->lpVtbl = &d3d_light_vtbl; + light->IDirect3DLight_iface.lpVtbl = &d3d_light_vtbl; light->ref = 1; light->ddraw = ddraw; } + +IDirect3DLightImpl *unsafe_impl_from_IDirect3DLight(IDirect3DLight *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &d3d_light_vtbl); + + return impl_from_IDirect3DLight(iface); +} diff --git a/reactos/dll/directx/wine/ddraw/main.c b/reactos/dll/directx/wine/ddraw/main.c index 875e1947f8d..9d706784466 100644 --- a/reactos/dll/directx/wine/ddraw/main.c +++ b/reactos/dll/directx/wine/ddraw/main.c @@ -29,6 +29,7 @@ #define DDRAW_INIT_GUID #include "ddraw_private.h" +#include "rpcproxy.h" #include "wine/exception.h" #include "winreg.h" @@ -36,21 +37,11 @@ WINE_DEFAULT_DEBUG_CHANNEL(ddraw); /* The configured default surface */ -WINED3DSURFTYPE DefaultSurfaceType = SURFACE_UNKNOWN; +WINED3DSURFTYPE DefaultSurfaceType = SURFACE_OPENGL; - - -/* DDraw list and critical section */ static struct list global_ddraw_list = LIST_INIT(global_ddraw_list); -static CRITICAL_SECTION_DEBUG ddraw_cs_debug = -{ - 0, 0, &ddraw_cs, - { &ddraw_cs_debug.ProcessLocksList, - &ddraw_cs_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": ddraw_cs") } -}; -CRITICAL_SECTION ddraw_cs = { &ddraw_cs_debug, -1, 0, 0, 0, 0 }; +static HINSTANCE instance; /* value of ForceRefreshRate */ DWORD force_refresh_rate = 0; @@ -195,7 +186,7 @@ DDRAW_Create(const GUID *guid, IUnknown *UnkOuter, REFIID iid) { - WINED3DDEVTYPE devicetype; + enum wined3d_device_type device_type; IDirectDrawImpl *This; HRESULT hr; @@ -213,15 +204,15 @@ DDRAW_Create(const GUID *guid, * WineD3D always uses OpenGL for D3D rendering. One could make it request * indirect rendering */ - devicetype = WINED3DDEVTYPE_REF; + device_type = WINED3D_DEVICE_TYPE_REF; } else if(guid == (GUID *) DDCREATE_HARDWAREONLY) { - devicetype = WINED3DDEVTYPE_HAL; + device_type = WINED3D_DEVICE_TYPE_HAL; } else { - devicetype = 0; + device_type = 0; } /* DDraw doesn't support aggregation, according to msdn */ @@ -236,7 +227,7 @@ DDRAW_Create(const GUID *guid, return E_OUTOFMEMORY; } - hr = ddraw_init(This, devicetype); + hr = ddraw_init(This, device_type); if (FAILED(hr)) { WARN("Failed to initialize ddraw object, hr %#x.\n", hr); @@ -271,9 +262,17 @@ DirectDrawCreate(GUID *GUID, TRACE("driver_guid %s, ddraw %p, outer_unknown %p.\n", debugstr_guid(GUID), DD, UnkOuter); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = DDRAW_Create(GUID, (void **) DD, UnkOuter, &IID_IDirectDraw); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + + if (SUCCEEDED(hr)) + { + hr = IDirectDraw_Initialize(*DD, GUID); + if (FAILED(hr)) + IDirectDraw_Release(*DD); + } + return hr; } @@ -287,22 +286,31 @@ DirectDrawCreate(GUID *GUID, * ***********************************************************************/ HRESULT WINAPI DECLSPEC_HOTPATCH -DirectDrawCreateEx(GUID *GUID, - LPVOID *DD, +DirectDrawCreateEx(GUID *guid, + LPVOID *dd, REFIID iid, IUnknown *UnkOuter) { HRESULT hr; TRACE("driver_guid %s, ddraw %p, interface_iid %s, outer_unknown %p.\n", - debugstr_guid(GUID), DD, debugstr_guid(iid), UnkOuter); + debugstr_guid(guid), dd, debugstr_guid(iid), UnkOuter); if (!IsEqualGUID(iid, &IID_IDirectDraw7)) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); - hr = DDRAW_Create(GUID, DD, UnkOuter, iid); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); + hr = DDRAW_Create(guid, dd, UnkOuter, iid); + wined3d_mutex_unlock(); + + if (SUCCEEDED(hr)) + { + IDirectDraw7 *ddraw7 = *(IDirectDraw7 **)dd; + hr = IDirectDraw7_Initialize(ddraw7, guid); + if (FAILED(hr)) + IDirectDraw7_Release(ddraw7); + } + return hr; } @@ -448,9 +456,10 @@ CF_CreateDirectDraw(IUnknown* UnkOuter, REFIID iid, TRACE("outer_unknown %p, riid %s, object %p.\n", UnkOuter, debugstr_guid(iid), obj); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = DDRAW_Create(NULL, obj, UnkOuter, iid); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -477,18 +486,19 @@ CF_CreateDirectDrawClipper(IUnknown* UnkOuter, REFIID riid, TRACE("outer_unknown %p, riid %s, object %p.\n", UnkOuter, debugstr_guid(riid), obj); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = DirectDrawCreateClipper(0, &Clip, UnkOuter); if (hr != DD_OK) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } hr = IDirectDrawClipper_QueryInterface(Clip, riid, obj); IDirectDrawClipper_Release(Clip); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -714,6 +724,23 @@ HRESULT WINAPI DllCanUnloadNow(void) return S_FALSE; } + +/*********************************************************************** + * DllRegisterServer (DDRAW.@) + */ +HRESULT WINAPI DllRegisterServer(void) +{ + return __wine_register_resources( instance ); +} + +/*********************************************************************** + * DllUnregisterServer (DDRAW.@) + */ +HRESULT WINAPI DllUnregisterServer(void) +{ + return __wine_unregister_resources( instance ); +} + /******************************************************************************* * DestroyCallback * @@ -733,11 +760,18 @@ DestroyCallback(IDirectDrawSurface7 *surf, DDSURFACEDESC2 *desc, void *context) { - IDirectDrawSurfaceImpl *Impl = (IDirectDrawSurfaceImpl *)surf; - ULONG ref; + IDirectDrawSurfaceImpl *Impl = impl_from_IDirectDrawSurface7(surf); + ULONG ref7, ref4, ref3, ref2, ref1, gamma_count, iface_count; - ref = IDirectDrawSurface7_Release(surf); /* For the EnumSurfaces */ - WARN("Surface %p has an reference count of %d\n", Impl, ref); + ref7 = IDirectDrawSurface7_Release(surf); /* For the EnumSurfaces */ + ref4 = Impl->ref4; + ref3 = Impl->ref3; + ref2 = Impl->ref2; + ref1 = Impl->ref1; + gamma_count = Impl->gamma_count; + + WARN("Surface %p has an reference counts of 7: %u 4: %u 3: %u 2: %u 1: %u gamma: %u\n", + Impl, ref7, ref4, ref3, ref2, ref1, gamma_count); /* Skip surfaces which are attached somewhere or which are * part of a complex compound. They will get released when destroying @@ -747,7 +781,8 @@ DestroyCallback(IDirectDrawSurface7 *surf, return DDENUMRET_OK; /* Destroy the surface */ - while(ref) ref = IDirectDrawSurface7_Release(surf); + iface_count = ddraw_surface_release_iface(Impl); + while (iface_count) iface_count = ddraw_surface_release_iface(Impl); return DDENUMRET_OK; } @@ -880,6 +915,7 @@ DllMain(HINSTANCE hInstDLL, RegCloseKey( hkey ); } + instance = hInstDLL; DisableThreadLibraryCalls(hInstDLL); } else if (Reason == DLL_PROCESS_DETACH) @@ -902,7 +938,6 @@ DllMain(HINSTANCE hInstDLL, /* Add references to each interface to avoid freeing them unexpectedly */ IDirectDraw_AddRef(&ddraw->IDirectDraw_iface); IDirectDraw2_AddRef(&ddraw->IDirectDraw2_iface); - IDirectDraw3_AddRef(&ddraw->IDirectDraw3_iface); IDirectDraw4_AddRef(&ddraw->IDirectDraw4_iface); IDirectDraw7_AddRef(&ddraw->IDirectDraw7_iface); @@ -913,9 +948,15 @@ DllMain(HINSTANCE hInstDLL, if(ddraw->d3ddevice) { WARN("DDraw %p has d3ddevice %p attached\n", ddraw, ddraw->d3ddevice); - while(IDirect3DDevice7_Release((IDirect3DDevice7 *)ddraw->d3ddevice)); + while(IDirect3DDevice7_Release(&ddraw->d3ddevice->IDirect3DDevice7_iface)); } + /* Destroy the swapchain after any 3D device. The 3D device + * cleanup code needs a swapchain. Specifically, it tries to + * set the current render target to the front buffer. */ + if (ddraw->wined3d_swapchain) + ddraw_destroy_swapchain(ddraw); + /* Try to release the objects * Do an EnumSurfaces to find any hanging surfaces */ @@ -929,16 +970,14 @@ DllMain(HINSTANCE hInstDLL, ERR("(%p) EnumSurfaces failed, prepare for trouble\n", ddraw); } - /* Check the surface count */ - if(ddraw->surfaces > 0) - ERR("DDraw %p still has %d surfaces attached\n", ddraw, ddraw->surfaces); + if (!list_empty(&ddraw->surface_list)) + ERR("DDraw %p still has surfaces attached.\n", ddraw); /* Release all hanging references to destroy the objects. This * restores the screen mode too */ while(IDirectDraw_Release(&ddraw->IDirectDraw_iface)); while(IDirectDraw2_Release(&ddraw->IDirectDraw2_iface)); - while(IDirectDraw3_Release(&ddraw->IDirectDraw3_iface)); while(IDirectDraw4_Release(&ddraw->IDirectDraw4_iface)); while(IDirectDraw7_Release(&ddraw->IDirectDraw7_iface)); } diff --git a/reactos/dll/directx/wine/ddraw/material.c b/reactos/dll/directx/wine/ddraw/material.c index e137bfcbed5..7b3b7026793 100644 --- a/reactos/dll/directx/wine/ddraw/material.c +++ b/reactos/dll/directx/wine/ddraw/material.c @@ -31,14 +31,19 @@ static void dump_material(const D3DMATERIAL *mat) TRACE(" dwSize : %d\n", mat->dwSize); } -static inline IDirect3DMaterialImpl *material_from_material1(IDirect3DMaterial *iface) +static inline IDirect3DMaterialImpl *impl_from_IDirect3DMaterial(IDirect3DMaterial *iface) { - return (IDirect3DMaterialImpl *)((char*)iface - FIELD_OFFSET(IDirect3DMaterialImpl, IDirect3DMaterial_vtbl)); + return CONTAINING_RECORD(iface, IDirect3DMaterialImpl, IDirect3DMaterial_iface); } -static inline IDirect3DMaterialImpl *material_from_material2(IDirect3DMaterial2 *iface) +static inline IDirect3DMaterialImpl *impl_from_IDirect3DMaterial2(IDirect3DMaterial2 *iface) { - return (IDirect3DMaterialImpl *)((char*)iface - FIELD_OFFSET(IDirect3DMaterialImpl, IDirect3DMaterial2_vtbl)); + return CONTAINING_RECORD(iface, IDirect3DMaterialImpl, IDirect3DMaterial2_iface); +} + +static inline IDirect3DMaterialImpl *impl_from_IDirect3DMaterial3(IDirect3DMaterial3 *iface) +{ + return CONTAINING_RECORD(iface, IDirect3DMaterialImpl, IDirect3DMaterial3_iface); } /***************************************************************************** @@ -60,12 +65,10 @@ static inline IDirect3DMaterialImpl *material_from_material2(IDirect3DMaterial2 * E_NOINTERFACE if the requested interface wasn't found * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DMaterialImpl_QueryInterface(IDirect3DMaterial3 *iface, - REFIID riid, - LPVOID* obp) +static HRESULT WINAPI IDirect3DMaterialImpl_QueryInterface(IDirect3DMaterial3 *iface, REFIID riid, + void **obp) { - IDirect3DMaterialImpl *This = (IDirect3DMaterialImpl *)iface; + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial3(iface); TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obp); @@ -78,19 +81,19 @@ IDirect3DMaterialImpl_QueryInterface(IDirect3DMaterial3 *iface, return S_OK; } if ( IsEqualGUID( &IID_IDirect3DMaterial, riid ) ) { - IDirect3DMaterial_AddRef((IDirect3DMaterial *)&This->IDirect3DMaterial_vtbl); - *obp = &This->IDirect3DMaterial_vtbl; + IDirect3DMaterial_AddRef(&This->IDirect3DMaterial_iface); + *obp = &This->IDirect3DMaterial_iface; TRACE(" Creating IDirect3DMaterial interface %p\n", *obp); return S_OK; } if ( IsEqualGUID( &IID_IDirect3DMaterial2, riid ) ) { - IDirect3DMaterial_AddRef((IDirect3DMaterial2 *)&This->IDirect3DMaterial2_vtbl); - *obp = &This->IDirect3DMaterial2_vtbl; + IDirect3DMaterial_AddRef(&This->IDirect3DMaterial2_iface); + *obp = &This->IDirect3DMaterial2_iface; TRACE(" Creating IDirect3DMaterial2 interface %p\n", *obp); return S_OK; } if ( IsEqualGUID( &IID_IDirect3DMaterial3, riid ) ) { - IDirect3DMaterial3_AddRef((IDirect3DMaterial3 *)This); + IDirect3DMaterial3_AddRef(&This->IDirect3DMaterial3_iface); *obp = This; TRACE(" Creating IDirect3DMaterial3 interface %p\n", *obp); return S_OK; @@ -108,10 +111,9 @@ IDirect3DMaterialImpl_QueryInterface(IDirect3DMaterial3 *iface, * The new refcount * *****************************************************************************/ -static ULONG WINAPI -IDirect3DMaterialImpl_AddRef(IDirect3DMaterial3 *iface) +static ULONG WINAPI IDirect3DMaterialImpl_AddRef(IDirect3DMaterial3 *iface) { - IDirect3DMaterialImpl *This = (IDirect3DMaterialImpl *)iface; + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial3(iface); ULONG ref = InterlockedIncrement(&This->ref); TRACE("%p increasing refcount to %u.\n", This, ref); @@ -129,10 +131,9 @@ IDirect3DMaterialImpl_AddRef(IDirect3DMaterial3 *iface) * The new refcount * *****************************************************************************/ -static ULONG WINAPI -IDirect3DMaterialImpl_Release(IDirect3DMaterial3 *iface) +static ULONG WINAPI IDirect3DMaterialImpl_Release(IDirect3DMaterial3 *iface) { - IDirect3DMaterialImpl *This = (IDirect3DMaterialImpl *)iface; + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial3(iface); ULONG ref = InterlockedDecrement(&This->ref); TRACE("%p decreasing refcount to %u.\n", This, ref); @@ -141,9 +142,9 @@ IDirect3DMaterialImpl_Release(IDirect3DMaterial3 *iface) { if(This->Handle) { - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); ddraw_free_handle(&This->ddraw->d3ddevice->handle_table, This->Handle - 1, DDRAW_HANDLE_MATERIAL); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); } HeapFree(GetProcessHeap(), 0, This); @@ -225,21 +226,20 @@ IDirect3DMaterialImpl_Unreserve(IDirect3DMaterial *iface) * DDERR_INVALIDPARAMS if Mat is NULL * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DMaterialImpl_SetMaterial(IDirect3DMaterial3 *iface, - D3DMATERIAL *lpMat) +static HRESULT WINAPI IDirect3DMaterialImpl_SetMaterial(IDirect3DMaterial3 *iface, + D3DMATERIAL *lpMat) { - IDirect3DMaterialImpl *This = (IDirect3DMaterialImpl *)iface; + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial3(iface); TRACE("iface %p, material %p.\n", iface, lpMat); if (TRACE_ON(ddraw)) dump_material(lpMat); /* Stores the material */ - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); memset(&This->mat, 0, sizeof(This->mat)); memcpy(&This->mat, lpMat, lpMat->dwSize); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DD_OK; } @@ -257,11 +257,10 @@ IDirect3DMaterialImpl_SetMaterial(IDirect3DMaterial3 *iface, * DDERR_INVALIDPARAMS if Mat is NULL * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DMaterialImpl_GetMaterial(IDirect3DMaterial3 *iface, - D3DMATERIAL *lpMat) +static HRESULT WINAPI IDirect3DMaterialImpl_GetMaterial(IDirect3DMaterial3 *iface, + D3DMATERIAL *lpMat) { - IDirect3DMaterialImpl *This = (IDirect3DMaterialImpl *)iface; + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial3(iface); DWORD dwSize; TRACE("iface %p, material %p.\n", iface, lpMat); @@ -272,10 +271,10 @@ IDirect3DMaterialImpl_GetMaterial(IDirect3DMaterial3 *iface, } /* Copies the material structure */ - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); dwSize = lpMat->dwSize; memcpy(lpMat, &This->mat, dwSize); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DD_OK; } @@ -295,129 +294,153 @@ IDirect3DMaterialImpl_GetMaterial(IDirect3DMaterial3 *iface, * DDERR_INVALIDPARAMS if Handle is NULL * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DMaterialImpl_GetHandle(IDirect3DMaterial3 *iface, - IDirect3DDevice3 *lpDirect3DDevice3, - D3DMATERIALHANDLE *lpHandle) +static HRESULT WINAPI IDirect3DMaterialImpl_GetHandle(IDirect3DMaterial3 *iface, + IDirect3DDevice3 *device, D3DMATERIALHANDLE *handle) { - IDirect3DMaterialImpl *This = (IDirect3DMaterialImpl *)iface; - IDirect3DDeviceImpl *device = device_from_device3(lpDirect3DDevice3); + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial3(iface); + IDirect3DDeviceImpl *device_impl = unsafe_impl_from_IDirect3DDevice3(device); - TRACE("iface %p, device %p, handle %p.\n", iface, lpDirect3DDevice3, lpHandle); + TRACE("iface %p, device %p, handle %p.\n", iface, device, handle); - EnterCriticalSection(&ddraw_cs); - This->active_device = device; + wined3d_mutex_lock(); + This->active_device = device_impl; if(!This->Handle) { - DWORD h = ddraw_allocate_handle(&device->handle_table, This, DDRAW_HANDLE_MATERIAL); + DWORD h = ddraw_allocate_handle(&device_impl->handle_table, This, DDRAW_HANDLE_MATERIAL); if (h == DDRAW_INVALID_HANDLE) { ERR("Failed to allocate a material handle.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; /* Unchecked */ } This->Handle = h + 1; } - *lpHandle = This->Handle; - TRACE(" returning handle %08x.\n", *lpHandle); - LeaveCriticalSection(&ddraw_cs); + *handle = This->Handle; + TRACE(" returning handle %08x.\n", *handle); + wined3d_mutex_unlock(); return D3D_OK; } static HRESULT WINAPI IDirect3DMaterialImpl_2_GetHandle(IDirect3DMaterial2 *iface, - IDirect3DDevice2 *lpDirect3DDevice2, D3DMATERIALHANDLE *lpHandle) + IDirect3DDevice2 *device, D3DMATERIALHANDLE *handle) { - TRACE("iface %p, device %p, handle %p.\n", iface, lpDirect3DDevice2, lpHandle); + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial2(iface); + IDirect3DDeviceImpl *device_impl = unsafe_impl_from_IDirect3DDevice2(device); - return IDirect3DMaterial3_GetHandle((IDirect3DMaterial3 *)material_from_material2(iface), lpDirect3DDevice2 ? - (IDirect3DDevice3 *)&device_from_device2(lpDirect3DDevice2)->IDirect3DDevice3_vtbl : NULL, lpHandle); + TRACE("iface %p, device %p, handle %p.\n", iface, device, handle); + + return IDirect3DMaterial3_GetHandle(&This->IDirect3DMaterial3_iface, device_impl ? + &device_impl->IDirect3DDevice3_iface : NULL, handle); } static HRESULT WINAPI IDirect3DMaterialImpl_1_GetHandle(IDirect3DMaterial *iface, - IDirect3DDevice *lpDirect3DDevice, D3DMATERIALHANDLE *lpHandle) + IDirect3DDevice *device, D3DMATERIALHANDLE *handle) { - TRACE("iface %p, device %p, handle %p.\n", iface, lpDirect3DDevice, lpHandle); + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial(iface); + IDirect3DDeviceImpl *device_impl = unsafe_impl_from_IDirect3DDevice(device); - return IDirect3DMaterial3_GetHandle((IDirect3DMaterial3 *)material_from_material1(iface), lpDirect3DDevice ? - (IDirect3DDevice3 *)&device_from_device1(lpDirect3DDevice)->IDirect3DDevice3_vtbl : NULL, lpHandle); + TRACE("iface %p, device %p, handle %p.\n", iface, device, handle); + + return IDirect3DMaterial3_GetHandle(&This->IDirect3DMaterial3_iface, device_impl ? + &device_impl->IDirect3DDevice3_iface : NULL, handle); } -static HRESULT WINAPI IDirect3DMaterialImpl_2_QueryInterface(LPDIRECT3DMATERIAL2 iface, REFIID riid, - LPVOID* obp) +static HRESULT WINAPI IDirect3DMaterialImpl_2_QueryInterface(IDirect3DMaterial2 *iface, REFIID riid, + void **obp) { + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial2(iface); + TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obp); - return IDirect3DMaterial3_QueryInterface((IDirect3DMaterial3 *)material_from_material2(iface), riid, obp); + return IDirect3DMaterial3_QueryInterface(&This->IDirect3DMaterial3_iface, riid, obp); } -static HRESULT WINAPI IDirect3DMaterialImpl_1_QueryInterface(LPDIRECT3DMATERIAL iface, REFIID riid, - LPVOID* obp) +static HRESULT WINAPI IDirect3DMaterialImpl_1_QueryInterface(IDirect3DMaterial *iface, REFIID riid, + void **obp) { + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial(iface); + TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obp); - return IDirect3DMaterial3_QueryInterface((IDirect3DMaterial3 *)material_from_material1(iface), riid, obp); + return IDirect3DMaterial3_QueryInterface(&This->IDirect3DMaterial3_iface, riid, obp); } -static ULONG WINAPI IDirect3DMaterialImpl_2_AddRef(LPDIRECT3DMATERIAL2 iface) +static ULONG WINAPI IDirect3DMaterialImpl_2_AddRef(IDirect3DMaterial2 *iface) { + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial2(iface); + TRACE("iface %p.\n", iface); - return IDirect3DMaterial3_AddRef((IDirect3DMaterial3 *)material_from_material2(iface)); + return IDirect3DMaterial3_AddRef(&This->IDirect3DMaterial3_iface); } -static ULONG WINAPI IDirect3DMaterialImpl_1_AddRef(LPDIRECT3DMATERIAL iface) +static ULONG WINAPI IDirect3DMaterialImpl_1_AddRef(IDirect3DMaterial *iface) { + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial(iface); + TRACE("iface %p.\n", iface); - return IDirect3DMaterial3_AddRef((IDirect3DMaterial3 *)material_from_material1(iface)); + return IDirect3DMaterial3_AddRef(&This->IDirect3DMaterial3_iface); } -static ULONG WINAPI IDirect3DMaterialImpl_2_Release(LPDIRECT3DMATERIAL2 iface) +static ULONG WINAPI IDirect3DMaterialImpl_2_Release(IDirect3DMaterial2 *iface) { + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial2(iface); + TRACE("iface %p.\n", iface); - return IDirect3DMaterial3_Release((IDirect3DMaterial3 *)material_from_material2(iface)); + return IDirect3DMaterial3_Release(&This->IDirect3DMaterial3_iface); } -static ULONG WINAPI IDirect3DMaterialImpl_1_Release(LPDIRECT3DMATERIAL iface) +static ULONG WINAPI IDirect3DMaterialImpl_1_Release(IDirect3DMaterial *iface) { + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial(iface); + TRACE("iface %p.\n", iface); - return IDirect3DMaterial3_Release((IDirect3DMaterial3 *)material_from_material1(iface)); + return IDirect3DMaterial3_Release(&This->IDirect3DMaterial3_iface); } -static HRESULT WINAPI IDirect3DMaterialImpl_2_SetMaterial(LPDIRECT3DMATERIAL2 iface, +static HRESULT WINAPI IDirect3DMaterialImpl_2_SetMaterial(IDirect3DMaterial2 *iface, LPD3DMATERIAL lpMat) { + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial2(iface); + TRACE("iface %p, material %p.\n", iface, lpMat); - return IDirect3DMaterial3_SetMaterial((IDirect3DMaterial3 *)material_from_material2(iface), lpMat); + return IDirect3DMaterial3_SetMaterial(&This->IDirect3DMaterial3_iface, lpMat); } -static HRESULT WINAPI IDirect3DMaterialImpl_1_SetMaterial(LPDIRECT3DMATERIAL iface, +static HRESULT WINAPI IDirect3DMaterialImpl_1_SetMaterial(IDirect3DMaterial *iface, LPD3DMATERIAL lpMat) { + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial(iface); + TRACE("iface %p, material %p.\n", iface, lpMat); - return IDirect3DMaterial3_SetMaterial((IDirect3DMaterial3 *)material_from_material1(iface), lpMat); + return IDirect3DMaterial3_SetMaterial(&This->IDirect3DMaterial3_iface, lpMat); } -static HRESULT WINAPI IDirect3DMaterialImpl_2_GetMaterial(LPDIRECT3DMATERIAL2 iface, +static HRESULT WINAPI IDirect3DMaterialImpl_2_GetMaterial(IDirect3DMaterial2 *iface, LPD3DMATERIAL lpMat) { + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial2(iface); + TRACE("iface %p, material %p.\n", iface, lpMat); - return IDirect3DMaterial3_GetMaterial((IDirect3DMaterial3 *)material_from_material2(iface), lpMat); + return IDirect3DMaterial3_GetMaterial(&This->IDirect3DMaterial3_iface, lpMat); } -static HRESULT WINAPI IDirect3DMaterialImpl_1_GetMaterial(LPDIRECT3DMATERIAL iface, +static HRESULT WINAPI IDirect3DMaterialImpl_1_GetMaterial(IDirect3DMaterial *iface, LPD3DMATERIAL lpMat) { + IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial(iface); + TRACE("iface %p, material %p.\n", iface, lpMat); - return IDirect3DMaterial3_GetMaterial((IDirect3DMaterial3 *)material_from_material1(iface), lpMat); + return IDirect3DMaterial3_GetMaterial(&This->IDirect3DMaterial3_iface, lpMat); } @@ -441,7 +464,7 @@ void material_activate(IDirect3DMaterialImpl* This) d3d7mat.u3.emissive = This->mat.u3.emissive; d3d7mat.u4.power = This->mat.u4.power; - IDirect3DDevice7_SetMaterial((IDirect3DDevice7 *)This->active_device, &d3d7mat); + IDirect3DDevice7_SetMaterial(&This->active_device->IDirect3DDevice7_iface, &d3d7mat); } static const struct IDirect3DMaterial3Vtbl d3d_material3_vtbl = @@ -483,11 +506,19 @@ static const struct IDirect3DMaterialVtbl d3d_material1_vtbl = IDirect3DMaterialImpl_Unreserve }; -void d3d_material_init(IDirect3DMaterialImpl *material, IDirectDrawImpl *ddraw) +IDirect3DMaterialImpl *d3d_material_create(IDirectDrawImpl *ddraw) { - material->lpVtbl = &d3d_material3_vtbl; - material->IDirect3DMaterial2_vtbl = &d3d_material2_vtbl; - material->IDirect3DMaterial_vtbl = &d3d_material1_vtbl; + IDirect3DMaterialImpl *material; + + material = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*material)); + if (!material) + return NULL; + + material->IDirect3DMaterial3_iface.lpVtbl = &d3d_material3_vtbl; + material->IDirect3DMaterial2_iface.lpVtbl = &d3d_material2_vtbl; + material->IDirect3DMaterial_iface.lpVtbl = &d3d_material1_vtbl; material->ref = 1; material->ddraw = ddraw; + + return material; } diff --git a/reactos/dll/directx/wine/ddraw/palette.c b/reactos/dll/directx/wine/ddraw/palette.c index b68cf82d4f0..cff59a6340b 100644 --- a/reactos/dll/directx/wine/ddraw/palette.c +++ b/reactos/dll/directx/wine/ddraw/palette.c @@ -70,7 +70,7 @@ IDirectDrawPaletteImpl_QueryInterface(IDirectDrawPalette *iface, static ULONG WINAPI IDirectDrawPaletteImpl_AddRef(IDirectDrawPalette *iface) { - IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface; + IDirectDrawPaletteImpl *This = impl_from_IDirectDrawPalette(iface); ULONG ref = InterlockedIncrement(&This->ref); TRACE("%p increasing refcount to %u.\n", This, ref); @@ -90,20 +90,21 @@ IDirectDrawPaletteImpl_AddRef(IDirectDrawPalette *iface) static ULONG WINAPI IDirectDrawPaletteImpl_Release(IDirectDrawPalette *iface) { - IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface; + IDirectDrawPaletteImpl *This = impl_from_IDirectDrawPalette(iface); ULONG ref = InterlockedDecrement(&This->ref); TRACE("%p decreasing refcount to %u.\n", This, ref); if (ref == 0) { - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); wined3d_palette_decref(This->wineD3DPalette); if(This->ifaceToRelease) { IUnknown_Release(This->ifaceToRelease); } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + HeapFree(GetProcessHeap(), 0, This); } @@ -155,13 +156,13 @@ static HRESULT WINAPI IDirectDrawPaletteImpl_GetCaps(IDirectDrawPalette *iface, DWORD *Caps) { - IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface; + IDirectDrawPaletteImpl *This = impl_from_IDirectDrawPalette(iface); TRACE("iface %p, caps %p.\n", iface, Caps); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); *Caps = wined3d_palette_get_flags(This->wineD3DPalette); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } @@ -191,7 +192,7 @@ IDirectDrawPaletteImpl_SetEntries(IDirectDrawPalette *iface, DWORD Count, PALETTEENTRY *PalEnt) { - IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface; + IDirectDrawPaletteImpl *This = impl_from_IDirectDrawPalette(iface); HRESULT hr; TRACE("iface %p, flags %#x, start %u, count %u, entries %p.\n", @@ -200,9 +201,10 @@ IDirectDrawPaletteImpl_SetEntries(IDirectDrawPalette *iface, if(!PalEnt) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_palette_set_entries(This->wineD3DPalette, Flags, Start, Count, PalEnt); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -230,7 +232,7 @@ IDirectDrawPaletteImpl_GetEntries(IDirectDrawPalette *iface, DWORD Count, PALETTEENTRY *PalEnt) { - IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface; + IDirectDrawPaletteImpl *This = impl_from_IDirectDrawPalette(iface); HRESULT hr; TRACE("iface %p, flags %#x, start %u, count %u, entries %p.\n", @@ -239,9 +241,10 @@ IDirectDrawPaletteImpl_GetEntries(IDirectDrawPalette *iface, if(!PalEnt) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_palette_get_entries(This->wineD3DPalette, Flags, Start, Count, PalEnt); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -258,12 +261,19 @@ static const struct IDirectDrawPaletteVtbl ddraw_palette_vtbl = IDirectDrawPaletteImpl_SetEntries }; +IDirectDrawPaletteImpl *unsafe_impl_from_IDirectDrawPalette(IDirectDrawPalette *iface) +{ + if (!iface) return NULL; + assert(iface->lpVtbl == &ddraw_palette_vtbl); + return CONTAINING_RECORD(iface, IDirectDrawPaletteImpl, IDirectDrawPalette_iface); +} + HRESULT ddraw_palette_init(IDirectDrawPaletteImpl *palette, IDirectDrawImpl *ddraw, DWORD flags, PALETTEENTRY *entries) { HRESULT hr; - palette->lpVtbl = &ddraw_palette_vtbl; + palette->IDirectDrawPalette_iface.lpVtbl = &ddraw_palette_vtbl; palette->ref = 1; hr = wined3d_palette_create(ddraw->wined3d_device, flags, diff --git a/reactos/dll/directx/wine/ddraw/parent.c b/reactos/dll/directx/wine/ddraw/parent.c deleted file mode 100644 index 871f0660e6e..00000000000 --- a/reactos/dll/directx/wine/ddraw/parent.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * IParent implementation - * - * Copyright (c) 2006 Stefan Dösinger - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - * - * A universal parent interface for everything in WineD3D that doesn't have - * a DDraw counterpart - */ - -#include "config.h" -#include "wine/port.h" - -#include "ddraw_private.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ddraw); - -/***************************************************************************** - * IUnknown methods - *****************************************************************************/ - -/***************************************************************************** - * IParent::Queryinterface - * - * It can't query any interfaces, and it's not used for anything. So - * it just returns E_NOINTERFACE - * - * Params: - * riid: guid of queried interface - * obj: returns a pointer to the interface - * - * Return values - * This implementation always returns E_NOINTERFACE and NULL - * - *****************************************************************************/ -static HRESULT WINAPI -IParentImpl_QueryInterface(IParent *iface, - REFIID riid, - void **obj) -{ - TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj); - - *obj = NULL; - if ( IsEqualGUID( &IID_IUnknown, riid ) || - IsEqualGUID( &IID_IParent, riid ) ) - { - *obj = iface; - IParent_AddRef(iface); - return DD_OK; - } - return E_NOINTERFACE; -} - -/***************************************************************************** - * IParent::AddRef - * - * Increases the refcount - * - * Params: - * - * Return values - * The new refcount - * - *****************************************************************************/ -static ULONG WINAPI -IParentImpl_AddRef(IParent *iface) -{ - IParentImpl *This = (IParentImpl *)iface; - ULONG ref = InterlockedIncrement(&This->ref); - - TRACE("%p increasing refcount to %u.\n", This, ref); - - return ref; -} - - -/***************************************************************************** - * IParent::Release - * - * Releases the refcount, and destroys the object if the refcount falls to 0 - * Also releases the child object, if destroyed. That's almost the whole sense - * of this interface. - * - * Params: - * - * Return values - * The new refcount - * - *****************************************************************************/ -static ULONG WINAPI IParentImpl_Release(IParent *iface) -{ - IParentImpl *This = (IParentImpl *)iface; - ULONG ref = InterlockedDecrement(&This->ref); - - TRACE("%p decreasing refcount to %u.\n", This, ref); - - if (ref == 0) - { - TRACE("(%p) Releasing child at %p\n", This, This->child); - if(This->child) - IUnknown_Release(This->child); - HeapFree(GetProcessHeap(), 0, This); - TRACE("Released\n"); - } - return ref; -} - -/***************************************************************************** - * The VTable - *****************************************************************************/ -static const struct IParentVtbl ddraw_parent_vtbl = -{ - IParentImpl_QueryInterface, - IParentImpl_AddRef, - IParentImpl_Release, -}; - -void ddraw_parent_init(IParentImpl *parent) -{ - parent->lpVtbl = &ddraw_parent_vtbl; - parent->ref = 1; -} diff --git a/reactos/dll/directx/wine/ddraw/regsvr.c b/reactos/dll/directx/wine/ddraw/regsvr.c deleted file mode 100644 index 52a6fb77bda..00000000000 --- a/reactos/dll/directx/wine/ddraw/regsvr.c +++ /dev/null @@ -1,439 +0,0 @@ -/* - * self-registerable dll functions for ddraw.dll - * - * Copyright (C) 2003 John K. Hohm - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include "config.h" -#include "wine/port.h" - -#include "ddraw_private.h" -#include "wine/unicode.h" -#include "winreg.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ddraw); - -static LSTATUS (WINAPI *pRegDeleteTreeW)(HKEY,LPCWSTR); -static LSTATUS (WINAPI *pRegDeleteTreeA)(HKEY,LPCSTR); - -/* - * Near the bottom of this file are the exported DllRegisterServer and - * DllUnregisterServer, which make all this worthwhile. - */ - -/*********************************************************************** - * interface for self-registering - */ -struct regsvr_interface -{ - IID const *iid; /* NULL for end of list */ - LPCSTR name; /* can be NULL to omit */ - IID const *base_iid; /* can be NULL to omit */ - int num_methods; /* can be <0 to omit */ - CLSID const *ps_clsid; /* can be NULL to omit */ - CLSID const *ps_clsid32; /* can be NULL to omit */ -}; - -static HRESULT register_interfaces(struct regsvr_interface const *list); -static HRESULT unregister_interfaces(struct regsvr_interface const *list); - -struct regsvr_coclass -{ - CLSID const *clsid; /* NULL for end of list */ - LPCSTR name; /* can be NULL to omit */ - LPCSTR ips; /* can be NULL to omit */ - LPCSTR ips32; /* can be NULL to omit */ - LPCSTR ips32_tmodel; /* can be NULL to omit */ - LPCSTR clsid_str; /* can be NULL to omit */ - LPCSTR progid; /* can be NULL to omit */ -}; - -static HRESULT register_coclasses(struct regsvr_coclass const *list); -static HRESULT unregister_coclasses(struct regsvr_coclass const *list); - -/*********************************************************************** - * static string constants - */ -static WCHAR const interface_keyname[10] = { - 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 }; -static WCHAR const base_ifa_keyname[14] = { - 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', - 'e', 0 }; -static WCHAR const num_methods_keyname[11] = { - 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 }; -static WCHAR const ps_clsid_keyname[15] = { - 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's', - 'i', 'd', 0 }; -static WCHAR const ps_clsid32_keyname[17] = { - 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's', - 'i', 'd', '3', '2', 0 }; -static WCHAR const clsid_keyname[6] = { - 'C', 'L', 'S', 'I', 'D', 0 }; -static WCHAR const ips_keyname[13] = { - 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r', - 0 }; -static WCHAR const ips32_keyname[15] = { - 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r', - '3', '2', 0 }; -static WCHAR const progid_keyname[7] = { - 'P', 'r', 'o', 'g', 'I', 'D', 0 }; -static char const tmodel_valuename[] = "ThreadingModel"; - -/*********************************************************************** - * static helper functions - */ -static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid); -static LONG register_key_defvalueW(HKEY base, WCHAR const *name, - WCHAR const *value); -static LONG register_key_defvalueA(HKEY base, WCHAR const *name, - char const *value); - -/*********************************************************************** - * register_interfaces - */ -static HRESULT register_interfaces(struct regsvr_interface const *list) -{ - LONG res = ERROR_SUCCESS; - HKEY interface_key; - - res = RegCreateKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, &interface_key, NULL); - if (res != ERROR_SUCCESS) goto error_return; - - for (; res == ERROR_SUCCESS && list->iid; ++list) { - WCHAR buf[39]; - HKEY iid_key; - - StringFromGUID2(list->iid, buf, 39); - res = RegCreateKeyExW(interface_key, buf, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, &iid_key, NULL); - if (res != ERROR_SUCCESS) goto error_close_interface_key; - - if (list->name) { - res = RegSetValueExA(iid_key, NULL, 0, REG_SZ, - (CONST BYTE*)(list->name), - strlen(list->name) + 1); - if (res != ERROR_SUCCESS) goto error_close_iid_key; - } - - if (list->base_iid) { - res = register_key_guid(iid_key, base_ifa_keyname, list->base_iid); - if (res != ERROR_SUCCESS) goto error_close_iid_key; - } - - if (0 <= list->num_methods) { - static WCHAR const fmt[3] = { '%', 'd', 0 }; - HKEY key; - - res = RegCreateKeyExW(iid_key, num_methods_keyname, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, &key, NULL); - if (res != ERROR_SUCCESS) goto error_close_iid_key; - - sprintfW(buf, fmt, list->num_methods); - res = RegSetValueExW(key, NULL, 0, REG_SZ, - (CONST BYTE*)buf, - (lstrlenW(buf) + 1) * sizeof(WCHAR)); - RegCloseKey(key); - - if (res != ERROR_SUCCESS) goto error_close_iid_key; - } - - if (list->ps_clsid) { - res = register_key_guid(iid_key, ps_clsid_keyname, list->ps_clsid); - if (res != ERROR_SUCCESS) goto error_close_iid_key; - } - - if (list->ps_clsid32) { - res = register_key_guid(iid_key, ps_clsid32_keyname, list->ps_clsid32); - if (res != ERROR_SUCCESS) goto error_close_iid_key; - } - - error_close_iid_key: - RegCloseKey(iid_key); - } - -error_close_interface_key: - RegCloseKey(interface_key); -error_return: - return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK; -} - -/*********************************************************************** - * unregister_interfaces - */ -static HRESULT unregister_interfaces(struct regsvr_interface const *list) -{ - LONG res = ERROR_SUCCESS; - HKEY interface_key; - - res = RegOpenKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, - KEY_READ | KEY_WRITE, &interface_key); - if (res == ERROR_FILE_NOT_FOUND) return S_OK; - if (res != ERROR_SUCCESS) goto error_return; - - for (; res == ERROR_SUCCESS && list->iid; ++list) { - WCHAR buf[39]; - - StringFromGUID2(list->iid, buf, 39); - res = pRegDeleteTreeW(interface_key, buf); - if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS; - } - - RegCloseKey(interface_key); -error_return: - return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK; -} - -/*********************************************************************** - * register_coclasses - */ -static HRESULT register_coclasses(struct regsvr_coclass const *list) -{ - LONG res = ERROR_SUCCESS; - HKEY coclass_key; - - res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL); - if (res != ERROR_SUCCESS) goto error_return; - - for (; res == ERROR_SUCCESS && list->clsid; ++list) { - WCHAR buf[39]; - HKEY clsid_key; - - StringFromGUID2(list->clsid, buf, 39); - res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL); - if (res != ERROR_SUCCESS) goto error_close_coclass_key; - - if (list->name) { - res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ, - (CONST BYTE*)(list->name), - strlen(list->name) + 1); - if (res != ERROR_SUCCESS) goto error_close_clsid_key; - } - - if (list->ips) { - res = register_key_defvalueA(clsid_key, ips_keyname, list->ips); - if (res != ERROR_SUCCESS) goto error_close_clsid_key; - } - - if (list->ips32) { - HKEY ips32_key; - - res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, - &ips32_key, NULL); - if (res != ERROR_SUCCESS) goto error_close_clsid_key; - - res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ, - (CONST BYTE*)list->ips32, - lstrlenA(list->ips32) + 1); - if (res == ERROR_SUCCESS && list->ips32_tmodel) - res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ, - (CONST BYTE*)list->ips32_tmodel, - strlen(list->ips32_tmodel) + 1); - RegCloseKey(ips32_key); - if (res != ERROR_SUCCESS) goto error_close_clsid_key; - } - - if (list->clsid_str) { - res = register_key_defvalueA(clsid_key, clsid_keyname, - list->clsid_str); - if (res != ERROR_SUCCESS) goto error_close_clsid_key; - } - - if (list->progid) { - HKEY progid_key; - - res = register_key_defvalueA(clsid_key, progid_keyname, - list->progid); - if (res != ERROR_SUCCESS) goto error_close_clsid_key; - - res = RegCreateKeyExA(HKEY_CLASSES_ROOT, list->progid, 0, - NULL, 0, KEY_READ | KEY_WRITE, NULL, - &progid_key, NULL); - if (res != ERROR_SUCCESS) goto error_close_clsid_key; - - res = register_key_defvalueW(progid_key, clsid_keyname, buf); - RegCloseKey(progid_key); - if (res != ERROR_SUCCESS) goto error_close_clsid_key; - } - - error_close_clsid_key: - RegCloseKey(clsid_key); - } - -error_close_coclass_key: - RegCloseKey(coclass_key); -error_return: - return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK; -} - -/*********************************************************************** - * unregister_coclasses - */ -static HRESULT unregister_coclasses(struct regsvr_coclass const *list) -{ - LONG res = ERROR_SUCCESS; - HKEY coclass_key; - - res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, - KEY_READ | KEY_WRITE, &coclass_key); - if (res == ERROR_FILE_NOT_FOUND) return S_OK; - if (res != ERROR_SUCCESS) goto error_return; - - for (; res == ERROR_SUCCESS && list->clsid; ++list) { - WCHAR buf[39]; - - StringFromGUID2(list->clsid, buf, 39); - res = pRegDeleteTreeW(coclass_key, buf); - if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS; - if (res != ERROR_SUCCESS) goto error_close_coclass_key; - - if (list->progid) { - res = pRegDeleteTreeA(HKEY_CLASSES_ROOT, list->progid); - if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS; - if (res != ERROR_SUCCESS) goto error_close_coclass_key; - } - } - -error_close_coclass_key: - RegCloseKey(coclass_key); -error_return: - return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK; -} - -/*********************************************************************** - * regsvr_key_guid - */ -static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid) -{ - WCHAR buf[39]; - - StringFromGUID2(guid, buf, 39); - return register_key_defvalueW(base, name, buf); -} - -/*********************************************************************** - * regsvr_key_defvalueW - */ -static LONG register_key_defvalueW( - HKEY base, - WCHAR const *name, - WCHAR const *value) -{ - LONG res; - HKEY key; - - res = RegCreateKeyExW(base, name, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, &key, NULL); - if (res != ERROR_SUCCESS) return res; - res = RegSetValueExW(key, NULL, 0, REG_SZ, (CONST BYTE*)value, - (lstrlenW(value) + 1) * sizeof(WCHAR)); - RegCloseKey(key); - return res; -} - -/*********************************************************************** - * regsvr_key_defvalueA - */ -static LONG register_key_defvalueA( - HKEY base, - WCHAR const *name, - char const *value) -{ - LONG res; - HKEY key; - - res = RegCreateKeyExW(base, name, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, &key, NULL); - if (res != ERROR_SUCCESS) return res; - res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value, - lstrlenA(value) + 1); - RegCloseKey(key); - return res; -} - -/*********************************************************************** - * coclass list - */ - -static struct regsvr_coclass const coclass_list[] = { - { &CLSID_DirectDraw, - "DirectDraw Object", - NULL, - "ddraw.dll", - "Both" - }, - { &CLSID_DirectDraw7, - "DirectDraw 7 Object", - NULL, - "ddraw.dll", - "Both" - }, - { &CLSID_DirectDrawClipper, - "DirectDraw Clipper Object", - NULL, - "ddraw.dll", - "Both" - }, - { NULL } /* list terminator */ -}; - -/*********************************************************************** - * interface list - */ - -static struct regsvr_interface const interface_list[] = { - { NULL } /* list terminator */ -}; - -/*********************************************************************** - * DllRegisterServer (DDRAW.@) - */ -HRESULT WINAPI DllRegisterServer(void) -{ - HRESULT hr; - - TRACE("\n"); - - hr = register_coclasses(coclass_list); - if (SUCCEEDED(hr)) - hr = register_interfaces(interface_list); - return hr; -} - -/*********************************************************************** - * DllUnregisterServer (DDRAW.@) - */ -HRESULT WINAPI DllUnregisterServer(void) -{ - HRESULT hr; - - HMODULE advapi32 = GetModuleHandleA("advapi32"); - if (!advapi32) return E_FAIL; - pRegDeleteTreeA = (void *) GetProcAddress(advapi32, "RegDeleteTreeA"); - pRegDeleteTreeW = (void *) GetProcAddress(advapi32, "RegDeleteTreeW"); - if (!pRegDeleteTreeA || !pRegDeleteTreeW) return E_FAIL; - - TRACE("\n"); - - hr = unregister_coclasses(coclass_list); - if (SUCCEEDED(hr)) - hr = unregister_interfaces(interface_list); - return hr; -} diff --git a/reactos/dll/directx/wine/ddraw/surface.c b/reactos/dll/directx/wine/ddraw/surface.c index ee30d8666d3..612eb3039d2 100644 --- a/reactos/dll/directx/wine/ddraw/surface.c +++ b/reactos/dll/directx/wine/ddraw/surface.c @@ -4,9 +4,7 @@ * Copyright (c) 1998-2000 Lionel Ulmer * Copyright (c) 2000-2001 TransGaming Technologies Inc. * Copyright (c) 2006 Stefan Dösinger - * - * This file contains the (internal) driver registration functions, - * driver enumeration APIs and DirectDraw creation functions. + * Copyright (c) 2011 Ričardas Barkauskas for CodeWeavers * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -30,10 +28,84 @@ WINE_DEFAULT_DEBUG_CHANNEL(ddraw); -static inline IDirectDrawSurfaceImpl *surface_from_gamma_control(IDirectDrawGammaControl *iface) +static IDirectDrawSurfaceImpl *unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2 *iface); +static IDirectDrawSurfaceImpl *unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3 *iface); + +static inline IDirectDrawSurfaceImpl *impl_from_IDirectDrawGammaControl(IDirectDrawGammaControl *iface) { - return (IDirectDrawSurfaceImpl *)((char*)iface - - FIELD_OFFSET(IDirectDrawSurfaceImpl, IDirectDrawGammaControl_vtbl)); + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirectDrawGammaControl_iface); +} + +/* This is slow, of course. Also, in case of locks, we can't prevent other + * applications from drawing to the screen while we've locked the frontbuffer. + * We'd like to do this in wined3d instead, but for that to work wined3d needs + * to support windowless rendering first. */ +static HRESULT ddraw_surface_update_frontbuffer(IDirectDrawSurfaceImpl *surface, const RECT *rect, BOOL read) +{ + HDC surface_dc, screen_dc; + int x, y, w, h; + HRESULT hr; + BOOL ret; + + if (!rect) + { + x = 0; + y = 0; + w = surface->surface_desc.dwWidth; + h = surface->surface_desc.dwHeight; + } + else + { + x = rect->left; + y = rect->top; + w = rect->right - rect->left; + h = rect->bottom - rect->top; + } + + if (w <= 0 || h <= 0) + return DD_OK; + + if (surface->ddraw->swapchain_window) + { + /* Nothing to do, we control the frontbuffer, or at least the parts we + * care about. */ + if (read) + return DD_OK; + + return wined3d_surface_blt(surface->ddraw->wined3d_frontbuffer, rect, + surface->wined3d_surface, rect, 0, NULL, WINED3D_TEXF_POINT); + } + + if (FAILED(hr = wined3d_surface_getdc(surface->wined3d_surface, &surface_dc))) + { + ERR("Failed to get surface DC, hr %#x.\n", hr); + return hr; + } + + if (!(screen_dc = GetDC(NULL))) + { + wined3d_surface_releasedc(surface->wined3d_surface, surface_dc); + ERR("Failed to get screen DC.\n"); + return E_FAIL; + } + + if (read) + ret = BitBlt(surface_dc, x, y, w, h, + screen_dc, x, y, SRCCOPY); + else + ret = BitBlt(screen_dc, x, y, w, h, + surface_dc, x, y, SRCCOPY); + + ReleaseDC(NULL, screen_dc); + wined3d_surface_releasedc(surface->wined3d_surface, surface_dc); + + if (!ret) + { + ERR("Failed to blit to/from screen.\n"); + return E_FAIL; + } + + return DD_OK; } /***************************************************************************** @@ -60,7 +132,7 @@ static inline IDirectDrawSurfaceImpl *surface_from_gamma_control(IDirectDrawGamm *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_QueryInterface(IDirectDrawSurface7 *iface, REFIID riid, void **obj) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj); @@ -71,27 +143,45 @@ static HRESULT WINAPI ddraw_surface7_QueryInterface(IDirectDrawSurface7 *iface, return DDERR_INVALIDPARAMS; if (IsEqualGUID(riid, &IID_IUnknown) - || IsEqualGUID(riid, &IID_IDirectDrawSurface7) - || IsEqualGUID(riid, &IID_IDirectDrawSurface4) ) + || IsEqualGUID(riid, &IID_IDirectDrawSurface7) ) { - IUnknown_AddRef(iface); + IDirectDrawSurface7_AddRef(iface); *obj = iface; TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This, *obj); return S_OK; } - else if( IsEqualGUID(riid, &IID_IDirectDrawSurface3) - || IsEqualGUID(riid, &IID_IDirectDrawSurface2) - || IsEqualGUID(riid, &IID_IDirectDrawSurface) ) + else if (IsEqualGUID(riid, &IID_IDirectDrawSurface4)) { - IUnknown_AddRef(iface); - *obj = &This->IDirectDrawSurface3_vtbl; + IDirectDrawSurface4_AddRef(&This->IDirectDrawSurface4_iface); + *obj = &This->IDirectDrawSurface4_iface; + TRACE("(%p) returning IDirectDrawSurface4 interface at %p\n", This, *obj); + return S_OK; + } + else if (IsEqualGUID(riid, &IID_IDirectDrawSurface3)) + { + IDirectDrawSurface3_AddRef(&This->IDirectDrawSurface3_iface); + *obj = &This->IDirectDrawSurface3_iface; TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This, *obj); return S_OK; } + else if (IsEqualGUID(riid, &IID_IDirectDrawSurface2)) + { + IDirectDrawSurface2_AddRef(&This->IDirectDrawSurface2_iface); + *obj = &This->IDirectDrawSurface2_iface; + TRACE("(%p) returning IDirectDrawSurface2 interface at %p\n", This, *obj); + return S_OK; + } + else if (IsEqualGUID(riid, &IID_IDirectDrawSurface)) + { + IDirectDrawSurface_AddRef(&This->IDirectDrawSurface_iface); + *obj = &This->IDirectDrawSurface_iface; + TRACE("(%p) returning IDirectDrawSurface interface at %p\n", This, *obj); + return S_OK; + } else if( IsEqualGUID(riid, &IID_IDirectDrawGammaControl) ) { - IUnknown_AddRef(iface); - *obj = &This->IDirectDrawGammaControl_vtbl; + IDirectDrawGammaControl_AddRef(&This->IDirectDrawGammaControl_iface); + *obj = &This->IDirectDrawGammaControl_iface; TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This, *obj); return S_OK; } @@ -100,14 +190,17 @@ static HRESULT WINAPI ddraw_surface7_QueryInterface(IDirectDrawSurface7 *iface, IsEqualGUID(riid, &IID_IDirect3DRGBDevice) ) { IDirect3DDevice7 *d3d; + IDirect3DDeviceImpl *device_impl; /* Call into IDirect3D7 for creation */ - IDirect3D7_CreateDevice(&This->ddraw->IDirect3D7_iface, riid, (IDirectDrawSurface7 *)This, + IDirect3D7_CreateDevice(&This->ddraw->IDirect3D7_iface, riid, &This->IDirectDrawSurface7_iface, &d3d); if (d3d) { - *obj = (IDirect3DDevice *)&((IDirect3DDeviceImpl *)d3d)->IDirect3DDevice_vtbl; + device_impl = impl_from_IDirect3DDevice7(d3d); + device_impl->from_surface = TRUE; + *obj = &device_impl->IDirect3DDevice_iface; TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj); return S_OK; } @@ -120,12 +213,12 @@ static HRESULT WINAPI ddraw_surface7_QueryInterface(IDirectDrawSurface7 *iface, { if (IsEqualGUID( &IID_IDirect3DTexture, riid )) { - *obj = &This->IDirect3DTexture_vtbl; + *obj = &This->IDirect3DTexture_iface; TRACE(" returning Direct3DTexture interface at %p.\n", *obj); } else { - *obj = &This->IDirect3DTexture2_vtbl; + *obj = &This->IDirect3DTexture2_iface; TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj); } IUnknown_AddRef( (IUnknown *) *obj); @@ -136,32 +229,78 @@ static HRESULT WINAPI ddraw_surface7_QueryInterface(IDirectDrawSurface7 *iface, return E_NOINTERFACE; } -static HRESULT WINAPI ddraw_surface3_QueryInterface(IDirectDrawSurface3 *iface, REFIID riid, void **object) +static HRESULT WINAPI ddraw_surface4_QueryInterface(IDirectDrawSurface4 *iface, REFIID riid, void **object) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); - return ddraw_surface7_QueryInterface((IDirectDrawSurface7 *)surface_from_surface3(iface), riid, object); + return ddraw_surface7_QueryInterface(&This->IDirectDrawSurface7_iface, riid, object); } -static HRESULT WINAPI ddraw_gamma_control_QueryInterface(IDirectDrawGammaControl *iface, REFIID riid, void **object) +static HRESULT WINAPI ddraw_surface3_QueryInterface(IDirectDrawSurface3 *iface, REFIID riid, void **object) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); - return ddraw_surface7_QueryInterface((IDirectDrawSurface7 *)surface_from_gamma_control(iface), riid, object); + return ddraw_surface7_QueryInterface(&This->IDirectDrawSurface7_iface, riid, object); +} + +static HRESULT WINAPI ddraw_surface2_QueryInterface(IDirectDrawSurface2 *iface, REFIID riid, void **object) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); + + return ddraw_surface7_QueryInterface(&This->IDirectDrawSurface7_iface, riid, object); +} + +static HRESULT WINAPI ddraw_surface1_QueryInterface(IDirectDrawSurface *iface, REFIID riid, void **object) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); + + return ddraw_surface7_QueryInterface(&This->IDirectDrawSurface7_iface, riid, object); +} + +static HRESULT WINAPI ddraw_gamma_control_QueryInterface(IDirectDrawGammaControl *iface, + REFIID riid, void **object) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawGammaControl(iface); + + TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); + + return ddraw_surface7_QueryInterface(&This->IDirectDrawSurface7_iface, riid, object); } static HRESULT WINAPI d3d_texture2_QueryInterface(IDirect3DTexture2 *iface, REFIID riid, void **object) { + IDirectDrawSurfaceImpl *This = impl_from_IDirect3DTexture2(iface); TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); - return ddraw_surface7_QueryInterface((IDirectDrawSurface7 *)surface_from_texture2(iface), riid, object); + return ddraw_surface7_QueryInterface(&This->IDirectDrawSurface7_iface, riid, object); } static HRESULT WINAPI d3d_texture1_QueryInterface(IDirect3DTexture *iface, REFIID riid, void **object) { + IDirectDrawSurfaceImpl *This = impl_from_IDirect3DTexture(iface); TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); - return ddraw_surface7_QueryInterface((IDirectDrawSurface7 *)surface_from_texture1(iface), riid, object); + return ddraw_surface7_QueryInterface(&This->IDirectDrawSurface7_iface, riid, object); +} + +static void ddraw_surface_add_iface(IDirectDrawSurfaceImpl *This) +{ + ULONG iface_count = InterlockedIncrement(&This->iface_count); + TRACE("%p increasing iface count to %u.\n", This, iface_count); + + if (iface_count == 1) + { + wined3d_mutex_lock(); + if (This->wined3d_surface) + wined3d_surface_incref(This->wined3d_surface); + if (This->wined3d_texture) + wined3d_texture_incref(This->wined3d_texture); + wined3d_mutex_unlock(); + } } /***************************************************************************** @@ -175,50 +314,108 @@ static HRESULT WINAPI d3d_texture1_QueryInterface(IDirect3DTexture *iface, REFII *****************************************************************************/ static ULONG WINAPI ddraw_surface7_AddRef(IDirectDrawSurface7 *iface) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; - ULONG refCount = InterlockedIncrement(&This->ref); + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); + ULONG refcount = InterlockedIncrement(&This->ref7); - TRACE("%p increasing refcount to %u.\n", This, refCount); + TRACE("iface %p increasing refcount to %u.\n", iface, refcount); - if (refCount == 1) + if (refcount == 1) { - EnterCriticalSection(&ddraw_cs); - if (This->wined3d_surface) - wined3d_surface_incref(This->wined3d_surface); - if (This->wined3d_texture) - wined3d_texture_incref(This->wined3d_texture); - LeaveCriticalSection(&ddraw_cs); + ddraw_surface_add_iface(This); } - return refCount; + return refcount; +} + +static ULONG WINAPI ddraw_surface4_AddRef(IDirectDrawSurface4 *iface) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + ULONG refcount = InterlockedIncrement(&This->ref4); + + TRACE("iface %p increasing refcount to %u.\n", iface, refcount); + + if (refcount == 1) + { + ddraw_surface_add_iface(This); + } + + return refcount; } static ULONG WINAPI ddraw_surface3_AddRef(IDirectDrawSurface3 *iface) { - TRACE("iface %p.\n", iface); + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + ULONG refcount = InterlockedIncrement(&This->ref3); - return ddraw_surface7_AddRef((IDirectDrawSurface7 *)surface_from_surface3(iface)); + TRACE("iface %p increasing refcount to %u.\n", iface, refcount); + + if (refcount == 1) + { + ddraw_surface_add_iface(This); + } + + return refcount; +} + +static ULONG WINAPI ddraw_surface2_AddRef(IDirectDrawSurface2 *iface) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + ULONG refcount = InterlockedIncrement(&This->ref2); + + TRACE("iface %p increasing refcount to %u.\n", iface, refcount); + + if (refcount == 1) + { + ddraw_surface_add_iface(This); + } + + return refcount; +} + +static ULONG WINAPI ddraw_surface1_AddRef(IDirectDrawSurface *iface) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + ULONG refcount = InterlockedIncrement(&This->ref1); + + TRACE("iface %p increasing refcount to %u.\n", iface, refcount); + + if (refcount == 1) + { + ddraw_surface_add_iface(This); + } + + return refcount; } static ULONG WINAPI ddraw_gamma_control_AddRef(IDirectDrawGammaControl *iface) { - TRACE("iface %p.\n", iface); + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawGammaControl(iface); + ULONG refcount = InterlockedIncrement(&This->gamma_count); - return ddraw_surface7_AddRef((IDirectDrawSurface7 *)surface_from_gamma_control(iface)); + TRACE("iface %p increasing refcount to %u.\n", iface, refcount); + + if (refcount == 1) + { + ddraw_surface_add_iface(This); + } + + return refcount; } static ULONG WINAPI d3d_texture2_AddRef(IDirect3DTexture2 *iface) { + IDirectDrawSurfaceImpl *This = impl_from_IDirect3DTexture2(iface); TRACE("iface %p.\n", iface); - return ddraw_surface7_AddRef((IDirectDrawSurface7 *)surface_from_texture2(iface)); + return ddraw_surface1_AddRef(&This->IDirectDrawSurface_iface); } static ULONG WINAPI d3d_texture1_AddRef(IDirect3DTexture *iface) { + IDirectDrawSurfaceImpl *This = impl_from_IDirect3DTexture(iface); TRACE("iface %p.\n", iface); - return ddraw_surface7_AddRef((IDirectDrawSurface7 *)surface_from_texture1(iface)); + return ddraw_surface1_AddRef(&This->IDirectDrawSurface_iface); } /***************************************************************************** @@ -233,18 +430,19 @@ static ULONG WINAPI d3d_texture1_AddRef(IDirect3DTexture *iface) * This: Surface to free * *****************************************************************************/ -void ddraw_surface_destroy(IDirectDrawSurfaceImpl *This) +static void ddraw_surface_destroy(IDirectDrawSurfaceImpl *This) { TRACE("surface %p.\n", This); - /* Check the refcount and give a warning */ - if(This->ref > 1) + /* Check the iface count and give a warning */ + if(This->iface_count > 1) { /* This can happen when a complex surface is destroyed, * because the 2nd surface was addref()ed when the app * called GetAttachedSurface */ - WARN("(%p): Destroying surface with refount %d\n", This, This->ref); + WARN("(%p): Destroying surface with refcounts 7: %d 4: %d 3: %d 2: %d 1: %d\n", + This, This->ref7, This->ref4, This->ref3, This->ref2, This->ref1); } if (This->wined3d_surface) @@ -259,60 +457,9 @@ static void ddraw_surface_cleanup(IDirectDrawSurfaceImpl *surface) TRACE("surface %p.\n", surface); - if (surface->wined3d_swapchain) - { - IDirectDrawImpl *ddraw = surface->ddraw; - - /* If it's the render target, destroy the D3D device. */ - if (ddraw->d3d_initialized && surface == ddraw->d3d_target) - { - TRACE("Destroying the render target, uninitializing D3D.\n"); - - for (i = 0; i < ddraw->numConvertedDecls; ++i) - { - wined3d_vertex_declaration_decref(ddraw->decls[i].decl); - } - HeapFree(GetProcessHeap(), 0, ddraw->decls); - ddraw->numConvertedDecls = 0; - - if (FAILED(wined3d_device_uninit_3d(ddraw->wined3d_device))) - { - ERR("Failed to uninit 3D.\n"); - } - else - { - /* Free the d3d window if one was created. */ - if (ddraw->d3d_window && ddraw->d3d_window != ddraw->dest_window) - { - TRACE("Destroying the hidden render window %p.\n", ddraw->d3d_window); - DestroyWindow(ddraw->d3d_window); - ddraw->d3d_window = 0; - } - } - - ddraw->d3d_initialized = FALSE; - ddraw->d3d_target = NULL; - } - else - { - wined3d_device_uninit_gdi(ddraw->wined3d_device); - } - - surface->wined3d_swapchain = NULL; - - /* Reset to the default surface implementation type. This is needed - * if applications use non render target surfaces and expect blits to - * work after destroying the render target. - * - * TODO: Recreate existing offscreen surfaces. */ - ddraw->ImplType = DefaultSurfaceType; - - TRACE("D3D unloaded.\n"); - } - /* The refcount test shows that the palette is detached when the surface * is destroyed. */ - IDirectDrawSurface7_SetPalette((IDirectDrawSurface7 *)surface, NULL); + IDirectDrawSurface7_SetPalette(&surface->IDirectDrawSurface7_iface, NULL); /* Loop through all complex attached surfaces and destroy them. * @@ -343,6 +490,31 @@ static void ddraw_surface_cleanup(IDirectDrawSurfaceImpl *surface) IUnknown_Release(ifaceToRelease); } +ULONG ddraw_surface_release_iface(IDirectDrawSurfaceImpl *This) +{ + ULONG iface_count = InterlockedDecrement(&This->iface_count); + TRACE("%p decreasing iface count to %u.\n", This, iface_count); + + if (iface_count == 0) + { + /* Complex attached surfaces are destroyed implicitly when the root is released */ + wined3d_mutex_lock(); + if(!This->is_complex_root) + { + WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This); + wined3d_mutex_unlock(); + return iface_count; + } + if (This->wined3d_texture) /* If it's a texture, destroy the wined3d texture. */ + wined3d_texture_decref(This->wined3d_texture); + else + ddraw_surface_cleanup(This); + wined3d_mutex_unlock(); + } + + return iface_count; +} + /***************************************************************************** * IDirectDrawSurface7::Release * @@ -374,57 +546,108 @@ static void ddraw_surface_cleanup(IDirectDrawSurfaceImpl *surface) *****************************************************************************/ static ULONG WINAPI ddraw_surface7_Release(IDirectDrawSurface7 *iface) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; - ULONG ref = InterlockedDecrement(&This->ref); + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); + ULONG refcount = InterlockedDecrement(&This->ref7); - TRACE("%p decreasing refcount to %u.\n", This, ref); + TRACE("iface %p decreasing refcount to %u.\n", iface, refcount); - if (ref == 0) + if (refcount == 0) { - /* Complex attached surfaces are destroyed implicitly when the root is released */ - EnterCriticalSection(&ddraw_cs); - if(!This->is_complex_root) - { - WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This); - LeaveCriticalSection(&ddraw_cs); - return ref; - } - if (This->wined3d_texture) /* If it's a texture, destroy the wined3d texture. */ - wined3d_texture_decref(This->wined3d_texture); - else - ddraw_surface_cleanup(This); - LeaveCriticalSection(&ddraw_cs); + ddraw_surface_release_iface(This); } - return ref; + return refcount; +} + +static ULONG WINAPI ddraw_surface4_Release(IDirectDrawSurface4 *iface) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + ULONG refcount = InterlockedDecrement(&This->ref4); + + TRACE("iface %p decreasing refcount to %u.\n", iface, refcount); + + if (refcount == 0) + { + ddraw_surface_release_iface(This); + } + + return refcount; } static ULONG WINAPI ddraw_surface3_Release(IDirectDrawSurface3 *iface) { - TRACE("iface %p.\n", iface); + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + ULONG refcount = InterlockedDecrement(&This->ref3); - return ddraw_surface7_Release((IDirectDrawSurface7 *)surface_from_surface3(iface)); + TRACE("iface %p decreasing refcount to %u.\n", iface, refcount); + + if (refcount == 0) + { + ddraw_surface_release_iface(This); + } + + return refcount; +} + +static ULONG WINAPI ddraw_surface2_Release(IDirectDrawSurface2 *iface) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + ULONG refcount = InterlockedDecrement(&This->ref2); + + TRACE("iface %p decreasing refcount to %u.\n", iface, refcount); + + if (refcount == 0) + { + ddraw_surface_release_iface(This); + } + + return refcount; +} + +static ULONG WINAPI ddraw_surface1_Release(IDirectDrawSurface *iface) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + ULONG refcount = InterlockedDecrement(&This->ref1); + + TRACE("iface %p decreasing refcount to %u.\n", iface, refcount); + + if (refcount == 0) + { + ddraw_surface_release_iface(This); + } + + return refcount; } static ULONG WINAPI ddraw_gamma_control_Release(IDirectDrawGammaControl *iface) { - TRACE("iface %p.\n", iface); + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawGammaControl(iface); + ULONG refcount = InterlockedDecrement(&This->gamma_count); - return ddraw_surface7_Release((IDirectDrawSurface7 *)surface_from_gamma_control(iface)); + TRACE("iface %p decreasing refcount to %u.\n", iface, refcount); + + if (refcount == 0) + { + ddraw_surface_release_iface(This); + } + + return refcount; } static ULONG WINAPI d3d_texture2_Release(IDirect3DTexture2 *iface) { + IDirectDrawSurfaceImpl *This = impl_from_IDirect3DTexture2(iface); TRACE("iface %p.\n", iface); - return ddraw_surface7_Release((IDirectDrawSurface7 *)surface_from_texture2(iface)); + return ddraw_surface1_Release(&This->IDirectDrawSurface_iface); } static ULONG WINAPI d3d_texture1_Release(IDirect3DTexture *iface) { + IDirectDrawSurfaceImpl *This = impl_from_IDirect3DTexture(iface); TRACE("iface %p.\n", iface); - return ddraw_surface7_Release((IDirectDrawSurface7 *)surface_from_texture1(iface)); + return ddraw_surface1_Release(&This->IDirectDrawSurface_iface); } /***************************************************************************** @@ -457,14 +680,14 @@ static ULONG WINAPI d3d_texture1_Release(IDirect3DTexture *iface) static HRESULT WINAPI ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7 *iface, DDSCAPS2 *Caps, IDirectDrawSurface7 **Surface) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); IDirectDrawSurfaceImpl *surf; DDSCAPS2 our_caps; int i; TRACE("iface %p, caps %p, attachment %p.\n", iface, Caps, Surface); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if(This->version < 7) { @@ -506,9 +729,10 @@ static HRESULT WINAPI ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7 *ifa TRACE("(%p): Returning surface %p\n", This, surf); TRACE("(%p): mipmapcount=%d\n", This, surf->mipmap_level); - *Surface = (IDirectDrawSurface7 *)surf; + *Surface = &surf->IDirectDrawSurface7_iface; ddraw_surface7_AddRef(*Surface); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return DD_OK; } } @@ -531,24 +755,52 @@ static HRESULT WINAPI ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7 *ifa ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) { TRACE("(%p): Returning surface %p\n", This, surf); - *Surface = (IDirectDrawSurface7 *)surf; + *Surface = &surf->IDirectDrawSurface7_iface; ddraw_surface7_AddRef(*Surface); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DD_OK; } } TRACE("(%p) Didn't find a valid surface\n", This); - LeaveCriticalSection(&ddraw_cs); + + wined3d_mutex_unlock(); *Surface = NULL; return DDERR_NOTFOUND; } +static HRESULT WINAPI ddraw_surface4_GetAttachedSurface(IDirectDrawSurface4 *iface, + DDSCAPS2 *caps, IDirectDrawSurface4 **attachment) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + IDirectDrawSurface7 *attachment7; + IDirectDrawSurfaceImpl *attachment_impl; + HRESULT hr; + + TRACE("iface %p, caps %p, attachment %p.\n", iface, caps, attachment); + + hr = ddraw_surface7_GetAttachedSurface(&This->IDirectDrawSurface7_iface, + caps, &attachment7); + if (FAILED(hr)) + { + *attachment = NULL; + return hr; + } + attachment_impl = impl_from_IDirectDrawSurface7(attachment7); + *attachment = &attachment_impl->IDirectDrawSurface4_iface; + ddraw_surface4_AddRef(*attachment); + ddraw_surface7_Release(attachment7); + + return hr; +} + static HRESULT WINAPI ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3 *iface, DDSCAPS *caps, IDirectDrawSurface3 **attachment) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); IDirectDrawSurface7 *attachment7; + IDirectDrawSurfaceImpl *attachment_impl; DDSCAPS2 caps2; HRESULT hr; @@ -559,11 +811,79 @@ static HRESULT WINAPI ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3 *ifa caps2.dwCaps3 = 0; caps2.u1.dwCaps4 = 0; - hr = ddraw_surface7_GetAttachedSurface((IDirectDrawSurface7 *)surface_from_surface3(iface), + hr = ddraw_surface7_GetAttachedSurface(&This->IDirectDrawSurface7_iface, &caps2, &attachment7); - if (FAILED(hr)) *attachment = NULL; - else *attachment = attachment7 ? - (IDirectDrawSurface3 *)&((IDirectDrawSurfaceImpl *)attachment7)->IDirectDrawSurface3_vtbl : NULL; + if (FAILED(hr)) + { + *attachment = NULL; + return hr; + } + attachment_impl = impl_from_IDirectDrawSurface7(attachment7); + *attachment = &attachment_impl->IDirectDrawSurface3_iface; + ddraw_surface3_AddRef(*attachment); + ddraw_surface7_Release(attachment7); + + return hr; +} + +static HRESULT WINAPI ddraw_surface2_GetAttachedSurface(IDirectDrawSurface2 *iface, + DDSCAPS *caps, IDirectDrawSurface2 **attachment) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + IDirectDrawSurface7 *attachment7; + IDirectDrawSurfaceImpl *attachment_impl; + DDSCAPS2 caps2; + HRESULT hr; + + TRACE("iface %p, caps %p, attachment %p.\n", iface, caps, attachment); + + caps2.dwCaps = caps->dwCaps; + caps2.dwCaps2 = 0; + caps2.dwCaps3 = 0; + caps2.u1.dwCaps4 = 0; + + hr = ddraw_surface7_GetAttachedSurface(&This->IDirectDrawSurface7_iface, + &caps2, &attachment7); + if (FAILED(hr)) + { + *attachment = NULL; + return hr; + } + attachment_impl = impl_from_IDirectDrawSurface7(attachment7); + *attachment = &attachment_impl->IDirectDrawSurface2_iface; + ddraw_surface2_AddRef(*attachment); + ddraw_surface7_Release(attachment7); + + return hr; +} + +static HRESULT WINAPI ddraw_surface1_GetAttachedSurface(IDirectDrawSurface *iface, + DDSCAPS *caps, IDirectDrawSurface **attachment) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + IDirectDrawSurface7 *attachment7; + IDirectDrawSurfaceImpl *attachment_impl; + DDSCAPS2 caps2; + HRESULT hr; + + TRACE("iface %p, caps %p, attachment %p.\n", iface, caps, attachment); + + caps2.dwCaps = caps->dwCaps; + caps2.dwCaps2 = 0; + caps2.dwCaps3 = 0; + caps2.u1.dwCaps4 = 0; + + hr = ddraw_surface7_GetAttachedSurface(&This->IDirectDrawSurface7_iface, + &caps2, &attachment7); + if (FAILED(hr)) + { + *attachment = NULL; + return hr; + } + attachment_impl = impl_from_IDirectDrawSurface7(attachment7); + *attachment = &attachment_impl->IDirectDrawSurface_iface; + ddraw_surface1_AddRef(*attachment); + ddraw_surface7_Release(attachment7); return hr; } @@ -585,21 +905,17 @@ static HRESULT WINAPI ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3 *ifa * For more details, see IWineD3DSurface::LockRect * *****************************************************************************/ -static HRESULT WINAPI ddraw_surface7_Lock(IDirectDrawSurface7 *iface, +static HRESULT surface_lock(IDirectDrawSurfaceImpl *This, RECT *Rect, DDSURFACEDESC2 *DDSD, DWORD Flags, HANDLE h) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; - WINED3DLOCKED_RECT LockedRect; - HRESULT hr; + struct wined3d_mapped_rect mapped_rect; + HRESULT hr = DD_OK; - TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n", - iface, wine_dbgstr_rect(Rect), DDSD, Flags, h); - - if(!DDSD) - return DDERR_INVALIDPARAMS; + TRACE("This %p, rect %s, surface_desc %p, flags %#x, h %p.\n", + This, wine_dbgstr_rect(Rect), DDSD, Flags, h); /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */ - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); /* Should I check for the handle to be NULL? * @@ -607,14 +923,6 @@ static HRESULT WINAPI ddraw_surface7_Lock(IDirectDrawSurface7 *iface, * for the supported values. The others are ignored by WineD3D */ - if(DDSD->dwSize != sizeof(DDSURFACEDESC) && - DDSD->dwSize != sizeof(DDSURFACEDESC2)) - { - WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", DDERR_INVALIDPARAMS); - LeaveCriticalSection(&ddraw_cs); - return DDERR_INVALIDPARAMS; - } - /* Windows zeroes this if the rect is invalid */ DDSD->lpSurface = 0; @@ -628,15 +936,18 @@ static HRESULT WINAPI ddraw_surface7_Lock(IDirectDrawSurface7 *iface, || (Rect->bottom > This->surface_desc.dwHeight)) { WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } } - hr = wined3d_surface_map(This->wined3d_surface, &LockedRect, Rect, Flags); + if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) + hr = ddraw_surface_update_frontbuffer(This, Rect, TRUE); + if (SUCCEEDED(hr)) + hr = wined3d_surface_map(This->wined3d_surface, &mapped_rect, Rect, Flags); if (FAILED(hr)) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); switch(hr) { /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more @@ -650,28 +961,138 @@ static HRESULT WINAPI ddraw_surface7_Lock(IDirectDrawSurface7 *iface, } } + if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) + { + if (Flags & DDLOCK_READONLY) + memset(&This->ddraw->primary_lock, 0, sizeof(This->ddraw->primary_lock)); + else if (Rect) + This->ddraw->primary_lock = *Rect; + else + SetRect(&This->ddraw->primary_lock, 0, 0, This->surface_desc.dwWidth, This->surface_desc.dwHeight); + } + /* Override the memory area. The pitch should be set already. Strangely windows * does not set the LPSURFACE flag on locked surfaces !?!. * DDSD->dwFlags |= DDSD_LPSURFACE; */ - This->surface_desc.lpSurface = LockedRect.pBits; + This->surface_desc.lpSurface = mapped_rect.data; DD_STRUCT_COPY_BYSIZE(DDSD,&(This->surface_desc)); TRACE("locked surface returning description :\n"); if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return DD_OK; } +static HRESULT WINAPI ddraw_surface7_Lock(IDirectDrawSurface7 *iface, + RECT *rect, DDSURFACEDESC2 *surface_desc, DWORD flags, HANDLE h) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); + TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n", + iface, wine_dbgstr_rect(rect), surface_desc, flags, h); + + if (!surface_desc) return DDERR_INVALIDPARAMS; + if (surface_desc->dwSize != sizeof(DDSURFACEDESC) && + surface_desc->dwSize != sizeof(DDSURFACEDESC2)) + { + WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc->dwSize); + return DDERR_INVALIDPARAMS; + } + return surface_lock(This, rect, surface_desc, flags, h); +} + +static HRESULT WINAPI ddraw_surface4_Lock(IDirectDrawSurface4 *iface, RECT *rect, + DDSURFACEDESC2 *surface_desc, DWORD flags, HANDLE h) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n", + iface, wine_dbgstr_rect(rect), surface_desc, flags, h); + + if (!surface_desc) return DDERR_INVALIDPARAMS; + if (surface_desc->dwSize != sizeof(DDSURFACEDESC) && + surface_desc->dwSize != sizeof(DDSURFACEDESC2)) + { + WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc->dwSize); + return DDERR_INVALIDPARAMS; + } + return surface_lock(This, rect, surface_desc, flags, h); +} + static HRESULT WINAPI ddraw_surface3_Lock(IDirectDrawSurface3 *iface, RECT *rect, DDSURFACEDESC *surface_desc, DWORD flags, HANDLE h) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + DDSURFACEDESC2 surface_desc2; + HRESULT hr; TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n", iface, wine_dbgstr_rect(rect), surface_desc, flags, h); - return ddraw_surface7_Lock((IDirectDrawSurface7 *)surface_from_surface3(iface), - rect, (DDSURFACEDESC2 *)surface_desc, flags, h); + if (!surface_desc) return DDERR_INVALIDPARAMS; + if (surface_desc->dwSize != sizeof(DDSURFACEDESC) && + surface_desc->dwSize != sizeof(DDSURFACEDESC2)) + { + WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc->dwSize); + return DDERR_INVALIDPARAMS; + } + + surface_desc2.dwSize = surface_desc->dwSize; + surface_desc2.dwFlags = 0; + hr = surface_lock(This, rect, &surface_desc2, flags, h); + DDSD2_to_DDSD(&surface_desc2, surface_desc); + surface_desc->dwSize = surface_desc2.dwSize; + return hr; +} + +static HRESULT WINAPI ddraw_surface2_Lock(IDirectDrawSurface2 *iface, RECT *rect, + DDSURFACEDESC *surface_desc, DWORD flags, HANDLE h) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + DDSURFACEDESC2 surface_desc2; + HRESULT hr; + TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n", + iface, wine_dbgstr_rect(rect), surface_desc, flags, h); + + if (!surface_desc) return DDERR_INVALIDPARAMS; + if (surface_desc->dwSize != sizeof(DDSURFACEDESC) && + surface_desc->dwSize != sizeof(DDSURFACEDESC2)) + { + WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc->dwSize); + return DDERR_INVALIDPARAMS; + } + + surface_desc2.dwSize = surface_desc->dwSize; + surface_desc2.dwFlags = 0; + hr = surface_lock(This, rect, &surface_desc2, flags, h); + DDSD2_to_DDSD(&surface_desc2, surface_desc); + surface_desc->dwSize = surface_desc2.dwSize; + return hr; +} + +static HRESULT WINAPI ddraw_surface1_Lock(IDirectDrawSurface *iface, RECT *rect, + DDSURFACEDESC *surface_desc, DWORD flags, HANDLE h) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + DDSURFACEDESC2 surface_desc2; + HRESULT hr; + TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n", + iface, wine_dbgstr_rect(rect), surface_desc, flags, h); + + if (!surface_desc) return DDERR_INVALIDPARAMS; + if (surface_desc->dwSize != sizeof(DDSURFACEDESC) && + surface_desc->dwSize != sizeof(DDSURFACEDESC2)) + { + WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc->dwSize); + return DDERR_INVALIDPARAMS; + } + + surface_desc2.dwSize = surface_desc->dwSize; + surface_desc2.dwFlags = 0; + hr = surface_lock(This, rect, &surface_desc2, flags, h); + DDSD2_to_DDSD(&surface_desc2, surface_desc); + surface_desc->dwSize = surface_desc2.dwSize; + return hr; } /***************************************************************************** @@ -689,27 +1110,57 @@ static HRESULT WINAPI ddraw_surface3_Lock(IDirectDrawSurface3 *iface, RECT *rect *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_Unlock(IDirectDrawSurface7 *iface, RECT *pRect) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); HRESULT hr; TRACE("iface %p, rect %s.\n", iface, wine_dbgstr_rect(pRect)); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_surface_unmap(This->wined3d_surface); if (SUCCEEDED(hr)) { + if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) + hr = ddraw_surface_update_frontbuffer(This, &This->ddraw->primary_lock, FALSE); This->surface_desc.lpSurface = NULL; } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } +static HRESULT WINAPI ddraw_surface4_Unlock(IDirectDrawSurface4 *iface, RECT *pRect) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, rect %p.\n", iface, pRect); + + return ddraw_surface7_Unlock(&This->IDirectDrawSurface7_iface, pRect); +} + static HRESULT WINAPI ddraw_surface3_Unlock(IDirectDrawSurface3 *iface, void *data) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); TRACE("iface %p, data %p.\n", iface, data); /* data might not be the LPRECT of later versions, so drop it. */ - return ddraw_surface7_Unlock((IDirectDrawSurface7 *)surface_from_surface3(iface), NULL); + return ddraw_surface7_Unlock(&This->IDirectDrawSurface7_iface, NULL); +} + +static HRESULT WINAPI ddraw_surface2_Unlock(IDirectDrawSurface2 *iface, void *data) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, data %p.\n", iface, data); + + /* data might not be the LPRECT of later versions, so drop it. */ + return ddraw_surface7_Unlock(&This->IDirectDrawSurface7_iface, NULL); +} + +static HRESULT WINAPI ddraw_surface1_Unlock(IDirectDrawSurface *iface, void *data) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, data %p.\n", iface, data); + + /* data might not be the LPRECT of later versions, so drop it. */ + return ddraw_surface7_Unlock(&This->IDirectDrawSurface7_iface, NULL); } /***************************************************************************** @@ -733,8 +1184,8 @@ static HRESULT WINAPI ddraw_surface3_Unlock(IDirectDrawSurface3 *iface, void *da *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_Flip(IDirectDrawSurface7 *iface, IDirectDrawSurface7 *DestOverride, DWORD Flags) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; - IDirectDrawSurfaceImpl *Override = (IDirectDrawSurfaceImpl *)DestOverride; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); + IDirectDrawSurfaceImpl *Override = unsafe_impl_from_IDirectDrawSurface7(DestOverride); IDirectDrawSurface7 *Override7; HRESULT hr; @@ -746,7 +1197,7 @@ static HRESULT WINAPI ddraw_surface7_Flip(IDirectDrawSurface7 *iface, IDirectDra if( !(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_OVERLAY)) ) return DDERR_INVALIDOBJECT; /* Unchecked */ - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); /* WineD3D doesn't keep track of attached surface, so find the target */ if(!Override) @@ -759,26 +1210,183 @@ static HRESULT WINAPI ddraw_surface7_Flip(IDirectDrawSurface7 *iface, IDirectDra if(hr != DD_OK) { ERR("Can't find a flip target\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_NOTFLIPPABLE; /* Unchecked */ } - Override = (IDirectDrawSurfaceImpl *)Override7; + Override = impl_from_IDirectDrawSurface7(Override7); /* For the GetAttachedSurface */ ddraw_surface7_Release(Override7); } hr = wined3d_surface_flip(This->wined3d_surface, Override->wined3d_surface, Flags); - LeaveCriticalSection(&ddraw_cs); + if (SUCCEEDED(hr) && This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) + hr = ddraw_surface_update_frontbuffer(This, NULL, FALSE); + + wined3d_mutex_unlock(); + return hr; } +static HRESULT WINAPI ddraw_surface4_Flip(IDirectDrawSurface4 *iface, IDirectDrawSurface4 *dst, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + IDirectDrawSurfaceImpl *dst_impl = unsafe_impl_from_IDirectDrawSurface4(dst); + TRACE("iface %p, dst %p, flags %#x.\n", iface, dst, flags); + + return ddraw_surface7_Flip(&This->IDirectDrawSurface7_iface, + dst_impl ? &dst_impl->IDirectDrawSurface7_iface : NULL, flags); +} + static HRESULT WINAPI ddraw_surface3_Flip(IDirectDrawSurface3 *iface, IDirectDrawSurface3 *dst, DWORD flags) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + IDirectDrawSurfaceImpl *dst_impl = unsafe_impl_from_IDirectDrawSurface3(dst); TRACE("iface %p, dst %p, flags %#x.\n", iface, dst, flags); - return ddraw_surface7_Flip((IDirectDrawSurface7 *)surface_from_surface3(iface), - dst ? (IDirectDrawSurface7 *)surface_from_surface3(dst) : NULL, flags); + return ddraw_surface7_Flip(&This->IDirectDrawSurface7_iface, + dst_impl ? &dst_impl->IDirectDrawSurface7_iface : NULL, flags); +} + +static HRESULT WINAPI ddraw_surface2_Flip(IDirectDrawSurface2 *iface, IDirectDrawSurface2 *dst, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + IDirectDrawSurfaceImpl *dst_impl = unsafe_impl_from_IDirectDrawSurface2(dst); + TRACE("iface %p, dst %p, flags %#x.\n", iface, dst, flags); + + return ddraw_surface7_Flip(&This->IDirectDrawSurface7_iface, + dst_impl ? &dst_impl->IDirectDrawSurface7_iface : NULL, flags); +} + +static HRESULT WINAPI ddraw_surface1_Flip(IDirectDrawSurface *iface, IDirectDrawSurface *dst, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + IDirectDrawSurfaceImpl *dst_impl = unsafe_impl_from_IDirectDrawSurface(dst); + TRACE("iface %p, dst %p, flags %#x.\n", iface, dst, flags); + + return ddraw_surface7_Flip(&This->IDirectDrawSurface7_iface, + dst_impl ? &dst_impl->IDirectDrawSurface7_iface : NULL, flags); +} + +static HRESULT ddraw_surface_blt_clipped(IDirectDrawSurfaceImpl *dst_surface, const RECT *dst_rect_in, + IDirectDrawSurfaceImpl *src_surface, const RECT *src_rect_in, DWORD flags, + const WINEDDBLTFX *fx, enum wined3d_texture_filter_type filter) +{ + struct wined3d_surface *wined3d_src_surface = src_surface ? src_surface->wined3d_surface : NULL; + RECT src_rect, dst_rect; + float scale_x, scale_y; + const RECT *clip_rect; + UINT clip_list_size; + RGNDATA *clip_list; + HRESULT hr = DD_OK; + UINT i; + + if (!dst_surface->clipper) + { + if (src_surface && src_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) + hr = ddraw_surface_update_frontbuffer(src_surface, src_rect_in, TRUE); + if (SUCCEEDED(hr)) + hr = wined3d_surface_blt(dst_surface->wined3d_surface, dst_rect_in, + wined3d_src_surface, src_rect_in, flags, fx, filter); + if (SUCCEEDED(hr) && (dst_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)) + hr = ddraw_surface_update_frontbuffer(dst_surface, dst_rect_in, FALSE); + + return hr; + } + + if (!dst_rect_in) + { + dst_rect.left = 0; + dst_rect.top = 0; + dst_rect.right = dst_surface->surface_desc.dwWidth; + dst_rect.bottom = dst_surface->surface_desc.dwHeight; + } + else + { + dst_rect = *dst_rect_in; + } + + if (IsRectEmpty(&dst_rect)) + return DDERR_INVALIDRECT; + + if (src_surface) + { + if (!src_rect_in) + { + src_rect.left = 0; + src_rect.top = 0; + src_rect.right = src_surface->surface_desc.dwWidth; + src_rect.bottom = src_surface->surface_desc.dwHeight; + } + else + { + src_rect = *src_rect_in; + } + + if (IsRectEmpty(&src_rect)) + return DDERR_INVALIDRECT; + } + else + { + SetRect(&src_rect, 0, 0, 0, 0); + } + + scale_x = (float)(src_rect.right - src_rect.left) / (float)(dst_rect.right - dst_rect.left); + scale_y = (float)(src_rect.bottom - src_rect.top) / (float)(dst_rect.bottom - dst_rect.top); + + if (FAILED(hr = IDirectDrawClipper_GetClipList(&dst_surface->clipper->IDirectDrawClipper_iface, + &dst_rect, NULL, &clip_list_size))) + { + WARN("Failed to get clip list size, hr %#x.\n", hr); + return hr; + } + + if (!(clip_list = HeapAlloc(GetProcessHeap(), 0, clip_list_size))) + { + WARN("Failed to allocate clip list.\n"); + return E_OUTOFMEMORY; + } + + if (FAILED(hr = IDirectDrawClipper_GetClipList(&dst_surface->clipper->IDirectDrawClipper_iface, + &dst_rect, clip_list, &clip_list_size))) + { + WARN("Failed to get clip list, hr %#x.\n", hr); + HeapFree(GetProcessHeap(), 0, clip_list); + return hr; + } + + clip_rect = (RECT *)clip_list->Buffer; + for (i = 0; i < clip_list->rdh.nCount; ++i) + { + RECT src_rect_clipped = src_rect; + + if (src_surface) + { + src_rect_clipped.left += (LONG)((clip_rect[i].left - dst_rect.left) * scale_x); + src_rect_clipped.top += (LONG)((clip_rect[i].top - dst_rect.top) * scale_y); + src_rect_clipped.right -= (LONG)((dst_rect.right - clip_rect[i].right) * scale_x); + src_rect_clipped.bottom -= (LONG)((dst_rect.bottom - clip_rect[i].bottom) * scale_y); + + if (src_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) + { + if (FAILED(hr = ddraw_surface_update_frontbuffer(src_surface, &src_rect_clipped, TRUE))) + break; + } + } + + if (FAILED(hr = wined3d_surface_blt(dst_surface->wined3d_surface, &clip_rect[i], + wined3d_src_surface, &src_rect_clipped, flags, fx, filter))) + break; + + if (dst_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) + { + if (FAILED(hr = ddraw_surface_update_frontbuffer(dst_surface, &clip_rect[i], FALSE))) + break; + } + } + + HeapFree(GetProcessHeap(), 0, clip_list); + return hr; } /***************************************************************************** @@ -801,9 +1409,9 @@ static HRESULT WINAPI ddraw_surface3_Flip(IDirectDrawSurface3 *iface, IDirectDra static HRESULT WINAPI ddraw_surface7_Blt(IDirectDrawSurface7 *iface, RECT *DestRect, IDirectDrawSurface7 *SrcSurface, RECT *SrcRect, DWORD Flags, DDBLTFX *DDBltFx) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; - IDirectDrawSurfaceImpl *Src = (IDirectDrawSurfaceImpl *)SrcSurface; - HRESULT hr; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); + IDirectDrawSurfaceImpl *Src = unsafe_impl_from_IDirectDrawSurface7(SrcSurface); + HRESULT hr = DD_OK; TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n", iface, wine_dbgstr_rect(DestRect), SrcSurface, wine_dbgstr_rect(SrcRect), Flags, DDBltFx); @@ -821,34 +1429,11 @@ static HRESULT WINAPI ddraw_surface7_Blt(IDirectDrawSurface7 *iface, RECT *DestR return DDERR_INVALIDPARAMS; } - /* Sizes can change, therefore hold the lock when testing the rectangles */ - EnterCriticalSection(&ddraw_cs); - if(DestRect) - { - if(DestRect->top >= DestRect->bottom || DestRect->left >= DestRect->right || - DestRect->right > This->surface_desc.dwWidth || - DestRect->bottom > This->surface_desc.dwHeight) - { - WARN("Destination rectangle is invalid, returning DDERR_INVALIDRECT\n"); - LeaveCriticalSection(&ddraw_cs); - return DDERR_INVALIDRECT; - } - } - if(Src && SrcRect) - { - if(SrcRect->top >= SrcRect->bottom || SrcRect->left >=SrcRect->right || - SrcRect->right > Src->surface_desc.dwWidth || - SrcRect->bottom > Src->surface_desc.dwHeight) - { - WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n"); - LeaveCriticalSection(&ddraw_cs); - return DDERR_INVALIDRECT; - } - } + wined3d_mutex_lock(); if(Flags & DDBLT_KEYSRC && (!Src || !(Src->surface_desc.dwFlags & DDSD_CKSRCBLT))) { WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } @@ -856,10 +1441,10 @@ static HRESULT WINAPI ddraw_surface7_Blt(IDirectDrawSurface7 *iface, RECT *DestR * does, copy the struct, and replace the ddraw surfaces with the wined3d * surfaces. So far no blitting operations using surfaces in the bltfx * struct are supported anyway. */ - hr = wined3d_surface_blt(This->wined3d_surface, DestRect, Src ? Src->wined3d_surface : NULL, - SrcRect, Flags, (WINEDDBLTFX *)DDBltFx, WINED3DTEXF_LINEAR); + hr = ddraw_surface_blt_clipped(This, DestRect, Src, SrcRect, + Flags, (WINEDDBLTFX *)DDBltFx, WINED3D_TEXF_LINEAR); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); switch(hr) { case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED; @@ -868,14 +1453,52 @@ static HRESULT WINAPI ddraw_surface7_Blt(IDirectDrawSurface7 *iface, RECT *DestR } } -static HRESULT WINAPI ddraw_surface3_Blt(IDirectDrawSurface3 *iface, RECT *dst_rect, - IDirectDrawSurface3 *src_surface, RECT *src_rect, DWORD flags, DDBLTFX *fx) +static HRESULT WINAPI ddraw_surface4_Blt(IDirectDrawSurface4 *iface, RECT *dst_rect, + IDirectDrawSurface4 *src_surface, RECT *src_rect, DWORD flags, DDBLTFX *fx) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + IDirectDrawSurfaceImpl *src = unsafe_impl_from_IDirectDrawSurface4(src_surface); TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n", iface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect), flags, fx); - return ddraw_surface7_Blt((IDirectDrawSurface7 *)surface_from_surface3(iface), dst_rect, - src_surface ? (IDirectDrawSurface7 *)surface_from_surface3(src_surface) : NULL, src_rect, flags, fx); + return ddraw_surface7_Blt(&This->IDirectDrawSurface7_iface, dst_rect, + src ? &src->IDirectDrawSurface7_iface : NULL, src_rect, flags, fx); +} + +static HRESULT WINAPI ddraw_surface3_Blt(IDirectDrawSurface3 *iface, RECT *dst_rect, + IDirectDrawSurface3 *src_surface, RECT *src_rect, DWORD flags, DDBLTFX *fx) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface3(src_surface); + TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n", + iface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect), flags, fx); + + return ddraw_surface7_Blt(&This->IDirectDrawSurface7_iface, dst_rect, + src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, src_rect, flags, fx); +} + +static HRESULT WINAPI ddraw_surface2_Blt(IDirectDrawSurface2 *iface, RECT *dst_rect, + IDirectDrawSurface2 *src_surface, RECT *src_rect, DWORD flags, DDBLTFX *fx) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface2(src_surface); + TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n", + iface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect), flags, fx); + + return ddraw_surface7_Blt(&This->IDirectDrawSurface7_iface, dst_rect, + src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, src_rect, flags, fx); +} + +static HRESULT WINAPI ddraw_surface1_Blt(IDirectDrawSurface *iface, RECT *dst_rect, + IDirectDrawSurface *src_surface, RECT *src_rect, DWORD flags, DDBLTFX *fx) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface(src_surface); + TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n", + iface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect), flags, fx); + + return ddraw_surface7_Blt(&This->IDirectDrawSurface7_iface, dst_rect, + src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, src_rect, flags, fx); } /***************************************************************************** @@ -883,7 +1506,7 @@ static HRESULT WINAPI ddraw_surface3_Blt(IDirectDrawSurface3 *iface, RECT *dst_r * * Attaches a surface to another surface. How the surface attachments work * is not totally understood yet, and this method is prone to problems. - * he surface that is attached is AddRef-ed. + * The surface that is attached is AddRef-ed. * * Tests with complex surfaces suggest that the surface attachments form a * tree, but no method to test this has been found yet. @@ -929,7 +1552,7 @@ static HRESULT ddraw_surface_attach_surface(IDirectDrawSurfaceImpl *This, IDirec if(Surf == This) return DDERR_CANNOTATTACHSURFACE; /* unchecked */ - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); /* Check if the surface is already attached somewhere */ if (Surf->next_attached || Surf->first_attached != Surf) @@ -940,7 +1563,7 @@ static HRESULT ddraw_surface_attach_surface(IDirectDrawSurfaceImpl *This, IDirec WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n", Surf, Surf->next_attached, Surf->first_attached); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_SURFACEALREADYATTACHED; } @@ -955,34 +1578,62 @@ static HRESULT ddraw_surface_attach_surface(IDirectDrawSurfaceImpl *This, IDirec IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice); } - ddraw_surface7_AddRef((IDirectDrawSurface7 *)Surf); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return DD_OK; } -static HRESULT WINAPI ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7 *iface, IDirectDrawSurface7 *Attach) +static HRESULT WINAPI ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7 *iface, IDirectDrawSurface7 *attachment) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; - IDirectDrawSurfaceImpl *Surf = (IDirectDrawSurfaceImpl *)Attach; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); + IDirectDrawSurfaceImpl *attachment_impl = unsafe_impl_from_IDirectDrawSurface7(attachment); + HRESULT hr; - TRACE("iface %p, attachment %p.\n", iface, Attach); + TRACE("iface %p, attachment %p.\n", iface, attachment); /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */ - if(!(Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER)) + if(!(attachment_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER)) { WARN("Application tries to attach a non Z buffer surface. caps %08x\n", - Surf->surface_desc.ddsCaps.dwCaps); + attachment_impl->surface_desc.ddsCaps.dwCaps); return DDERR_CANNOTATTACHSURFACE; } - return ddraw_surface_attach_surface(This, Surf); + hr = ddraw_surface_attach_surface(This, attachment_impl); + if (FAILED(hr)) + { + return hr; + } + ddraw_surface7_AddRef(attachment); + attachment_impl->attached_iface = (IUnknown *)attachment; + return hr; } +static HRESULT WINAPI ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4 *iface, IDirectDrawSurface4 *attachment) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + IDirectDrawSurfaceImpl *attachment_impl = unsafe_impl_from_IDirectDrawSurface4(attachment); + HRESULT hr; + + TRACE("iface %p, attachment %p.\n", iface, attachment); + + hr = ddraw_surface7_AddAttachedSurface(&This->IDirectDrawSurface7_iface, + attachment_impl ? &attachment_impl->IDirectDrawSurface7_iface : NULL); + if (FAILED(hr)) + { + return hr; + } + ddraw_surface4_AddRef(attachment); + ddraw_surface7_Release(&attachment_impl->IDirectDrawSurface7_iface); + attachment_impl->attached_iface = (IUnknown *)attachment; + return hr; +} static HRESULT WINAPI ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3 *iface, IDirectDrawSurface3 *attachment) { - IDirectDrawSurfaceImpl *surface = surface_from_surface3(iface); - IDirectDrawSurfaceImpl *attach_impl = surface_from_surface3(attachment); + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + IDirectDrawSurfaceImpl *attachment_impl = unsafe_impl_from_IDirectDrawSurface3(attachment); + HRESULT hr; TRACE("iface %p, attachment %p.\n", iface, attachment); @@ -991,20 +1642,20 @@ static HRESULT WINAPI ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3 *ifa * -> offscreen plain surfaces can be attached to primaries * -> primaries can be attached to offscreen plain surfaces * -> z buffers can be attached to primaries */ - if (surface->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_OFFSCREENPLAIN) - && attach_impl->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_OFFSCREENPLAIN)) + if (This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_OFFSCREENPLAIN) + && attachment_impl->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_OFFSCREENPLAIN)) { /* Sizes have to match */ - if (attach_impl->surface_desc.dwWidth != surface->surface_desc.dwWidth - || attach_impl->surface_desc.dwHeight != surface->surface_desc.dwHeight) + if (attachment_impl->surface_desc.dwWidth != This->surface_desc.dwWidth + || attachment_impl->surface_desc.dwHeight != This->surface_desc.dwHeight) { WARN("Surface sizes do not match.\n"); return DDERR_CANNOTATTACHSURFACE; } /* OK */ } - else if (surface->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE) - && attach_impl->surface_desc.ddsCaps.dwCaps & (DDSCAPS_ZBUFFER)) + else if (This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE) + && attachment_impl->surface_desc.ddsCaps.dwCaps & (DDSCAPS_ZBUFFER)) { /* OK */ } @@ -1014,7 +1665,54 @@ static HRESULT WINAPI ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3 *ifa return DDERR_CANNOTATTACHSURFACE; } - return ddraw_surface_attach_surface(surface, attach_impl); + hr = ddraw_surface_attach_surface(This, attachment_impl); + if (FAILED(hr)) + { + return hr; + } + ddraw_surface3_AddRef(attachment); + attachment_impl->attached_iface = (IUnknown *)attachment; + return hr; +} + +static HRESULT WINAPI ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2 *iface, IDirectDrawSurface2 *attachment) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + IDirectDrawSurfaceImpl *attachment_impl = unsafe_impl_from_IDirectDrawSurface2(attachment); + HRESULT hr; + + TRACE("iface %p, attachment %p.\n", iface, attachment); + + hr = ddraw_surface3_AddAttachedSurface(&This->IDirectDrawSurface3_iface, + attachment_impl ? &attachment_impl->IDirectDrawSurface3_iface : NULL); + if (FAILED(hr)) + { + return hr; + } + ddraw_surface2_AddRef(attachment); + ddraw_surface3_Release(&attachment_impl->IDirectDrawSurface3_iface); + attachment_impl->attached_iface = (IUnknown *)attachment; + return hr; +} + +static HRESULT WINAPI ddraw_surface1_AddAttachedSurface(IDirectDrawSurface *iface, IDirectDrawSurface *attachment) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + IDirectDrawSurfaceImpl *attachment_impl = unsafe_impl_from_IDirectDrawSurface(attachment); + HRESULT hr; + + TRACE("iface %p, attachment %p.\n", iface, attachment); + + hr = ddraw_surface3_AddAttachedSurface(&This->IDirectDrawSurface3_iface, + attachment_impl ? &attachment_impl->IDirectDrawSurface3_iface : NULL); + if (FAILED(hr)) + { + return hr; + } + ddraw_surface1_AddRef(attachment); + ddraw_surface3_Release(&attachment_impl->IDirectDrawSurface3_iface); + attachment_impl->attached_iface = (IUnknown *)attachment; + return hr; } /***************************************************************************** @@ -1032,22 +1730,27 @@ static HRESULT WINAPI ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3 *ifa * DDERR_SURFACENOTATTACHED if the surface isn't attached to * *****************************************************************************/ -static HRESULT WINAPI ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7 *iface, - DWORD Flags, IDirectDrawSurface7 *Attach) +static HRESULT ddraw_surface_delete_attached_surface(IDirectDrawSurfaceImpl *This, + IDirectDrawSurfaceImpl *Surf, IUnknown *detach_iface) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; - IDirectDrawSurfaceImpl *Surf = (IDirectDrawSurfaceImpl *)Attach; IDirectDrawSurfaceImpl *Prev = This; - TRACE("iface %p, flags %#x, attachment %p.\n", iface, Flags, Attach); + TRACE("surface %p, attachment %p, detach_iface %p.\n", This, Surf, detach_iface); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if (!Surf || (Surf->first_attached != This) || (Surf == This) ) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_CANNOTDETACHSURFACE; } + if (Surf->attached_iface != detach_iface) + { + WARN("Surf->attach_iface %p != detach_iface %p.\n", Surf->attached_iface, detach_iface); + wined3d_mutex_unlock(); + return DDERR_SURFACENOTATTACHED; + } + /* Remove MIPMAPSUBLEVEL if this seemed to be one */ if (This->surface_desc.ddsCaps.dwCaps & Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP) @@ -1077,19 +1780,69 @@ static HRESULT WINAPI ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7 * { IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice); } + wined3d_mutex_unlock(); + + /* Set attached_iface to NULL before releasing it, the surface may go + * away. */ + Surf->attached_iface = NULL; + IUnknown_Release(detach_iface); - ddraw_surface7_Release(Attach); - LeaveCriticalSection(&ddraw_cs); return DD_OK; } +static HRESULT WINAPI ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7 *iface, + DWORD flags, IDirectDrawSurface7 *attachment) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); + IDirectDrawSurfaceImpl *attachment_impl = unsafe_impl_from_IDirectDrawSurface7(attachment); + + TRACE("iface %p, flags %#x, attachment %p.\n", iface, flags, attachment); + + return ddraw_surface_delete_attached_surface(This, attachment_impl, (IUnknown *)attachment); +} + +static HRESULT WINAPI ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4 *iface, + DWORD flags, IDirectDrawSurface4 *attachment) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + IDirectDrawSurfaceImpl *attachment_impl = unsafe_impl_from_IDirectDrawSurface4(attachment); + + TRACE("iface %p, flags %#x, attachment %p.\n", iface, flags, attachment); + + return ddraw_surface_delete_attached_surface(This, attachment_impl, (IUnknown *)attachment); +} + static HRESULT WINAPI ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3 *iface, DWORD flags, IDirectDrawSurface3 *attachment) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + IDirectDrawSurfaceImpl *attachment_impl = unsafe_impl_from_IDirectDrawSurface3(attachment); + TRACE("iface %p, flags %#x, attachment %p.\n", iface, flags, attachment); - return ddraw_surface7_DeleteAttachedSurface((IDirectDrawSurface7 *)surface_from_surface3(iface), flags, - attachment ? (IDirectDrawSurface7 *)surface_from_surface3(attachment) : NULL); + return ddraw_surface_delete_attached_surface(This, attachment_impl, (IUnknown *)attachment); +} + +static HRESULT WINAPI ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2 *iface, + DWORD flags, IDirectDrawSurface2 *attachment) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + IDirectDrawSurfaceImpl *attachment_impl = unsafe_impl_from_IDirectDrawSurface2(attachment); + + TRACE("iface %p, flags %#x, attachment %p.\n", iface, flags, attachment); + + return ddraw_surface_delete_attached_surface(This, attachment_impl, (IUnknown *)attachment); +} + +static HRESULT WINAPI ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface *iface, + DWORD flags, IDirectDrawSurface *attachment) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + IDirectDrawSurfaceImpl *attachment_impl = unsafe_impl_from_IDirectDrawSurface(attachment); + + TRACE("iface %p, flags %#x, attachment %p.\n", iface, flags, attachment); + + return ddraw_surface_delete_attached_surface(This, attachment_impl, (IUnknown *)attachment); } /***************************************************************************** @@ -1111,11 +1864,36 @@ static HRESULT WINAPI ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7 *if return DDERR_UNSUPPORTED; /* unchecked */ } -static HRESULT WINAPI ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3 *iface, RECT *rect) +static HRESULT WINAPI ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4 *iface, RECT *rect) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); TRACE("iface %p, rect %s.\n", iface, wine_dbgstr_rect(rect)); - return ddraw_surface7_AddOverlayDirtyRect((IDirectDrawSurface7 *)surface_from_surface3(iface), rect); + return ddraw_surface7_AddOverlayDirtyRect(&This->IDirectDrawSurface7_iface, rect); +} + +static HRESULT WINAPI ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3 *iface, RECT *rect) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + TRACE("iface %p, rect %s.\n", iface, wine_dbgstr_rect(rect)); + + return ddraw_surface7_AddOverlayDirtyRect(&This->IDirectDrawSurface7_iface, rect); +} + +static HRESULT WINAPI ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2 *iface, RECT *rect) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, rect %s.\n", iface, wine_dbgstr_rect(rect)); + + return ddraw_surface7_AddOverlayDirtyRect(&This->IDirectDrawSurface7_iface, rect); +} + +static HRESULT WINAPI ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface *iface, RECT *rect) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, rect %s.\n", iface, wine_dbgstr_rect(rect)); + + return ddraw_surface7_AddOverlayDirtyRect(&This->IDirectDrawSurface7_iface, rect); } /***************************************************************************** @@ -1134,17 +1912,20 @@ static HRESULT WINAPI ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3 *if *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_GetDC(IDirectDrawSurface7 *iface, HDC *hdc) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; - HRESULT hr; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); + HRESULT hr = DD_OK; TRACE("iface %p, dc %p.\n", iface, hdc); if(!hdc) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); - hr = wined3d_surface_getdc(This->wined3d_surface, hdc); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); + if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) + hr = ddraw_surface_update_frontbuffer(This, NULL, TRUE); + if (SUCCEEDED(hr)) + hr = wined3d_surface_getdc(This->wined3d_surface, hdc); + wined3d_mutex_unlock(); switch(hr) { /* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not @@ -1158,11 +1939,36 @@ static HRESULT WINAPI ddraw_surface7_GetDC(IDirectDrawSurface7 *iface, HDC *hdc) } } -static HRESULT WINAPI ddraw_surface3_GetDC(IDirectDrawSurface3 *iface, HDC *dc) +static HRESULT WINAPI ddraw_surface4_GetDC(IDirectDrawSurface4 *iface, HDC *dc) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); TRACE("iface %p, dc %p.\n", iface, dc); - return ddraw_surface7_GetDC((IDirectDrawSurface7 *)surface_from_surface3(iface), dc); + return ddraw_surface7_GetDC(&This->IDirectDrawSurface7_iface, dc); +} + +static HRESULT WINAPI ddraw_surface3_GetDC(IDirectDrawSurface3 *iface, HDC *dc) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + TRACE("iface %p, dc %p.\n", iface, dc); + + return ddraw_surface7_GetDC(&This->IDirectDrawSurface7_iface, dc); +} + +static HRESULT WINAPI ddraw_surface2_GetDC(IDirectDrawSurface2 *iface, HDC *dc) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, dc %p.\n", iface, dc); + + return ddraw_surface7_GetDC(&This->IDirectDrawSurface7_iface, dc); +} + +static HRESULT WINAPI ddraw_surface1_GetDC(IDirectDrawSurface *iface, HDC *dc) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, dc %p.\n", iface, dc); + + return ddraw_surface7_GetDC(&This->IDirectDrawSurface7_iface, dc); } /***************************************************************************** @@ -1180,22 +1986,50 @@ static HRESULT WINAPI ddraw_surface3_GetDC(IDirectDrawSurface3 *iface, HDC *dc) *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_ReleaseDC(IDirectDrawSurface7 *iface, HDC hdc) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); HRESULT hr; TRACE("iface %p, dc %p.\n", iface, hdc); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_surface_releasedc(This->wined3d_surface, hdc); - LeaveCriticalSection(&ddraw_cs); + if (SUCCEEDED(hr) && (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)) + hr = ddraw_surface_update_frontbuffer(This, NULL, FALSE); + wined3d_mutex_unlock(); + return hr; } +static HRESULT WINAPI ddraw_surface4_ReleaseDC(IDirectDrawSurface4 *iface, HDC dc) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, dc %p.\n", iface, dc); + + return ddraw_surface7_ReleaseDC(&This->IDirectDrawSurface7_iface, dc); +} + static HRESULT WINAPI ddraw_surface3_ReleaseDC(IDirectDrawSurface3 *iface, HDC dc) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); TRACE("iface %p, dc %p.\n", iface, dc); - return ddraw_surface7_ReleaseDC((IDirectDrawSurface7 *)surface_from_surface3(iface), dc); + return ddraw_surface7_ReleaseDC(&This->IDirectDrawSurface7_iface, dc); +} + +static HRESULT WINAPI ddraw_surface2_ReleaseDC(IDirectDrawSurface2 *iface, HDC dc) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, dc %p.\n", iface, dc); + + return ddraw_surface7_ReleaseDC(&This->IDirectDrawSurface7_iface, dc); +} + +static HRESULT WINAPI ddraw_surface1_ReleaseDC(IDirectDrawSurface *iface, HDC dc) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, dc %p.\n", iface, dc); + + return ddraw_surface7_ReleaseDC(&This->IDirectDrawSurface7_iface, dc); } /***************************************************************************** @@ -1213,7 +2047,7 @@ static HRESULT WINAPI ddraw_surface3_ReleaseDC(IDirectDrawSurface3 *iface, HDC d *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_GetCaps(IDirectDrawSurface7 *iface, DDSCAPS2 *Caps) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); TRACE("iface %p, caps %p.\n", iface, Caps); @@ -1224,14 +2058,53 @@ static HRESULT WINAPI ddraw_surface7_GetCaps(IDirectDrawSurface7 *iface, DDSCAPS return DD_OK; } +static HRESULT WINAPI ddraw_surface4_GetCaps(IDirectDrawSurface4 *iface, DDSCAPS2 *caps) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, caps %p.\n", iface, caps); + + return ddraw_surface7_GetCaps(&This->IDirectDrawSurface7_iface, caps); +} + static HRESULT WINAPI ddraw_surface3_GetCaps(IDirectDrawSurface3 *iface, DDSCAPS *caps) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); DDSCAPS2 caps2; HRESULT hr; TRACE("iface %p, caps %p.\n", iface, caps); - hr = ddraw_surface7_GetCaps((IDirectDrawSurface7 *)surface_from_surface3(iface), &caps2); + hr = ddraw_surface7_GetCaps(&This->IDirectDrawSurface7_iface, &caps2); + if (FAILED(hr)) return hr; + + caps->dwCaps = caps2.dwCaps; + return hr; +} + +static HRESULT WINAPI ddraw_surface2_GetCaps(IDirectDrawSurface2 *iface, DDSCAPS *caps) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + DDSCAPS2 caps2; + HRESULT hr; + + TRACE("iface %p, caps %p.\n", iface, caps); + + hr = ddraw_surface7_GetCaps(&This->IDirectDrawSurface7_iface, &caps2); + if (FAILED(hr)) return hr; + + caps->dwCaps = caps2.dwCaps; + return hr; +} + +static HRESULT WINAPI ddraw_surface1_GetCaps(IDirectDrawSurface *iface, DDSCAPS *caps) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + DDSCAPS2 caps2; + HRESULT hr; + + TRACE("iface %p, caps %p.\n", iface, caps); + + hr = ddraw_surface7_GetCaps(&This->IDirectDrawSurface7_iface, &caps2); if (FAILED(hr)) return hr; caps->dwCaps = caps2.dwCaps; @@ -1253,14 +2126,15 @@ static HRESULT WINAPI ddraw_surface3_GetCaps(IDirectDrawSurface3 *iface, DDSCAPS *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_SetPriority(IDirectDrawSurface7 *iface, DWORD Priority) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); HRESULT hr; TRACE("iface %p, priority %u.\n", iface, Priority); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_surface_set_priority(This->wined3d_surface, Priority); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -1280,7 +2154,7 @@ static HRESULT WINAPI ddraw_surface7_SetPriority(IDirectDrawSurface7 *iface, DWO *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_GetPriority(IDirectDrawSurface7 *iface, DWORD *Priority) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); TRACE("iface %p, priority %p.\n", iface, Priority); @@ -1289,9 +2163,10 @@ static HRESULT WINAPI ddraw_surface7_GetPriority(IDirectDrawSurface7 *iface, DWO return DDERR_INVALIDPARAMS; } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); *Priority = wined3d_surface_get_priority(This->wined3d_surface); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return DD_OK; } @@ -1315,15 +2190,18 @@ static HRESULT WINAPI ddraw_surface7_GetPriority(IDirectDrawSurface7 *iface, DWO static HRESULT WINAPI ddraw_surface7_SetPrivateData(IDirectDrawSurface7 *iface, REFGUID tag, void *Data, DWORD Size, DWORD Flags) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n", iface, debugstr_guid(tag), Data, Size, Flags); - EnterCriticalSection(&ddraw_cs); - hr = wined3d_surface_set_private_data(This->wined3d_surface, tag, Data, Size, Flags); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); + resource = wined3d_surface_get_resource(This->wined3d_surface); + hr = wined3d_resource_set_private_data(resource, tag, Data, Size, Flags); + wined3d_mutex_unlock(); + switch(hr) { case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS; @@ -1331,6 +2209,16 @@ static HRESULT WINAPI ddraw_surface7_SetPrivateData(IDirectDrawSurface7 *iface, } } +static HRESULT WINAPI ddraw_surface4_SetPrivateData(IDirectDrawSurface4 *iface, + REFGUID tag, void *data, DWORD size, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n", + iface, debugstr_guid(tag), data, size, flags); + + return ddraw_surface7_SetPrivateData(&This->IDirectDrawSurface7_iface, tag, data, size, flags); +} + /***************************************************************************** * IDirectDrawSurface7::GetPrivateData * @@ -1349,7 +2237,8 @@ static HRESULT WINAPI ddraw_surface7_SetPrivateData(IDirectDrawSurface7 *iface, *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_GetPrivateData(IDirectDrawSurface7 *iface, REFGUID tag, void *Data, DWORD *Size) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, tag %s, data %p, data_size %p.\n", @@ -1358,12 +2247,23 @@ static HRESULT WINAPI ddraw_surface7_GetPrivateData(IDirectDrawSurface7 *iface, if(!Data) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); - hr = wined3d_surface_get_private_data(This->wined3d_surface, tag, Data, Size); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); + resource = wined3d_surface_get_resource(This->wined3d_surface); + hr = wined3d_resource_get_private_data(resource, tag, Data, Size); + wined3d_mutex_unlock(); + return hr; } +static HRESULT WINAPI ddraw_surface4_GetPrivateData(IDirectDrawSurface4 *iface, REFGUID tag, void *data, DWORD *size) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, tag %s, data %p, data_size %p.\n", + iface, debugstr_guid(tag), data, size); + + return ddraw_surface7_GetPrivateData(&This->IDirectDrawSurface7_iface, tag, data, size); +} + /***************************************************************************** * IDirectDrawSurface7::FreePrivateData * @@ -1379,17 +2279,28 @@ static HRESULT WINAPI ddraw_surface7_GetPrivateData(IDirectDrawSurface7 *iface, *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_FreePrivateData(IDirectDrawSurface7 *iface, REFGUID tag) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); + struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, tag %s.\n", iface, debugstr_guid(tag)); - EnterCriticalSection(&ddraw_cs); - hr = wined3d_surface_free_private_data(This->wined3d_surface, tag); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); + resource = wined3d_surface_get_resource(This->wined3d_surface); + hr = wined3d_resource_free_private_data(resource, tag); + wined3d_mutex_unlock(); + return hr; } +static HRESULT WINAPI ddraw_surface4_FreePrivateData(IDirectDrawSurface4 *iface, REFGUID tag) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, tag %s.\n", iface, debugstr_guid(tag)); + + return ddraw_surface7_FreePrivateData(&This->IDirectDrawSurface7_iface, tag); +} + /***************************************************************************** * IDirectDrawSurface7::PageLock * @@ -1410,11 +2321,28 @@ static HRESULT WINAPI ddraw_surface7_PageLock(IDirectDrawSurface7 *iface, DWORD return DD_OK; } -static HRESULT WINAPI ddraw_surface3_PageLock(IDirectDrawSurface3 *iface, DWORD flags) +static HRESULT WINAPI ddraw_surface4_PageLock(IDirectDrawSurface4 *iface, DWORD flags) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); TRACE("iface %p, flags %#x.\n", iface, flags); - return ddraw_surface7_PageLock((IDirectDrawSurface7 *)surface_from_surface3(iface), flags); + return ddraw_surface7_PageLock(&This->IDirectDrawSurface7_iface, flags); +} + +static HRESULT WINAPI ddraw_surface3_PageLock(IDirectDrawSurface3 *iface, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + TRACE("iface %p, flags %#x.\n", iface, flags); + + return ddraw_surface7_PageLock(&This->IDirectDrawSurface7_iface, flags); +} + +static HRESULT WINAPI ddraw_surface2_PageLock(IDirectDrawSurface2 *iface, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, flags %#x.\n", iface, flags); + + return ddraw_surface7_PageLock(&This->IDirectDrawSurface7_iface, flags); } /***************************************************************************** @@ -1436,11 +2364,28 @@ static HRESULT WINAPI ddraw_surface7_PageUnlock(IDirectDrawSurface7 *iface, DWOR return DD_OK; } -static HRESULT WINAPI ddraw_surface3_PageUnlock(IDirectDrawSurface3 *iface, DWORD flags) +static HRESULT WINAPI ddraw_surface4_PageUnlock(IDirectDrawSurface4 *iface, DWORD flags) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); TRACE("iface %p, flags %#x.\n", iface, flags); - return ddraw_surface7_PageUnlock((IDirectDrawSurface7 *)surface_from_surface3(iface), flags); + return ddraw_surface7_PageUnlock(&This->IDirectDrawSurface7_iface, flags); +} + +static HRESULT WINAPI ddraw_surface3_PageUnlock(IDirectDrawSurface3 *iface, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + TRACE("iface %p, flags %#x.\n", iface, flags); + + return ddraw_surface7_PageUnlock(&This->IDirectDrawSurface7_iface, flags); +} + +static HRESULT WINAPI ddraw_surface2_PageUnlock(IDirectDrawSurface2 *iface, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, flags %#x.\n", iface, flags); + + return ddraw_surface7_PageUnlock(&This->IDirectDrawSurface7_iface, flags); } /***************************************************************************** @@ -1463,11 +2408,36 @@ static HRESULT WINAPI ddraw_surface7_BltBatch(IDirectDrawSurface7 *iface, DDBLTB return DDERR_UNSUPPORTED; } -static HRESULT WINAPI ddraw_surface3_BltBatch(IDirectDrawSurface3 *iface, DDBLTBATCH *batch, DWORD count, DWORD flags) +static HRESULT WINAPI ddraw_surface4_BltBatch(IDirectDrawSurface4 *iface, DDBLTBATCH *batch, DWORD count, DWORD flags) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface, batch, count, flags); - return ddraw_surface7_BltBatch((IDirectDrawSurface7 *)surface_from_surface3(iface), batch, count, flags); + return ddraw_surface7_BltBatch(&This->IDirectDrawSurface7_iface, batch, count, flags); +} + +static HRESULT WINAPI ddraw_surface3_BltBatch(IDirectDrawSurface3 *iface, DDBLTBATCH *batch, DWORD count, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface, batch, count, flags); + + return ddraw_surface7_BltBatch(&This->IDirectDrawSurface7_iface, batch, count, flags); +} + +static HRESULT WINAPI ddraw_surface2_BltBatch(IDirectDrawSurface2 *iface, DDBLTBATCH *batch, DWORD count, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface, batch, count, flags); + + return ddraw_surface7_BltBatch(&This->IDirectDrawSurface7_iface, batch, count, flags); +} + +static HRESULT WINAPI ddraw_surface1_BltBatch(IDirectDrawSurface *iface, DDBLTBATCH *batch, DWORD count, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface, batch, count, flags); + + return ddraw_surface7_BltBatch(&This->IDirectDrawSurface7_iface, batch, count, flags); } /***************************************************************************** @@ -1487,7 +2457,7 @@ static HRESULT WINAPI ddraw_surface3_BltBatch(IDirectDrawSurface3 *iface, DDBLTB static HRESULT WINAPI ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7 *iface, void *context, LPDDENUMSURFACESCALLBACK7 cb) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); IDirectDrawSurfaceImpl *surf; DDSURFACEDESC2 desc; int i; @@ -1498,57 +2468,97 @@ static HRESULT WINAPI ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7 *i if(!cb) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); + for(i = 0; i < MAX_COMPLEX_ATTACHED; i++) { surf = This->complex_array[i]; if(!surf) break; - ddraw_surface7_AddRef((IDirectDrawSurface7 *)surf); + ddraw_surface7_AddRef(&surf->IDirectDrawSurface7_iface); desc = surf->surface_desc; /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */ - if (cb((IDirectDrawSurface7 *)surf, &desc, context) == DDENUMRET_CANCEL) + if (cb(&surf->IDirectDrawSurface7_iface, &desc, context) == DDENUMRET_CANCEL) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DD_OK; } } for (surf = This->next_attached; surf != NULL; surf = surf->next_attached) { - ddraw_surface7_AddRef((IDirectDrawSurface7 *)surf); + ddraw_surface7_AddRef(&surf->IDirectDrawSurface7_iface); desc = surf->surface_desc; /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */ - if (cb((IDirectDrawSurface7 *)surf, &desc, context) == DDENUMRET_CANCEL) + if (cb(&surf->IDirectDrawSurface7_iface, &desc, context) == DDENUMRET_CANCEL) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DD_OK; } } TRACE(" end of enumeration.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return DD_OK; } +struct callback_info2 +{ + LPDDENUMSURFACESCALLBACK2 callback; + void *context; +}; + struct callback_info { LPDDENUMSURFACESCALLBACK callback; void *context; }; +static HRESULT CALLBACK EnumCallback2(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *surface_desc, void *context) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(surface); + const struct callback_info2 *info = context; + + ddraw_surface4_AddRef(&This->IDirectDrawSurface4_iface); + ddraw_surface7_Release(surface); + + return info->callback(&This->IDirectDrawSurface4_iface, surface_desc, info->context); +} + static HRESULT CALLBACK EnumCallback(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *surface_desc, void *context) { + IDirectDrawSurfaceImpl *surface_impl = impl_from_IDirectDrawSurface7(surface); const struct callback_info *info = context; - return info->callback((IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)surface)->IDirectDrawSurface3_vtbl, + ddraw_surface1_AddRef(&surface_impl->IDirectDrawSurface_iface); + ddraw_surface7_Release(surface); + + /* FIXME: Check surface_test.dwSize */ + return info->callback(&surface_impl->IDirectDrawSurface_iface, (DDSURFACEDESC *)surface_desc, info->context); } +static HRESULT WINAPI ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4 *iface, + void *context, LPDDENUMSURFACESCALLBACK2 callback) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + struct callback_info2 info; + + TRACE("iface %p, context %p, callback %p.\n", iface, context, callback); + + info.callback = callback; + info.context = context; + + return ddraw_surface7_EnumAttachedSurfaces(&This->IDirectDrawSurface7_iface, + &info, EnumCallback2); +} + static HRESULT WINAPI ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3 *iface, void *context, LPDDENUMSURFACESCALLBACK callback) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); struct callback_info info; TRACE("iface %p, context %p, callback %p.\n", iface, context, callback); @@ -1556,7 +2566,37 @@ static HRESULT WINAPI ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3 *i info.callback = callback; info.context = context; - return ddraw_surface7_EnumAttachedSurfaces((IDirectDrawSurface7 *)surface_from_surface3(iface), + return ddraw_surface7_EnumAttachedSurfaces(&This->IDirectDrawSurface7_iface, + &info, EnumCallback); +} + +static HRESULT WINAPI ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2 *iface, + void *context, LPDDENUMSURFACESCALLBACK callback) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + struct callback_info info; + + TRACE("iface %p, context %p, callback %p.\n", iface, context, callback); + + info.callback = callback; + info.context = context; + + return ddraw_surface7_EnumAttachedSurfaces(&This->IDirectDrawSurface7_iface, + &info, EnumCallback); +} + +static HRESULT WINAPI ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface *iface, + void *context, LPDDENUMSURFACESCALLBACK callback) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + struct callback_info info; + + TRACE("iface %p, context %p, callback %p.\n", iface, context, callback); + + info.callback = callback; + info.context = context; + + return ddraw_surface7_EnumAttachedSurfaces(&This->IDirectDrawSurface7_iface, &info, EnumCallback); } @@ -1582,9 +2622,25 @@ static HRESULT WINAPI ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7 *ifa return DD_OK; } +static HRESULT WINAPI ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4 *iface, + DWORD flags, void *context, LPDDENUMSURFACESCALLBACK2 callback) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + struct callback_info2 info; + + TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface, flags, context, callback); + + info.callback = callback; + info.context = context; + + return ddraw_surface7_EnumOverlayZOrders(&This->IDirectDrawSurface7_iface, + flags, &info, EnumCallback2); +} + static HRESULT WINAPI ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3 *iface, DWORD flags, void *context, LPDDENUMSURFACESCALLBACK callback) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); struct callback_info info; TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface, flags, context, callback); @@ -1592,7 +2648,37 @@ static HRESULT WINAPI ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3 *ifa info.callback = callback; info.context = context; - return ddraw_surface7_EnumOverlayZOrders((IDirectDrawSurface7 *)surface_from_surface3(iface), + return ddraw_surface7_EnumOverlayZOrders(&This->IDirectDrawSurface7_iface, + flags, &info, EnumCallback); +} + +static HRESULT WINAPI ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2 *iface, + DWORD flags, void *context, LPDDENUMSURFACESCALLBACK callback) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + struct callback_info info; + + TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface, flags, context, callback); + + info.callback = callback; + info.context = context; + + return ddraw_surface7_EnumOverlayZOrders(&This->IDirectDrawSurface7_iface, + flags, &info, EnumCallback); +} + +static HRESULT WINAPI ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface *iface, + DWORD flags, void *context, LPDDENUMSURFACESCALLBACK callback) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + struct callback_info info; + + TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface, flags, context, callback); + + info.callback = callback; + info.context = context; + + return ddraw_surface7_EnumOverlayZOrders(&This->IDirectDrawSurface7_iface, flags, &info, EnumCallback); } @@ -1610,14 +2696,14 @@ static HRESULT WINAPI ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3 *ifa *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_GetBltStatus(IDirectDrawSurface7 *iface, DWORD Flags) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); HRESULT hr; TRACE("iface %p, flags %#x.\n", iface, Flags); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_surface_get_blt_status(This->wined3d_surface, Flags); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); switch(hr) { case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS; @@ -1625,11 +2711,36 @@ static HRESULT WINAPI ddraw_surface7_GetBltStatus(IDirectDrawSurface7 *iface, DW } } -static HRESULT WINAPI ddraw_surface3_GetBltStatus(IDirectDrawSurface3 *iface, DWORD flags) +static HRESULT WINAPI ddraw_surface4_GetBltStatus(IDirectDrawSurface4 *iface, DWORD flags) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); TRACE("iface %p, flags %#x.\n", iface, flags); - return ddraw_surface7_GetBltStatus((IDirectDrawSurface7 *)surface_from_surface3(iface), flags); + return ddraw_surface7_GetBltStatus(&This->IDirectDrawSurface7_iface, flags); +} + +static HRESULT WINAPI ddraw_surface3_GetBltStatus(IDirectDrawSurface3 *iface, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + TRACE("iface %p, flags %#x.\n", iface, flags); + + return ddraw_surface7_GetBltStatus(&This->IDirectDrawSurface7_iface, flags); +} + +static HRESULT WINAPI ddraw_surface2_GetBltStatus(IDirectDrawSurface2 *iface, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, flags %#x.\n", iface, flags); + + return ddraw_surface7_GetBltStatus(&This->IDirectDrawSurface7_iface, flags); +} + +static HRESULT WINAPI ddraw_surface1_GetBltStatus(IDirectDrawSurface *iface, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, flags %#x.\n", iface, flags); + + return ddraw_surface7_GetBltStatus(&This->IDirectDrawSurface7_iface, flags); } /***************************************************************************** @@ -1648,21 +2759,21 @@ static HRESULT WINAPI ddraw_surface3_GetBltStatus(IDirectDrawSurface3 *iface, DW *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_GetColorKey(IDirectDrawSurface7 *iface, DWORD Flags, DDCOLORKEY *CKey) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); TRACE("iface %p, flags %#x, color_key %p.\n", iface, Flags, CKey); if(!CKey) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); switch (Flags) { case DDCKEY_DESTBLT: if (!(This->surface_desc.dwFlags & DDSD_CKDESTBLT)) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_NOCOLORKEY; } *CKey = This->surface_desc.ddckCKDestBlt; @@ -1670,17 +2781,17 @@ static HRESULT WINAPI ddraw_surface7_GetColorKey(IDirectDrawSurface7 *iface, DWO case DDCKEY_DESTOVERLAY: if (!(This->surface_desc.dwFlags & DDSD_CKDESTOVERLAY)) - { - LeaveCriticalSection(&ddraw_cs); + { + wined3d_mutex_unlock(); return DDERR_NOCOLORKEY; - } + } *CKey = This->surface_desc.u3.ddckCKDestOverlay; break; case DDCKEY_SRCBLT: if (!(This->surface_desc.dwFlags & DDSD_CKSRCBLT)) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_NOCOLORKEY; } *CKey = This->surface_desc.ddckCKSrcBlt; @@ -1689,26 +2800,52 @@ static HRESULT WINAPI ddraw_surface7_GetColorKey(IDirectDrawSurface7 *iface, DWO case DDCKEY_SRCOVERLAY: if (!(This->surface_desc.dwFlags & DDSD_CKSRCOVERLAY)) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_NOCOLORKEY; } *CKey = This->surface_desc.ddckCKSrcOverlay; break; default: - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return DD_OK; } +static HRESULT WINAPI ddraw_surface4_GetColorKey(IDirectDrawSurface4 *iface, DWORD flags, DDCOLORKEY *color_key) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key); + + return ddraw_surface7_GetColorKey(&This->IDirectDrawSurface7_iface, flags, color_key); +} + static HRESULT WINAPI ddraw_surface3_GetColorKey(IDirectDrawSurface3 *iface, DWORD flags, DDCOLORKEY *color_key) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key); - return ddraw_surface7_GetColorKey((IDirectDrawSurface7 *)surface_from_surface3(iface), flags, color_key); + return ddraw_surface7_GetColorKey(&This->IDirectDrawSurface7_iface, flags, color_key); +} + +static HRESULT WINAPI ddraw_surface2_GetColorKey(IDirectDrawSurface2 *iface, DWORD flags, DDCOLORKEY *color_key) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key); + + return ddraw_surface7_GetColorKey(&This->IDirectDrawSurface7_iface, flags, color_key); +} + +static HRESULT WINAPI ddraw_surface1_GetColorKey(IDirectDrawSurface *iface, DWORD flags, DDCOLORKEY *color_key) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key); + + return ddraw_surface7_GetColorKey(&This->IDirectDrawSurface7_iface, flags, color_key); } /***************************************************************************** @@ -1725,14 +2862,15 @@ static HRESULT WINAPI ddraw_surface3_GetColorKey(IDirectDrawSurface3 *iface, DWO *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_GetFlipStatus(IDirectDrawSurface7 *iface, DWORD Flags) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); HRESULT hr; TRACE("iface %p, flags %#x.\n", iface, Flags); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_surface_get_flip_status(This->wined3d_surface, Flags); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + switch(hr) { case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS; @@ -1740,11 +2878,36 @@ static HRESULT WINAPI ddraw_surface7_GetFlipStatus(IDirectDrawSurface7 *iface, D } } -static HRESULT WINAPI ddraw_surface3_GetFlipStatus(IDirectDrawSurface3 *iface, DWORD flags) +static HRESULT WINAPI ddraw_surface4_GetFlipStatus(IDirectDrawSurface4 *iface, DWORD flags) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); TRACE("iface %p, flags %#x.\n", iface, flags); - return ddraw_surface7_GetFlipStatus((IDirectDrawSurface7 *)surface_from_surface3(iface), flags); + return ddraw_surface7_GetFlipStatus(&This->IDirectDrawSurface7_iface, flags); +} + +static HRESULT WINAPI ddraw_surface3_GetFlipStatus(IDirectDrawSurface3 *iface, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + TRACE("iface %p, flags %#x.\n", iface, flags); + + return ddraw_surface7_GetFlipStatus(&This->IDirectDrawSurface7_iface, flags); +} + +static HRESULT WINAPI ddraw_surface2_GetFlipStatus(IDirectDrawSurface2 *iface, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, flags %#x.\n", iface, flags); + + return ddraw_surface7_GetFlipStatus(&This->IDirectDrawSurface7_iface, flags); +} + +static HRESULT WINAPI ddraw_surface1_GetFlipStatus(IDirectDrawSurface *iface, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, flags %#x.\n", iface, flags); + + return ddraw_surface7_GetFlipStatus(&This->IDirectDrawSurface7_iface, flags); } /***************************************************************************** @@ -1761,22 +2924,48 @@ static HRESULT WINAPI ddraw_surface3_GetFlipStatus(IDirectDrawSurface3 *iface, D *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7 *iface, LONG *X, LONG *Y) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); HRESULT hr; TRACE("iface %p, x %p, y %p.\n", iface, X, Y); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_surface_get_overlay_position(This->wined3d_surface, X, Y); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } +static HRESULT WINAPI ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4 *iface, LONG *x, LONG *y) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, x %p, y %p.\n", iface, x, y); + + return ddraw_surface7_GetOverlayPosition(&This->IDirectDrawSurface7_iface, x, y); +} + static HRESULT WINAPI ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3 *iface, LONG *x, LONG *y) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); TRACE("iface %p, x %p, y %p.\n", iface, x, y); - return ddraw_surface7_GetOverlayPosition((IDirectDrawSurface7 *)surface_from_surface3(iface), x, y); + return ddraw_surface7_GetOverlayPosition(&This->IDirectDrawSurface7_iface, x, y); +} + +static HRESULT WINAPI ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2 *iface, LONG *x, LONG *y) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, x %p, y %p.\n", iface, x, y); + + return ddraw_surface7_GetOverlayPosition(&This->IDirectDrawSurface7_iface, x, y); +} + +static HRESULT WINAPI ddraw_surface1_GetOverlayPosition(IDirectDrawSurface *iface, LONG *x, LONG *y) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, x %p, y %p.\n", iface, x, y); + + return ddraw_surface7_GetOverlayPosition(&This->IDirectDrawSurface7_iface, x, y); } /***************************************************************************** @@ -1796,25 +2985,50 @@ static HRESULT WINAPI ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3 *ifa static HRESULT WINAPI ddraw_surface7_GetPixelFormat(IDirectDrawSurface7 *iface, DDPIXELFORMAT *PixelFormat) { /* What is DDERR_INVALIDSURFACETYPE for here? */ - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); TRACE("iface %p, pixel_format %p.\n", iface, PixelFormat); if(!PixelFormat) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); DD_STRUCT_COPY_BYSIZE(PixelFormat,&This->surface_desc.u4.ddpfPixelFormat); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DD_OK; } -static HRESULT WINAPI ddraw_surface3_GetPixelFormat(IDirectDrawSurface3 *iface, DDPIXELFORMAT *pixel_format) +static HRESULT WINAPI ddraw_surface4_GetPixelFormat(IDirectDrawSurface4 *iface, DDPIXELFORMAT *pixel_format) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); TRACE("iface %p, pixel_format %p.\n", iface, pixel_format); - return ddraw_surface7_GetPixelFormat((IDirectDrawSurface7 *)surface_from_surface3(iface), pixel_format); + return ddraw_surface7_GetPixelFormat(&This->IDirectDrawSurface7_iface, pixel_format); +} + +static HRESULT WINAPI ddraw_surface3_GetPixelFormat(IDirectDrawSurface3 *iface, DDPIXELFORMAT *pixel_format) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + TRACE("iface %p, pixel_format %p.\n", iface, pixel_format); + + return ddraw_surface7_GetPixelFormat(&This->IDirectDrawSurface7_iface, pixel_format); +} + +static HRESULT WINAPI ddraw_surface2_GetPixelFormat(IDirectDrawSurface2 *iface, DDPIXELFORMAT *pixel_format) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, pixel_format %p.\n", iface, pixel_format); + + return ddraw_surface7_GetPixelFormat(&This->IDirectDrawSurface7_iface, pixel_format); +} + +static HRESULT WINAPI ddraw_surface1_GetPixelFormat(IDirectDrawSurface *iface, DDPIXELFORMAT *pixel_format) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, pixel_format %p.\n", iface, pixel_format); + + return ddraw_surface7_GetPixelFormat(&This->IDirectDrawSurface7_iface, pixel_format); } /***************************************************************************** @@ -1833,7 +3047,7 @@ static HRESULT WINAPI ddraw_surface3_GetPixelFormat(IDirectDrawSurface3 *iface, *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7 *iface, DDSURFACEDESC2 *DDSD) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); TRACE("iface %p, surface_desc %p.\n", iface, DDSD); @@ -1846,18 +3060,26 @@ static HRESULT WINAPI ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7 *iface, return DDERR_INVALIDPARAMS; } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); DD_STRUCT_COPY_BYSIZE(DDSD,&This->surface_desc); TRACE("Returning surface desc:\n"); if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD); + wined3d_mutex_unlock(); - LeaveCriticalSection(&ddraw_cs); return DD_OK; } +static HRESULT WINAPI ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4 *iface, DDSURFACEDESC2 *DDSD) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, surface_desc %p.\n", iface, DDSD); + + return ddraw_surface7_GetSurfaceDesc(&This->IDirectDrawSurface7_iface, DDSD); +} + static HRESULT WINAPI ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3 *iface, DDSURFACEDESC *surface_desc) { - IDirectDrawSurfaceImpl *surface = surface_from_surface3(iface); + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); TRACE("iface %p, surface_desc %p.\n", iface, surface_desc); @@ -1869,19 +3091,35 @@ static HRESULT WINAPI ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3 *iface, return DDERR_INVALIDPARAMS; } - EnterCriticalSection(&ddraw_cs); - DD_STRUCT_COPY_BYSIZE(surface_desc, (DDSURFACEDESC *)&surface->surface_desc); + wined3d_mutex_lock(); + DDSD2_to_DDSD(&This->surface_desc, surface_desc); TRACE("Returning surface desc:\n"); if (TRACE_ON(ddraw)) { /* DDRAW_dump_surface_desc handles the smaller size */ DDRAW_dump_surface_desc((DDSURFACEDESC2 *)surface_desc); } + wined3d_mutex_unlock(); - LeaveCriticalSection(&ddraw_cs); return DD_OK; } +static HRESULT WINAPI ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2 *iface, DDSURFACEDESC *DDSD) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, surface_desc %p.\n", iface, DDSD); + + return ddraw_surface3_GetSurfaceDesc(&This->IDirectDrawSurface3_iface, DDSD); +} + +static HRESULT WINAPI ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface *iface, DDSURFACEDESC *DDSD) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, surface_desc %p.\n", iface, DDSD); + + return ddraw_surface3_GetSurfaceDesc(&This->IDirectDrawSurface3_iface, DDSD); +} + /***************************************************************************** * IDirectDrawSurface7::Initialize * @@ -1903,13 +3141,50 @@ static HRESULT WINAPI ddraw_surface7_Initialize(IDirectDrawSurface7 *iface, return DDERR_ALREADYINITIALIZED; } +static HRESULT WINAPI ddraw_surface4_Initialize(IDirectDrawSurface4 *iface, + IDirectDraw *ddraw, DDSURFACEDESC2 *surface_desc) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc); + + return ddraw_surface7_Initialize(&This->IDirectDrawSurface7_iface, + ddraw, surface_desc); +} + static HRESULT WINAPI ddraw_surface3_Initialize(IDirectDrawSurface3 *iface, IDirectDraw *ddraw, DDSURFACEDESC *surface_desc) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + DDSURFACEDESC2 surface_desc2; TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc); - return ddraw_surface7_Initialize((IDirectDrawSurface7 *)surface_from_surface3(iface), - ddraw, (DDSURFACEDESC2 *)surface_desc); + if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2); + return ddraw_surface7_Initialize(&This->IDirectDrawSurface7_iface, + ddraw, surface_desc ? &surface_desc2 : NULL); +} + +static HRESULT WINAPI ddraw_surface2_Initialize(IDirectDrawSurface2 *iface, + IDirectDraw *ddraw, DDSURFACEDESC *surface_desc) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + DDSURFACEDESC2 surface_desc2; + TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc); + + if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2); + return ddraw_surface7_Initialize(&This->IDirectDrawSurface7_iface, + ddraw, surface_desc ? &surface_desc2 : NULL); +} + +static HRESULT WINAPI ddraw_surface1_Initialize(IDirectDrawSurface *iface, + IDirectDraw *ddraw, DDSURFACEDESC *surface_desc) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + DDSURFACEDESC2 surface_desc2; + TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc); + + if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2); + return ddraw_surface7_Initialize(&This->IDirectDrawSurface7_iface, + ddraw, surface_desc ? &surface_desc2 : NULL); } /***************************************************************************** @@ -1945,26 +3220,15 @@ static HRESULT WINAPI d3d_texture1_Initialize(IDirect3DTexture *iface, *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_IsLost(IDirectDrawSurface7 *iface) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); HRESULT hr; TRACE("iface %p.\n", iface); - EnterCriticalSection(&ddraw_cs); - /* We lose the surface if the implementation was changed */ - if(This->ImplType != This->ddraw->ImplType) - { - /* But this shouldn't happen. When we change the implementation, - * all surfaces are re-created automatically, and their content - * is copied - */ - ERR(" (%p) Implementation was changed from %d to %d\n", This, This->ImplType, This->ddraw->ImplType); - LeaveCriticalSection(&ddraw_cs); - return DDERR_SURFACELOST; - } - + wined3d_mutex_lock(); hr = wined3d_surface_is_lost(This->wined3d_surface); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + switch(hr) { /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error. @@ -1975,11 +3239,36 @@ static HRESULT WINAPI ddraw_surface7_IsLost(IDirectDrawSurface7 *iface) } } -static HRESULT WINAPI ddraw_surface3_IsLost(IDirectDrawSurface3 *iface) +static HRESULT WINAPI ddraw_surface4_IsLost(IDirectDrawSurface4 *iface) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); TRACE("iface %p.\n", iface); - return ddraw_surface7_IsLost((IDirectDrawSurface7 *)surface_from_surface3(iface)); + return ddraw_surface7_IsLost(&This->IDirectDrawSurface7_iface); +} + +static HRESULT WINAPI ddraw_surface3_IsLost(IDirectDrawSurface3 *iface) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + TRACE("iface %p.\n", iface); + + return ddraw_surface7_IsLost(&This->IDirectDrawSurface7_iface); +} + +static HRESULT WINAPI ddraw_surface2_IsLost(IDirectDrawSurface2 *iface) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p.\n", iface); + + return ddraw_surface7_IsLost(&This->IDirectDrawSurface7_iface); +} + +static HRESULT WINAPI ddraw_surface1_IsLost(IDirectDrawSurface *iface) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p.\n", iface); + + return ddraw_surface7_IsLost(&This->IDirectDrawSurface7_iface); } /***************************************************************************** @@ -1995,28 +3284,48 @@ static HRESULT WINAPI ddraw_surface3_IsLost(IDirectDrawSurface3 *iface) *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_Restore(IDirectDrawSurface7 *iface) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); HRESULT hr; TRACE("iface %p.\n", iface); - EnterCriticalSection(&ddraw_cs); - if(This->ImplType != This->ddraw->ImplType) - { - /* Call the recreation callback. Make sure to AddRef first */ - IDirectDrawSurface_AddRef(iface); - ddraw_recreate_surfaces_cb(iface, &This->surface_desc, NULL /* Not needed */); - } + wined3d_mutex_lock(); hr = wined3d_surface_restore(This->wined3d_surface); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } +static HRESULT WINAPI ddraw_surface4_Restore(IDirectDrawSurface4 *iface) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p.\n", iface); + + return ddraw_surface7_Restore(&This->IDirectDrawSurface7_iface); +} + static HRESULT WINAPI ddraw_surface3_Restore(IDirectDrawSurface3 *iface) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); TRACE("iface %p.\n", iface); - return ddraw_surface7_Restore((IDirectDrawSurface7 *)surface_from_surface3(iface)); + return ddraw_surface7_Restore(&This->IDirectDrawSurface7_iface); +} + +static HRESULT WINAPI ddraw_surface2_Restore(IDirectDrawSurface2 *iface) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p.\n", iface); + + return ddraw_surface7_Restore(&This->IDirectDrawSurface7_iface); +} + +static HRESULT WINAPI ddraw_surface1_Restore(IDirectDrawSurface *iface) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p.\n", iface); + + return ddraw_surface7_Restore(&This->IDirectDrawSurface7_iface); } /***************************************************************************** @@ -2033,22 +3342,48 @@ static HRESULT WINAPI ddraw_surface3_Restore(IDirectDrawSurface3 *iface) *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7 *iface, LONG X, LONG Y) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); HRESULT hr; TRACE("iface %p, x %d, y %d.\n", iface, X, Y); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_surface_set_overlay_position(This->wined3d_surface, X, Y); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } +static HRESULT WINAPI ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4 *iface, LONG x, LONG y) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, x %d, y %d.\n", iface, x, y); + + return ddraw_surface7_SetOverlayPosition(&This->IDirectDrawSurface7_iface, x, y); +} + static HRESULT WINAPI ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3 *iface, LONG x, LONG y) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); TRACE("iface %p, x %d, y %d.\n", iface, x, y); - return ddraw_surface7_SetOverlayPosition((IDirectDrawSurface7 *)surface_from_surface3(iface), x, y); + return ddraw_surface7_SetOverlayPosition(&This->IDirectDrawSurface7_iface, x, y); +} + +static HRESULT WINAPI ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2 *iface, LONG x, LONG y) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, x %d, y %d.\n", iface, x, y); + + return ddraw_surface7_SetOverlayPosition(&This->IDirectDrawSurface7_iface, x, y); +} + +static HRESULT WINAPI ddraw_surface1_SetOverlayPosition(IDirectDrawSurface *iface, LONG x, LONG y) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, x %d, y %d.\n", iface, x, y); + + return ddraw_surface7_SetOverlayPosition(&This->IDirectDrawSurface7_iface, x, y); } /***************************************************************************** @@ -2069,17 +3404,18 @@ static HRESULT WINAPI ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3 *ifa static HRESULT WINAPI ddraw_surface7_UpdateOverlay(IDirectDrawSurface7 *iface, RECT *SrcRect, IDirectDrawSurface7 *DstSurface, RECT *DstRect, DWORD Flags, DDOVERLAYFX *FX) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; - IDirectDrawSurfaceImpl *Dst = (IDirectDrawSurfaceImpl *)DstSurface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); + IDirectDrawSurfaceImpl *Dst = unsafe_impl_from_IDirectDrawSurface7(DstSurface); HRESULT hr; TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n", iface, wine_dbgstr_rect(SrcRect), DstSurface, wine_dbgstr_rect(DstRect), Flags, FX); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_surface_update_overlay(This->wined3d_surface, SrcRect, Dst ? Dst->wined3d_surface : NULL, DstRect, Flags, (WINEDDOVERLAYFX *)FX); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + switch(hr) { case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS; case WINEDDERR_NOTAOVERLAYSURFACE: return DDERR_NOTAOVERLAYSURFACE; @@ -2089,14 +3425,52 @@ static HRESULT WINAPI ddraw_surface7_UpdateOverlay(IDirectDrawSurface7 *iface, R } } -static HRESULT WINAPI ddraw_surface3_UpdateOverlay(IDirectDrawSurface3 *iface, RECT *src_rect, - IDirectDrawSurface3 *dst_surface, RECT *dst_rect, DWORD flags, DDOVERLAYFX *fx) +static HRESULT WINAPI ddraw_surface4_UpdateOverlay(IDirectDrawSurface4 *iface, RECT *src_rect, + IDirectDrawSurface4 *dst_surface, RECT *dst_rect, DWORD flags, DDOVERLAYFX *fx) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + IDirectDrawSurfaceImpl *dst_impl = unsafe_impl_from_IDirectDrawSurface4(dst_surface); TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n", iface, wine_dbgstr_rect(src_rect), dst_surface, wine_dbgstr_rect(dst_rect), flags, fx); - return ddraw_surface7_UpdateOverlay((IDirectDrawSurface7 *)surface_from_surface3(iface), src_rect, - dst_surface ? (IDirectDrawSurface7 *)surface_from_surface3(dst_surface) : NULL, dst_rect, flags, fx); + return ddraw_surface7_UpdateOverlay(&This->IDirectDrawSurface7_iface, src_rect, + dst_impl ? &dst_impl->IDirectDrawSurface7_iface : NULL, dst_rect, flags, fx); +} + +static HRESULT WINAPI ddraw_surface3_UpdateOverlay(IDirectDrawSurface3 *iface, RECT *src_rect, + IDirectDrawSurface3 *dst_surface, RECT *dst_rect, DWORD flags, DDOVERLAYFX *fx) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + IDirectDrawSurfaceImpl *dst_impl = unsafe_impl_from_IDirectDrawSurface3(dst_surface); + TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n", + iface, wine_dbgstr_rect(src_rect), dst_surface, wine_dbgstr_rect(dst_rect), flags, fx); + + return ddraw_surface7_UpdateOverlay(&This->IDirectDrawSurface7_iface, src_rect, + dst_impl ? &dst_impl->IDirectDrawSurface7_iface : NULL, dst_rect, flags, fx); +} + +static HRESULT WINAPI ddraw_surface2_UpdateOverlay(IDirectDrawSurface2 *iface, RECT *src_rect, + IDirectDrawSurface2 *dst_surface, RECT *dst_rect, DWORD flags, DDOVERLAYFX *fx) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + IDirectDrawSurfaceImpl *dst_impl = unsafe_impl_from_IDirectDrawSurface2(dst_surface); + TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n", + iface, wine_dbgstr_rect(src_rect), dst_surface, wine_dbgstr_rect(dst_rect), flags, fx); + + return ddraw_surface7_UpdateOverlay(&This->IDirectDrawSurface7_iface, src_rect, + dst_impl ? &dst_impl->IDirectDrawSurface7_iface : NULL, dst_rect, flags, fx); +} + +static HRESULT WINAPI ddraw_surface1_UpdateOverlay(IDirectDrawSurface *iface, RECT *src_rect, + IDirectDrawSurface *dst_surface, RECT *dst_rect, DWORD flags, DDOVERLAYFX *fx) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + IDirectDrawSurfaceImpl *dst_impl = unsafe_impl_from_IDirectDrawSurface(dst_surface); + TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n", + iface, wine_dbgstr_rect(src_rect), dst_surface, wine_dbgstr_rect(dst_rect), flags, fx); + + return ddraw_surface7_UpdateOverlay(&This->IDirectDrawSurface7_iface, src_rect, + dst_impl ? &dst_impl->IDirectDrawSurface7_iface : NULL, dst_rect, flags, fx); } /***************************************************************************** @@ -2117,11 +3491,36 @@ static HRESULT WINAPI ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7 *i return DDERR_UNSUPPORTED; } -static HRESULT WINAPI ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3 *iface, DWORD flags) +static HRESULT WINAPI ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4 *iface, DWORD flags) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); TRACE("iface %p, flags %#x.\n", iface, flags); - return ddraw_surface7_UpdateOverlayDisplay((IDirectDrawSurface7 *)surface_from_surface3(iface), flags); + return ddraw_surface7_UpdateOverlayDisplay(&This->IDirectDrawSurface7_iface, flags); +} + +static HRESULT WINAPI ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3 *iface, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + TRACE("iface %p, flags %#x.\n", iface, flags); + + return ddraw_surface7_UpdateOverlayDisplay(&This->IDirectDrawSurface7_iface, flags); +} + +static HRESULT WINAPI ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2 *iface, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, flags %#x.\n", iface, flags); + + return ddraw_surface7_UpdateOverlayDisplay(&This->IDirectDrawSurface7_iface, flags); +} + +static HRESULT WINAPI ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface *iface, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, flags %#x.\n", iface, flags); + + return ddraw_surface7_UpdateOverlayDisplay(&This->IDirectDrawSurface7_iface, flags); } /***************************************************************************** @@ -2140,26 +3539,62 @@ static HRESULT WINAPI ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3 *i static HRESULT WINAPI ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7 *iface, DWORD Flags, IDirectDrawSurface7 *DDSRef) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; - IDirectDrawSurfaceImpl *Ref = (IDirectDrawSurfaceImpl *)DDSRef; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); + IDirectDrawSurfaceImpl *Ref = unsafe_impl_from_IDirectDrawSurface7(DDSRef); HRESULT hr; TRACE("iface %p, flags %#x, reference %p.\n", iface, Flags, DDSRef); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_surface_update_overlay_z_order(This->wined3d_surface, Flags, Ref ? Ref->wined3d_surface : NULL); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } +static HRESULT WINAPI ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4 *iface, + DWORD flags, IDirectDrawSurface4 *reference) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + IDirectDrawSurfaceImpl *reference_impl = unsafe_impl_from_IDirectDrawSurface4(reference); + TRACE("iface %p, flags %#x, reference %p.\n", iface, flags, reference); + + return ddraw_surface7_UpdateOverlayZOrder(&This->IDirectDrawSurface7_iface, flags, + reference_impl ? &reference_impl->IDirectDrawSurface7_iface : NULL); +} + static HRESULT WINAPI ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3 *iface, DWORD flags, IDirectDrawSurface3 *reference) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + IDirectDrawSurfaceImpl *reference_impl = unsafe_impl_from_IDirectDrawSurface3(reference); TRACE("iface %p, flags %#x, reference %p.\n", iface, flags, reference); - return ddraw_surface7_UpdateOverlayZOrder((IDirectDrawSurface7 *)surface_from_surface3(iface), flags, - reference ? (IDirectDrawSurface7 *)surface_from_surface3(reference) : NULL); + return ddraw_surface7_UpdateOverlayZOrder(&This->IDirectDrawSurface7_iface, flags, + reference_impl ? &reference_impl->IDirectDrawSurface7_iface : NULL); +} + +static HRESULT WINAPI ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2 *iface, + DWORD flags, IDirectDrawSurface2 *reference) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + IDirectDrawSurfaceImpl *reference_impl = unsafe_impl_from_IDirectDrawSurface2(reference); + TRACE("iface %p, flags %#x, reference %p.\n", iface, flags, reference); + + return ddraw_surface7_UpdateOverlayZOrder(&This->IDirectDrawSurface7_iface, flags, + reference_impl ? &reference_impl->IDirectDrawSurface7_iface : NULL); +} + +static HRESULT WINAPI ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface *iface, + DWORD flags, IDirectDrawSurface *reference) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + IDirectDrawSurfaceImpl *reference_impl = unsafe_impl_from_IDirectDrawSurface(reference); + TRACE("iface %p, flags %#x, reference %p.\n", iface, flags, reference); + + return ddraw_surface7_UpdateOverlayZOrder(&This->IDirectDrawSurface7_iface, flags, + reference_impl ? &reference_impl->IDirectDrawSurface7_iface : NULL); } /***************************************************************************** @@ -2178,7 +3613,7 @@ static HRESULT WINAPI ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3 *if *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_GetDDInterface(IDirectDrawSurface7 *iface, void **DD) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); TRACE("iface %p, ddraw %p.\n", iface, DD); @@ -2209,22 +3644,39 @@ static HRESULT WINAPI ddraw_surface7_GetDDInterface(IDirectDrawSurface7 *iface, return DD_OK; } -static HRESULT WINAPI ddraw_surface3_GetDDInterface(IDirectDrawSurface3 *iface, void **ddraw) +static HRESULT WINAPI ddraw_surface4_GetDDInterface(IDirectDrawSurface4 *iface, void **ddraw) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); TRACE("iface %p, ddraw %p.\n", iface, ddraw); - return ddraw_surface7_GetDDInterface((IDirectDrawSurface7 *)surface_from_surface3(iface), ddraw); + return ddraw_surface7_GetDDInterface(&This->IDirectDrawSurface7_iface, ddraw); +} + +static HRESULT WINAPI ddraw_surface3_GetDDInterface(IDirectDrawSurface3 *iface, void **ddraw) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + TRACE("iface %p, ddraw %p.\n", iface, ddraw); + + return ddraw_surface7_GetDDInterface(&This->IDirectDrawSurface7_iface, ddraw); +} + +static HRESULT WINAPI ddraw_surface2_GetDDInterface(IDirectDrawSurface2 *iface, void **ddraw) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, ddraw %p.\n", iface, ddraw); + + return ddraw_surface7_GetDDInterface(&This->IDirectDrawSurface7_iface, ddraw); } /* This seems also windows implementation specific - I don't think WineD3D needs this */ static HRESULT WINAPI ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7 *iface) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); volatile IDirectDrawSurfaceImpl* vThis = This; TRACE("iface %p.\n", iface); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); /* A uniqueness value of 0 is apparently special. * This needs to be checked. * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed @@ -2243,22 +3695,40 @@ static HRESULT WINAPI ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7 * break; } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return DD_OK; } +static HRESULT WINAPI ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4 *iface) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p.\n", iface); + + return ddraw_surface7_ChangeUniquenessValue(&This->IDirectDrawSurface7_iface); +} + static HRESULT WINAPI ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7 *iface, DWORD *pValue) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); TRACE("iface %p, value %p.\n", iface, pValue); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); *pValue = This->uniqueness_value; - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return DD_OK; } +static HRESULT WINAPI ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4 *iface, DWORD *pValue) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, value %p.\n", iface, pValue); + + return ddraw_surface7_GetUniquenessValue(&This->IDirectDrawSurface7_iface, pValue); +} + /***************************************************************************** * IDirectDrawSurface7::SetLOD * @@ -2274,27 +3744,28 @@ static HRESULT WINAPI ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7 *ifa *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_SetLOD(IDirectDrawSurface7 *iface, DWORD MaxLOD) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); HRESULT hr; TRACE("iface %p, lod %u.\n", iface, MaxLOD); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE)) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDOBJECT; } if (!This->wined3d_texture) { ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDOBJECT; } hr = wined3d_texture_set_lod(This->wined3d_texture, MaxLOD); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -2314,22 +3785,23 @@ static HRESULT WINAPI ddraw_surface7_SetLOD(IDirectDrawSurface7 *iface, DWORD Ma *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_GetLOD(IDirectDrawSurface7 *iface, DWORD *MaxLOD) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); TRACE("iface %p, lod %p.\n", iface, MaxLOD); if(!MaxLOD) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE)) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDOBJECT; } *MaxLOD = wined3d_texture_get_lod(This->wined3d_texture); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return DD_OK; } @@ -2353,10 +3825,12 @@ static HRESULT WINAPI ddraw_surface7_GetLOD(IDirectDrawSurface7 *iface, DWORD *M static HRESULT WINAPI ddraw_surface7_BltFast(IDirectDrawSurface7 *iface, DWORD dstx, DWORD dsty, IDirectDrawSurface7 *Source, RECT *rsrc, DWORD trans) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; - IDirectDrawSurfaceImpl *src = (IDirectDrawSurfaceImpl *)Source; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); + IDirectDrawSurfaceImpl *src = unsafe_impl_from_IDirectDrawSurface7(Source); DWORD src_w, src_h, dst_w, dst_h; - HRESULT hr; + HRESULT hr = DD_OK; + DWORD flags = 0; + RECT dst_rect; TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n", iface, dstx, dsty, Source, wine_dbgstr_rect(rsrc), trans); @@ -2369,14 +3843,6 @@ static HRESULT WINAPI ddraw_surface7_BltFast(IDirectDrawSurface7 *iface, DWORD d */ if(rsrc) { - if(rsrc->top > rsrc->bottom || rsrc->left > rsrc->right || - rsrc->right > src->surface_desc.dwWidth || - rsrc->bottom > src->surface_desc.dwHeight) - { - WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n"); - return DDERR_INVALIDRECT; - } - src_w = rsrc->right - rsrc->left; src_h = rsrc->bottom - rsrc->top; } @@ -2393,10 +3859,33 @@ static HRESULT WINAPI ddraw_surface7_BltFast(IDirectDrawSurface7 *iface, DWORD d return DDERR_INVALIDRECT; } - EnterCriticalSection(&ddraw_cs); - hr = wined3d_surface_bltfast(This->wined3d_surface, dstx, dsty, - src ? src->wined3d_surface : NULL, rsrc, trans); - LeaveCriticalSection(&ddraw_cs); + SetRect(&dst_rect, dstx, dsty, dstx + src_w, dsty + src_h); + if (trans & DDBLTFAST_SRCCOLORKEY) + flags |= WINEDDBLT_KEYSRC; + if (trans & DDBLTFAST_DESTCOLORKEY) + flags |= WINEDDBLT_KEYDEST; + if (trans & DDBLTFAST_WAIT) + flags |= WINEDDBLT_WAIT; + if (trans & DDBLTFAST_DONOTWAIT) + flags |= WINEDDBLT_DONOTWAIT; + + wined3d_mutex_lock(); + if (This->clipper) + { + wined3d_mutex_unlock(); + WARN("Destination surface has a clipper set, returning DDERR_BLTFASTCANTCLIP.\n"); + return DDERR_BLTFASTCANTCLIP; + } + + if (src->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) + hr = ddraw_surface_update_frontbuffer(src, rsrc, TRUE); + if (SUCCEEDED(hr)) + hr = wined3d_surface_blt(This->wined3d_surface, &dst_rect, + src->wined3d_surface, rsrc, flags, NULL, WINED3D_TEXF_POINT); + if (SUCCEEDED(hr) && (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)) + hr = ddraw_surface_update_frontbuffer(This, &dst_rect, FALSE); + wined3d_mutex_unlock(); + switch(hr) { case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED; @@ -2405,14 +3894,52 @@ static HRESULT WINAPI ddraw_surface7_BltFast(IDirectDrawSurface7 *iface, DWORD d } } -static HRESULT WINAPI ddraw_surface3_BltFast(IDirectDrawSurface3 *iface, DWORD dst_x, DWORD dst_y, - IDirectDrawSurface3 *src_surface, RECT *src_rect, DWORD flags) +static HRESULT WINAPI ddraw_surface4_BltFast(IDirectDrawSurface4 *iface, DWORD dst_x, DWORD dst_y, + IDirectDrawSurface4 *src_surface, RECT *src_rect, DWORD flags) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface4(src_surface); TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n", iface, dst_x, dst_y, src_surface, wine_dbgstr_rect(src_rect), flags); - return ddraw_surface7_BltFast((IDirectDrawSurface7 *)surface_from_surface3(iface), dst_x, dst_y, - src_surface ? (IDirectDrawSurface7 *)surface_from_surface3(src_surface) : NULL, src_rect, flags); + return ddraw_surface7_BltFast(&This->IDirectDrawSurface7_iface, dst_x, dst_y, + src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, src_rect, flags); +} + +static HRESULT WINAPI ddraw_surface3_BltFast(IDirectDrawSurface3 *iface, DWORD dst_x, DWORD dst_y, + IDirectDrawSurface3 *src_surface, RECT *src_rect, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface3(src_surface); + TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n", + iface, dst_x, dst_y, src_surface, wine_dbgstr_rect(src_rect), flags); + + return ddraw_surface7_BltFast(&This->IDirectDrawSurface7_iface, dst_x, dst_y, + src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, src_rect, flags); +} + +static HRESULT WINAPI ddraw_surface2_BltFast(IDirectDrawSurface2 *iface, DWORD dst_x, DWORD dst_y, + IDirectDrawSurface2 *src_surface, RECT *src_rect, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface2(src_surface); + TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n", + iface, dst_x, dst_y, src_surface, wine_dbgstr_rect(src_rect), flags); + + return ddraw_surface7_BltFast(&This->IDirectDrawSurface7_iface, dst_x, dst_y, + src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, src_rect, flags); +} + +static HRESULT WINAPI ddraw_surface1_BltFast(IDirectDrawSurface *iface, DWORD dst_x, DWORD dst_y, + IDirectDrawSurface *src_surface, RECT *src_rect, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface(src_surface); + TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n", + iface, dst_x, dst_y, src_surface, wine_dbgstr_rect(src_rect), flags); + + return ddraw_surface7_BltFast(&This->IDirectDrawSurface7_iface, dst_x, dst_y, + src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, src_rect, flags); } /***************************************************************************** @@ -2432,34 +3959,57 @@ static HRESULT WINAPI ddraw_surface3_BltFast(IDirectDrawSurface3 *iface, DWORD d *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_GetClipper(IDirectDrawSurface7 *iface, IDirectDrawClipper **Clipper) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); TRACE("iface %p, clipper %p.\n", iface, Clipper); - if(!Clipper) - { - LeaveCriticalSection(&ddraw_cs); + if (!Clipper) return DDERR_INVALIDPARAMS; - } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if(This->clipper == NULL) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_NOCLIPPERATTACHED; } *Clipper = (IDirectDrawClipper *)This->clipper; IDirectDrawClipper_AddRef(*Clipper); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return DD_OK; } +static HRESULT WINAPI ddraw_surface4_GetClipper(IDirectDrawSurface4 *iface, IDirectDrawClipper **clipper) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, clipper %p.\n", iface, clipper); + + return ddraw_surface7_GetClipper(&This->IDirectDrawSurface7_iface, clipper); +} + static HRESULT WINAPI ddraw_surface3_GetClipper(IDirectDrawSurface3 *iface, IDirectDrawClipper **clipper) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); TRACE("iface %p, clipper %p.\n", iface, clipper); - return ddraw_surface7_GetClipper((IDirectDrawSurface7 *)surface_from_surface3(iface), clipper); + return ddraw_surface7_GetClipper(&This->IDirectDrawSurface7_iface, clipper); +} + +static HRESULT WINAPI ddraw_surface2_GetClipper(IDirectDrawSurface2 *iface, IDirectDrawClipper **clipper) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, clipper %p.\n", iface, clipper); + + return ddraw_surface7_GetClipper(&This->IDirectDrawSurface7_iface, clipper); +} + +static HRESULT WINAPI ddraw_surface1_GetClipper(IDirectDrawSurface *iface, IDirectDrawClipper **clipper) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, clipper %p.\n", iface, clipper); + + return ddraw_surface7_GetClipper(&This->IDirectDrawSurface7_iface, clipper); } /***************************************************************************** @@ -2474,54 +4024,84 @@ static HRESULT WINAPI ddraw_surface3_GetClipper(IDirectDrawSurface3 *iface, IDir * DD_OK on success * *****************************************************************************/ -static HRESULT WINAPI ddraw_surface7_SetClipper(IDirectDrawSurface7 *iface, IDirectDrawClipper *Clipper) +static HRESULT WINAPI ddraw_surface7_SetClipper(IDirectDrawSurface7 *iface, + IDirectDrawClipper *iclipper) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; - IDirectDrawClipperImpl *oldClipper = This->clipper; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); + struct ddraw_clipper *clipper = unsafe_impl_from_IDirectDrawClipper(iclipper); + struct ddraw_clipper *old_clipper = This->clipper; HWND clipWindow; - HRESULT hr; - TRACE("iface %p, clipper %p.\n", iface, Clipper); + TRACE("iface %p, clipper %p.\n", iface, iclipper); - EnterCriticalSection(&ddraw_cs); - if ((IDirectDrawClipperImpl *)Clipper == This->clipper) + wined3d_mutex_lock(); + if (clipper == This->clipper) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DD_OK; } - This->clipper = (IDirectDrawClipperImpl *)Clipper; + This->clipper = clipper; - if (Clipper != NULL) - IDirectDrawClipper_AddRef(Clipper); - if(oldClipper) - IDirectDrawClipper_Release((IDirectDrawClipper *)oldClipper); + if (clipper != NULL) + IDirectDrawClipper_AddRef(iclipper); + if (old_clipper) + IDirectDrawClipper_Release(&old_clipper->IDirectDrawClipper_iface); - hr = wined3d_surface_set_clipper(This->wined3d_surface, - This->clipper ? This->clipper->wineD3DClipper : NULL); - - if (This->wined3d_swapchain) + if ((This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) && This->ddraw->wined3d_swapchain) { clipWindow = NULL; - if(Clipper) { - IDirectDrawClipper_GetHWnd(Clipper, &clipWindow); + if(clipper) { + IDirectDrawClipper_GetHWnd(iclipper, &clipWindow); } if (clipWindow) - wined3d_swapchain_set_window(This->wined3d_swapchain, clipWindow); + { + wined3d_swapchain_set_window(This->ddraw->wined3d_swapchain, clipWindow); + ddraw_set_swapchain_window(This->ddraw, clipWindow); + } else - wined3d_swapchain_set_window(This->wined3d_swapchain, This->ddraw->d3d_window); + { + wined3d_swapchain_set_window(This->ddraw->wined3d_swapchain, This->ddraw->d3d_window); + ddraw_set_swapchain_window(This->ddraw, This->ddraw->dest_window); + } } - LeaveCriticalSection(&ddraw_cs); - return hr; + wined3d_mutex_unlock(); + + return DD_OK; +} + +static HRESULT WINAPI ddraw_surface4_SetClipper(IDirectDrawSurface4 *iface, IDirectDrawClipper *clipper) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, clipper %p.\n", iface, clipper); + + return ddraw_surface7_SetClipper(&This->IDirectDrawSurface7_iface, clipper); } static HRESULT WINAPI ddraw_surface3_SetClipper(IDirectDrawSurface3 *iface, IDirectDrawClipper *clipper) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); TRACE("iface %p, clipper %p.\n", iface, clipper); - return ddraw_surface7_SetClipper((IDirectDrawSurface7 *)surface_from_surface3(iface), clipper); + return ddraw_surface7_SetClipper(&This->IDirectDrawSurface7_iface, clipper); +} + +static HRESULT WINAPI ddraw_surface2_SetClipper(IDirectDrawSurface2 *iface, IDirectDrawClipper *clipper) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, clipper %p.\n", iface, clipper); + + return ddraw_surface7_SetClipper(&This->IDirectDrawSurface7_iface, clipper); +} + +static HRESULT WINAPI ddraw_surface1_SetClipper(IDirectDrawSurface *iface, IDirectDrawClipper *clipper) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, clipper %p.\n", iface, clipper); + + return ddraw_surface7_SetClipper(&This->IDirectDrawSurface7_iface, clipper); } /***************************************************************************** @@ -2542,56 +4122,147 @@ static HRESULT WINAPI ddraw_surface3_SetClipper(IDirectDrawSurface3 *iface, IDir *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7 *iface, DDSURFACEDESC2 *DDSD, DWORD Flags) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; - enum wined3d_format_id newFormat = WINED3DFMT_UNKNOWN; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); HRESULT hr; + const DWORD allowed_flags = DDSD_LPSURFACE | DDSD_PIXELFORMAT | DDSD_WIDTH + | DDSD_HEIGHT | DDSD_PITCH | DDSD_CAPS; + enum wined3d_format_id format_id; + BOOL update_wined3d = FALSE; + UINT width, height; TRACE("iface %p, surface_desc %p, flags %#x.\n", iface, DDSD, Flags); - if(!DDSD) - return DDERR_INVALIDPARAMS; - - EnterCriticalSection(&ddraw_cs); - if (DDSD->dwFlags & DDSD_PIXELFORMAT) + if (!DDSD) { - newFormat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat); + WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n"); + return DDERR_INVALIDPARAMS; + } + if (Flags) + { + WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags); + return DDERR_INVALIDPARAMS; + } + if (!(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)) + { + WARN("Surface is not in system memory, returning DDERR_INVALIDSURFACETYPE.\n"); + return DDERR_INVALIDSURFACETYPE; + } - if(newFormat == WINED3DFMT_UNKNOWN) + /* Tests show that only LPSURFACE and PIXELFORMAT can be set, and LPSURFACE is required + * for PIXELFORMAT to work */ + if (DDSD->dwFlags & ~allowed_flags) + { + WARN("Invalid flags (0x%08x) set, returning DDERR_INVALIDPARAMS\n", DDSD->dwFlags); + return DDERR_INVALIDPARAMS; + } + if (!(DDSD->dwFlags & DDSD_LPSURFACE)) + { + WARN("DDSD_LPSURFACE is not set, returning DDERR_INVALIDPARAMS\n"); + return DDERR_INVALIDPARAMS; + } + if (DDSD->dwFlags & DDSD_CAPS) + { + WARN("DDSD_CAPS is set, returning DDERR_INVALIDCAPS.\n"); + return DDERR_INVALIDCAPS; + } + if (DDSD->dwFlags & DDSD_WIDTH) + { + if (!(DDSD->dwFlags & DDSD_PITCH)) { - ERR("Requested to set an unknown pixelformat\n"); - LeaveCriticalSection(&ddraw_cs); + WARN("DDSD_WIDTH is set, but DDSD_PITCH is not, returning DDERR_INVALIDPARAMS.\n"); return DDERR_INVALIDPARAMS; } - if(newFormat != PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat) ) + if (!DDSD->dwWidth || DDSD->u1.lPitch <= 0 || DDSD->u1.lPitch & 0x3) { - hr = wined3d_surface_set_format(This->wined3d_surface, newFormat); - if (FAILED(hr)) - { - LeaveCriticalSection(&ddraw_cs); - return hr; - } + WARN("Pitch is %d, width is %u, returning DDERR_INVALIDPARAMS.\n", + DDSD->u1.lPitch, DDSD->dwWidth); + return DDERR_INVALIDPARAMS; + } + if (DDSD->dwWidth != This->surface_desc.dwWidth) + { + TRACE("Surface width changed from %u to %u.\n", This->surface_desc.dwWidth, DDSD->dwWidth); + update_wined3d = TRUE; + } + if (DDSD->u1.lPitch != This->surface_desc.u1.lPitch) + { + TRACE("Surface pitch changed from %u to %u.\n", This->surface_desc.u1.lPitch, DDSD->u1.lPitch); + update_wined3d = TRUE; + } + width = DDSD->dwWidth; + } + else if (DDSD->dwFlags & DDSD_PITCH) + { + WARN("DDSD_PITCH is set, but DDSD_WIDTH is not, returning DDERR_INVALIDPARAMS.\n"); + return DDERR_INVALIDPARAMS; + } + else + { + width = This->surface_desc.dwWidth; + } + + if (DDSD->dwFlags & DDSD_HEIGHT) + { + if (!DDSD->dwHeight) + { + WARN("Height is 0, returning DDERR_INVALIDPARAMS.\n"); + return DDERR_INVALIDPARAMS; + } + if (DDSD->dwHeight != This->surface_desc.dwHeight) + { + TRACE("Surface height changed from %u to %u.\n", This->surface_desc.dwHeight, DDSD->dwHeight); + update_wined3d = TRUE; + } + height = DDSD->dwHeight; + } + else + { + height = This->surface_desc.dwHeight; + } + + wined3d_mutex_lock(); + if (DDSD->dwFlags & DDSD_PIXELFORMAT) + { + enum wined3d_format_id current_format_id; + format_id = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat); + + if (format_id == WINED3DFMT_UNKNOWN) + { + ERR("Requested to set an unknown pixelformat\n"); + wined3d_mutex_unlock(); + return DDERR_INVALIDPARAMS; + } + current_format_id = PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat); + if (format_id != current_format_id) + { + TRACE("Surface format changed from %#x to %#x.\n", current_format_id, format_id); + update_wined3d = TRUE; } } - if (DDSD->dwFlags & DDSD_CKDESTOVERLAY) + else { - wined3d_surface_set_color_key(This->wined3d_surface, DDCKEY_DESTOVERLAY, - (WINEDDCOLORKEY *)&DDSD->u3.ddckCKDestOverlay); + format_id = PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat); } - if (DDSD->dwFlags & DDSD_CKDESTBLT) + + if (update_wined3d) { - wined3d_surface_set_color_key(This->wined3d_surface, DDCKEY_DESTBLT, - (WINEDDCOLORKEY *)&DDSD->ddckCKDestBlt); - } - if (DDSD->dwFlags & DDSD_CKSRCOVERLAY) - { - wined3d_surface_set_color_key(This->wined3d_surface, DDCKEY_SRCOVERLAY, - (WINEDDCOLORKEY *)&DDSD->ddckCKSrcOverlay); - } - if (DDSD->dwFlags & DDSD_CKSRCBLT) - { - wined3d_surface_set_color_key(This->wined3d_surface, DDCKEY_SRCBLT, - (WINEDDCOLORKEY *)&DDSD->ddckCKSrcBlt); + if (FAILED(hr = wined3d_surface_update_desc(This->wined3d_surface, width, height, + format_id, WINED3D_MULTISAMPLE_NONE, 0))) + { + WARN("Failed to update surface desc, hr %#x.\n", hr); + wined3d_mutex_unlock(); + return hr; + } + + if (DDSD->dwFlags & DDSD_WIDTH) + This->surface_desc.dwWidth = width; + if (DDSD->dwFlags & DDSD_PITCH) + This->surface_desc.u1.lPitch = DDSD->u1.lPitch; + if (DDSD->dwFlags & DDSD_HEIGHT) + This->surface_desc.dwHeight = height; + if (DDSD->dwFlags & DDSD_PIXELFORMAT) + This->surface_desc.u4.ddpfPixelFormat = DDSD->u4.ddpfPixelFormat; } + if (DDSD->dwFlags & DDSD_LPSURFACE && DDSD->lpSurface) { hr = wined3d_surface_set_mem(This->wined3d_surface, DDSD->lpSurface); @@ -2601,27 +4272,40 @@ static HRESULT WINAPI ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7 *iface, switch(hr) { case WINED3DERR_INVALIDCALL: - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; default: break; /* Go on */ } } + /* DDSD->lpSurface is set by Lock() */ } - This->surface_desc = *DDSD; + wined3d_mutex_unlock(); - LeaveCriticalSection(&ddraw_cs); return DD_OK; } +static HRESULT WINAPI ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4 *iface, + DDSURFACEDESC2 *surface_desc, DWORD flags) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, surface_desc %p, flags %#x.\n", iface, surface_desc, flags); + + return ddraw_surface7_SetSurfaceDesc(&This->IDirectDrawSurface7_iface, + surface_desc, flags); +} + static HRESULT WINAPI ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3 *iface, DDSURFACEDESC *surface_desc, DWORD flags) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + DDSURFACEDESC2 surface_desc2; TRACE("iface %p, surface_desc %p, flags %#x.\n", iface, surface_desc, flags); - return ddraw_surface7_SetSurfaceDesc((IDirectDrawSurface7 *)surface_from_surface3(iface), - (DDSURFACEDESC2 *)surface_desc, flags); + if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2); + return ddraw_surface7_SetSurfaceDesc(&This->IDirectDrawSurface7_iface, + surface_desc ? &surface_desc2 : NULL, flags); } /***************************************************************************** @@ -2640,7 +4324,7 @@ static HRESULT WINAPI ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3 *iface, *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_GetPalette(IDirectDrawSurface7 *iface, IDirectDrawPalette **Pal) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); struct wined3d_palette *wined3d_palette; HRESULT hr = DD_OK; @@ -2649,7 +4333,7 @@ static HRESULT WINAPI ddraw_surface7_GetPalette(IDirectDrawSurface7 *iface, IDir if(!Pal) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); wined3d_palette = wined3d_surface_get_palette(This->wined3d_surface); if (wined3d_palette) { @@ -2662,15 +4346,41 @@ static HRESULT WINAPI ddraw_surface7_GetPalette(IDirectDrawSurface7 *iface, IDir hr = DDERR_NOPALETTEATTACHED; } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } +static HRESULT WINAPI ddraw_surface4_GetPalette(IDirectDrawSurface4 *iface, IDirectDrawPalette **palette) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, palette %p.\n", iface, palette); + + return ddraw_surface7_GetPalette(&This->IDirectDrawSurface7_iface, palette); +} + static HRESULT WINAPI ddraw_surface3_GetPalette(IDirectDrawSurface3 *iface, IDirectDrawPalette **palette) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); TRACE("iface %p, palette %p.\n", iface, palette); - return ddraw_surface7_GetPalette((IDirectDrawSurface7 *)surface_from_surface3(iface), palette); + return ddraw_surface7_GetPalette(&This->IDirectDrawSurface7_iface, palette); +} + +static HRESULT WINAPI ddraw_surface2_GetPalette(IDirectDrawSurface2 *iface, IDirectDrawPalette **palette) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, palette %p.\n", iface, palette); + + return ddraw_surface7_GetPalette(&This->IDirectDrawSurface7_iface, palette); +} + +static HRESULT WINAPI ddraw_surface1_GetPalette(IDirectDrawSurface *iface, IDirectDrawPalette **palette) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, palette %p.\n", iface, palette); + + return ddraw_surface7_GetPalette(&This->IDirectDrawSurface7_iface, palette); } /***************************************************************************** @@ -2683,7 +4393,7 @@ static HRESULT WINAPI ddraw_surface3_GetPalette(IDirectDrawSurface3 *iface, IDir struct SCKContext { HRESULT ret; - WINEDDCOLORKEY *CKey; + struct wined3d_color_key *color_key; DWORD Flags; }; @@ -2692,11 +4402,11 @@ SetColorKeyEnum(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)surface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(surface); struct SCKContext *ctx = context; HRESULT hr; - hr = wined3d_surface_set_color_key(This->wined3d_surface, ctx->Flags, ctx->CKey); + hr = wined3d_surface_set_color_key(This->wined3d_surface, ctx->Flags, ctx->color_key); if (FAILED(hr)) { WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr); @@ -2727,13 +4437,13 @@ SetColorKeyEnum(IDirectDrawSurface7 *surface, *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_SetColorKey(IDirectDrawSurface7 *iface, DWORD Flags, DDCOLORKEY *CKey) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); DDCOLORKEY FixedCKey; - struct SCKContext ctx = { DD_OK, (WINEDDCOLORKEY *) (CKey ? &FixedCKey : NULL), Flags }; + struct SCKContext ctx = { DD_OK, (struct wined3d_color_key *)(CKey ? &FixedCKey : NULL), Flags }; TRACE("iface %p, flags %#x, color_key %p.\n", iface, Flags, CKey); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if (CKey) { FixedCKey = *CKey; @@ -2764,7 +4474,7 @@ static HRESULT WINAPI ddraw_surface7_SetColorKey(IDirectDrawSurface7 *iface, DWO break; default: - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } } @@ -2789,13 +4499,14 @@ static HRESULT WINAPI ddraw_surface7_SetColorKey(IDirectDrawSurface7 *iface, DWO break; default: - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } } - ctx.ret = wined3d_surface_set_color_key(This->wined3d_surface, Flags, ctx.CKey); + ctx.ret = wined3d_surface_set_color_key(This->wined3d_surface, Flags, ctx.color_key); ddraw_surface7_EnumAttachedSurfaces(iface, &ctx, SetColorKeyEnum); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + switch(ctx.ret) { case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS; @@ -2803,11 +4514,36 @@ static HRESULT WINAPI ddraw_surface7_SetColorKey(IDirectDrawSurface7 *iface, DWO } } -static HRESULT WINAPI ddraw_surface3_SetColorKey(IDirectDrawSurface3 *iface, DWORD flags, DDCOLORKEY *color_key) +static HRESULT WINAPI ddraw_surface4_SetColorKey(IDirectDrawSurface4 *iface, DWORD flags, DDCOLORKEY *color_key) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key); - return ddraw_surface7_SetColorKey((IDirectDrawSurface7 *)surface_from_surface3(iface), flags, color_key); + return ddraw_surface7_SetColorKey(&This->IDirectDrawSurface7_iface, flags, color_key); +} + +static HRESULT WINAPI ddraw_surface3_SetColorKey(IDirectDrawSurface3 *iface, DWORD flags, DDCOLORKEY *color_key) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); + TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key); + + return ddraw_surface7_SetColorKey(&This->IDirectDrawSurface7_iface, flags, color_key); +} + +static HRESULT WINAPI ddraw_surface2_SetColorKey(IDirectDrawSurface2 *iface, DWORD flags, DDCOLORKEY *color_key) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key); + + return ddraw_surface7_SetColorKey(&This->IDirectDrawSurface7_iface, flags, color_key); +} + +static HRESULT WINAPI ddraw_surface1_SetColorKey(IDirectDrawSurface *iface, DWORD flags, DDCOLORKEY *color_key) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key); + + return ddraw_surface7_SetColorKey(&This->IDirectDrawSurface7_iface, flags, color_key); } /***************************************************************************** @@ -2824,10 +4560,10 @@ static HRESULT WINAPI ddraw_surface3_SetColorKey(IDirectDrawSurface3 *iface, DWO *****************************************************************************/ static HRESULT WINAPI ddraw_surface7_SetPalette(IDirectDrawSurface7 *iface, IDirectDrawPalette *Pal) { - IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); IDirectDrawPalette *oldPal; IDirectDrawSurfaceImpl *surf; - IDirectDrawPaletteImpl *PalImpl = (IDirectDrawPaletteImpl *)Pal; + IDirectDrawPaletteImpl *PalImpl = unsafe_impl_from_IDirectDrawPalette(Pal); HRESULT hr; TRACE("iface %p, palette %p.\n", iface, Pal); @@ -2837,12 +4573,17 @@ static HRESULT WINAPI ddraw_surface7_SetPalette(IDirectDrawSurface7 *iface, IDir return DDERR_INVALIDPIXELFORMAT; } + if (This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_MIPMAPSUBLEVEL) + { + return DDERR_NOTONMIPMAPSUBLEVEL; + } + /* Find the old palette */ - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = IDirectDrawSurface_GetPalette(iface, &oldPal); if(hr != DD_OK && hr != DDERR_NOPALETTEATTACHED) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } if(oldPal) IDirectDrawPalette_Release(oldPal); /* For the GetPalette */ @@ -2855,6 +4596,14 @@ static HRESULT WINAPI ddraw_surface7_SetPalette(IDirectDrawSurface7 *iface, IDir /* Release the old palette */ if(oldPal) IDirectDrawPalette_Release(oldPal); + /* Update the wined3d frontbuffer if this is the frontbuffer. */ + if ((This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) && This->ddraw->wined3d_frontbuffer) + { + hr = wined3d_surface_set_palette(This->ddraw->wined3d_frontbuffer, PalImpl ? PalImpl->wineD3DPalette : NULL); + if (FAILED(hr)) + ERR("Failed to set frontbuffer palette, hr %#x.\n", hr); + } + /* If this is a front buffer, also update the back buffers * TODO: How do things work for palettized cube textures? */ @@ -2868,7 +4617,7 @@ static HRESULT WINAPI ddraw_surface7_SetPalette(IDirectDrawSurface7 *iface, IDir { IDirectDrawSurface7 *attach; HRESULT hr; - hr = ddraw_surface7_GetAttachedSurface((IDirectDrawSurface7 *)surf, &caps2, &attach); + hr = ddraw_surface7_GetAttachedSurface(&surf->IDirectDrawSurface7_iface, &caps2, &attach); if(hr != DD_OK) { break; @@ -2876,20 +4625,46 @@ static HRESULT WINAPI ddraw_surface7_SetPalette(IDirectDrawSurface7 *iface, IDir TRACE("Setting palette on %p\n", attach); ddraw_surface7_SetPalette(attach, Pal); - surf = (IDirectDrawSurfaceImpl *)attach; + surf = impl_from_IDirectDrawSurface7(attach); ddraw_surface7_Release(attach); } } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return DD_OK; } +static HRESULT WINAPI ddraw_surface4_SetPalette(IDirectDrawSurface4 *iface, IDirectDrawPalette *palette) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface4(iface); + TRACE("iface %p, palette %p.\n", iface, palette); + + return ddraw_surface7_SetPalette(&This->IDirectDrawSurface7_iface, palette); +} + static HRESULT WINAPI ddraw_surface3_SetPalette(IDirectDrawSurface3 *iface, IDirectDrawPalette *palette) { + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); TRACE("iface %p, palette %p.\n", iface, palette); - return ddraw_surface7_SetPalette((IDirectDrawSurface7 *)surface_from_surface3(iface), palette); + return ddraw_surface7_SetPalette(&This->IDirectDrawSurface7_iface, palette); +} + +static HRESULT WINAPI ddraw_surface2_SetPalette(IDirectDrawSurface2 *iface, IDirectDrawPalette *palette) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface); + TRACE("iface %p, palette %p.\n", iface, palette); + + return ddraw_surface7_SetPalette(&This->IDirectDrawSurface7_iface, palette); +} + +static HRESULT WINAPI ddraw_surface1_SetPalette(IDirectDrawSurface *iface, IDirectDrawPalette *palette) +{ + IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); + TRACE("iface %p, palette %p.\n", iface, palette); + + return ddraw_surface7_SetPalette(&This->IDirectDrawSurface7_iface, palette); } /********************************************************** @@ -2909,7 +4684,7 @@ static HRESULT WINAPI ddraw_surface3_SetPalette(IDirectDrawSurface3 *iface, IDir static HRESULT WINAPI ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl *iface, DWORD flags, DDGAMMARAMP *gamma_ramp) { - IDirectDrawSurfaceImpl *surface = surface_from_gamma_control(iface); + IDirectDrawSurfaceImpl *surface = impl_from_IDirectDrawGammaControl(iface); TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface, flags, gamma_ramp); @@ -2919,17 +4694,17 @@ static HRESULT WINAPI ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl * return DDERR_INVALIDPARAMS; } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) { - /* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP. */ - wined3d_device_get_gamma_ramp(surface->ddraw->wined3d_device, 0, (WINED3DGAMMARAMP *)gamma_ramp); + /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */ + wined3d_device_get_gamma_ramp(surface->ddraw->wined3d_device, 0, (struct wined3d_gamma_ramp *)gamma_ramp); } else { ERR("Not implemented for non-primary surfaces.\n"); } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DD_OK; } @@ -2951,7 +4726,7 @@ static HRESULT WINAPI ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl * static HRESULT WINAPI ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl *iface, DWORD flags, DDGAMMARAMP *gamma_ramp) { - IDirectDrawSurfaceImpl *surface = surface_from_gamma_control(iface); + IDirectDrawSurfaceImpl *surface = impl_from_IDirectDrawGammaControl(iface); TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface, flags, gamma_ramp); @@ -2961,17 +4736,18 @@ static HRESULT WINAPI ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl * return DDERR_INVALIDPARAMS; } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) { - /* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP */ - wined3d_device_set_gamma_ramp(surface->ddraw->wined3d_device, 0, flags, (WINED3DGAMMARAMP *)gamma_ramp); + /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */ + wined3d_device_set_gamma_ramp(surface->ddraw->wined3d_device, + 0, flags, (struct wined3d_gamma_ramp *)gamma_ramp); } else { ERR("Not implemented for non-primary surfaces.\n"); } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DD_OK; } @@ -2998,11 +4774,11 @@ static HRESULT WINAPI d3d_texture2_PaletteChanged(IDirect3DTexture2 *iface, DWOR static HRESULT WINAPI d3d_texture1_PaletteChanged(IDirect3DTexture *iface, DWORD start, DWORD count) { - IDirectDrawSurfaceImpl *surface = surface_from_texture1(iface); + IDirectDrawSurfaceImpl *surface = impl_from_IDirect3DTexture(iface); TRACE("iface %p, start %u, count %u.\n", iface, start, count); - return d3d_texture2_PaletteChanged((IDirect3DTexture2 *)&surface->IDirect3DTexture2_vtbl, start, count); + return d3d_texture2_PaletteChanged(&surface->IDirect3DTexture2_iface, start, count); } /***************************************************************************** @@ -3039,19 +4815,20 @@ static HRESULT WINAPI d3d_texture1_Unload(IDirect3DTexture *iface) static HRESULT WINAPI d3d_texture2_GetHandle(IDirect3DTexture2 *iface, IDirect3DDevice2 *device, D3DTEXTUREHANDLE *handle) { - IDirectDrawSurfaceImpl *surface = surface_from_texture2(iface); + IDirectDrawSurfaceImpl *surface = impl_from_IDirect3DTexture2(iface); + IDirect3DDeviceImpl *device_impl = unsafe_impl_from_IDirect3DDevice2(device); TRACE("iface %p, device %p, handle %p.\n", iface, device, handle); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if (!surface->Handle) { - DWORD h = ddraw_allocate_handle(&device_from_device2(device)->handle_table, surface, DDRAW_HANDLE_SURFACE); + DWORD h = ddraw_allocate_handle(&device_impl->handle_table, surface, DDRAW_HANDLE_SURFACE); if (h == DDRAW_INVALID_HANDLE) { ERR("Failed to allocate a texture handle.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_OUTOFMEMORY; } @@ -3061,7 +4838,7 @@ static HRESULT WINAPI d3d_texture2_GetHandle(IDirect3DTexture2 *iface, TRACE("Returning handle %08x.\n", surface->Handle); *handle = surface->Handle; - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } @@ -3069,12 +4846,13 @@ static HRESULT WINAPI d3d_texture2_GetHandle(IDirect3DTexture2 *iface, static HRESULT WINAPI d3d_texture1_GetHandle(IDirect3DTexture *iface, IDirect3DDevice *device, D3DTEXTUREHANDLE *handle) { - IDirect3DTexture2 *texture2 = (IDirect3DTexture2 *)&surface_from_texture1(iface)->IDirect3DTexture2_vtbl; - IDirect3DDevice2 *device2 = (IDirect3DDevice2 *)&device_from_device1(device)->IDirect3DDevice2_vtbl; + IDirectDrawSurfaceImpl *This = impl_from_IDirect3DTexture(iface); + IDirect3DDeviceImpl *device_impl = unsafe_impl_from_IDirect3DDevice(device); TRACE("iface %p, device %p, handle %p.\n", iface, device, handle); - return d3d_texture2_GetHandle(texture2, device2, handle); + return d3d_texture2_GetHandle(&This->IDirect3DTexture2_iface, + device_impl ? &device_impl->IDirect3DDevice2_iface : NULL, handle); } /***************************************************************************** @@ -3092,12 +4870,12 @@ static IDirectDrawSurfaceImpl *get_sub_mimaplevel(IDirectDrawSurfaceImpl *surfac IDirectDrawSurface7 *next_level; HRESULT hr; - hr = ddraw_surface7_GetAttachedSurface((IDirectDrawSurface7 *)surface, &mipmap_caps, &next_level); + hr = ddraw_surface7_GetAttachedSurface(&surface->IDirectDrawSurface7_iface, &mipmap_caps, &next_level); if (FAILED(hr)) return NULL; ddraw_surface7_Release(next_level); - return (IDirectDrawSurfaceImpl *)next_level; + return impl_from_IDirectDrawSurface7(next_level); } /***************************************************************************** @@ -3119,8 +4897,8 @@ static IDirectDrawSurfaceImpl *get_sub_mimaplevel(IDirectDrawSurfaceImpl *surfac *****************************************************************************/ static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTexture2 *src_texture) { - IDirectDrawSurfaceImpl *dst_surface = surface_from_texture2(iface); - IDirectDrawSurfaceImpl *src_surface = surface_from_texture2(src_texture); + IDirectDrawSurfaceImpl *dst_surface = impl_from_IDirect3DTexture2(iface); + IDirectDrawSurfaceImpl *src_surface = unsafe_impl_from_IDirect3DTexture2(src_texture); HRESULT hr; TRACE("iface %p, src_texture %p.\n", iface, src_texture); @@ -3131,7 +4909,7 @@ static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTextu return D3D_OK; } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if (((src_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP) != (dst_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)) @@ -3167,7 +4945,7 @@ static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTextu if (!dst_pal) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_NOPALETTEATTACHED; } IDirectDrawPalette_GetEntries(src_pal, 0, 0, 256, palent); @@ -3182,12 +4960,12 @@ static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTextu { /* Should also check for same pixel format, u1.lPitch, ... */ ERR("Error in surface sizes.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3DERR_TEXTURE_LOAD_FAILED; } else { - WINED3DLOCKED_RECT src_rect, dst_rect; + struct wined3d_mapped_rect src_rect, dst_rect; /* Copy also the ColorKeying stuff */ if (src_desc->dwFlags & DDSD_CKSRCBLT) @@ -3204,7 +4982,7 @@ static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTextu if (FAILED(hr)) { ERR("Failed to lock source surface, hr %#x.\n", hr); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3DERR_TEXTURE_LOAD_FAILED; } @@ -3213,14 +4991,14 @@ static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTextu { ERR("Failed to lock destination surface, hr %#x.\n", hr); wined3d_surface_unmap(src_surface->wined3d_surface); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3DERR_TEXTURE_LOAD_FAILED; } if (dst_surface->surface_desc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC) - memcpy(dst_rect.pBits, src_rect.pBits, src_surface->surface_desc.u1.dwLinearSize); + memcpy(dst_rect.data, src_rect.data, src_surface->surface_desc.u1.dwLinearSize); else - memcpy(dst_rect.pBits, src_rect.pBits, src_rect.Pitch * src_desc->dwHeight); + memcpy(dst_rect.data, src_rect.data, src_rect.row_pitch * src_desc->dwHeight); wined3d_surface_unmap(src_surface->wined3d_surface); wined3d_surface_unmap(dst_surface->wined3d_surface); @@ -3244,17 +5022,19 @@ static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTextu } } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } static HRESULT WINAPI d3d_texture1_Load(IDirect3DTexture *iface, IDirect3DTexture *src_texture) { + IDirectDrawSurfaceImpl* This = impl_from_IDirect3DTexture(iface); + IDirectDrawSurfaceImpl* src_surface = unsafe_impl_from_IDirect3DTexture(src_texture); TRACE("iface %p, src_texture %p.\n", iface, src_texture); - return d3d_texture2_Load((IDirect3DTexture2 *)&surface_from_texture1(iface)->IDirect3DTexture2_vtbl, - src_texture ? (IDirect3DTexture2 *)&surface_from_texture1(src_texture)->IDirect3DTexture2_vtbl : NULL); + return d3d_texture2_Load(&This->IDirect3DTexture2_iface, + src_surface ? &src_surface->IDirect3DTexture2_iface : NULL); } /***************************************************************************** @@ -3320,6 +5100,60 @@ static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl = ddraw_surface7_GetLOD, }; +static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl = +{ + /* IUnknown */ + ddraw_surface4_QueryInterface, + ddraw_surface4_AddRef, + ddraw_surface4_Release, + /* IDirectDrawSurface */ + ddraw_surface4_AddAttachedSurface, + ddraw_surface4_AddOverlayDirtyRect, + ddraw_surface4_Blt, + ddraw_surface4_BltBatch, + ddraw_surface4_BltFast, + ddraw_surface4_DeleteAttachedSurface, + ddraw_surface4_EnumAttachedSurfaces, + ddraw_surface4_EnumOverlayZOrders, + ddraw_surface4_Flip, + ddraw_surface4_GetAttachedSurface, + ddraw_surface4_GetBltStatus, + ddraw_surface4_GetCaps, + ddraw_surface4_GetClipper, + ddraw_surface4_GetColorKey, + ddraw_surface4_GetDC, + ddraw_surface4_GetFlipStatus, + ddraw_surface4_GetOverlayPosition, + ddraw_surface4_GetPalette, + ddraw_surface4_GetPixelFormat, + ddraw_surface4_GetSurfaceDesc, + ddraw_surface4_Initialize, + ddraw_surface4_IsLost, + ddraw_surface4_Lock, + ddraw_surface4_ReleaseDC, + ddraw_surface4_Restore, + ddraw_surface4_SetClipper, + ddraw_surface4_SetColorKey, + ddraw_surface4_SetOverlayPosition, + ddraw_surface4_SetPalette, + ddraw_surface4_Unlock, + ddraw_surface4_UpdateOverlay, + ddraw_surface4_UpdateOverlayDisplay, + ddraw_surface4_UpdateOverlayZOrder, + /* IDirectDrawSurface2 */ + ddraw_surface4_GetDDInterface, + ddraw_surface4_PageLock, + ddraw_surface4_PageUnlock, + /* IDirectDrawSurface3 */ + ddraw_surface4_SetSurfaceDesc, + /* IDirectDrawSurface4 */ + ddraw_surface4_SetPrivateData, + ddraw_surface4_GetPrivateData, + ddraw_surface4_FreePrivateData, + ddraw_surface4_GetUniquenessValue, + ddraw_surface4_ChangeUniquenessValue, +}; + static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl = { /* IUnknown */ @@ -3368,6 +5202,94 @@ static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl = ddraw_surface3_SetSurfaceDesc, }; +static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl = +{ + /* IUnknown */ + ddraw_surface2_QueryInterface, + ddraw_surface2_AddRef, + ddraw_surface2_Release, + /* IDirectDrawSurface */ + ddraw_surface2_AddAttachedSurface, + ddraw_surface2_AddOverlayDirtyRect, + ddraw_surface2_Blt, + ddraw_surface2_BltBatch, + ddraw_surface2_BltFast, + ddraw_surface2_DeleteAttachedSurface, + ddraw_surface2_EnumAttachedSurfaces, + ddraw_surface2_EnumOverlayZOrders, + ddraw_surface2_Flip, + ddraw_surface2_GetAttachedSurface, + ddraw_surface2_GetBltStatus, + ddraw_surface2_GetCaps, + ddraw_surface2_GetClipper, + ddraw_surface2_GetColorKey, + ddraw_surface2_GetDC, + ddraw_surface2_GetFlipStatus, + ddraw_surface2_GetOverlayPosition, + ddraw_surface2_GetPalette, + ddraw_surface2_GetPixelFormat, + ddraw_surface2_GetSurfaceDesc, + ddraw_surface2_Initialize, + ddraw_surface2_IsLost, + ddraw_surface2_Lock, + ddraw_surface2_ReleaseDC, + ddraw_surface2_Restore, + ddraw_surface2_SetClipper, + ddraw_surface2_SetColorKey, + ddraw_surface2_SetOverlayPosition, + ddraw_surface2_SetPalette, + ddraw_surface2_Unlock, + ddraw_surface2_UpdateOverlay, + ddraw_surface2_UpdateOverlayDisplay, + ddraw_surface2_UpdateOverlayZOrder, + /* IDirectDrawSurface2 */ + ddraw_surface2_GetDDInterface, + ddraw_surface2_PageLock, + ddraw_surface2_PageUnlock, +}; + +static const struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl = +{ + /* IUnknown */ + ddraw_surface1_QueryInterface, + ddraw_surface1_AddRef, + ddraw_surface1_Release, + /* IDirectDrawSurface */ + ddraw_surface1_AddAttachedSurface, + ddraw_surface1_AddOverlayDirtyRect, + ddraw_surface1_Blt, + ddraw_surface1_BltBatch, + ddraw_surface1_BltFast, + ddraw_surface1_DeleteAttachedSurface, + ddraw_surface1_EnumAttachedSurfaces, + ddraw_surface1_EnumOverlayZOrders, + ddraw_surface1_Flip, + ddraw_surface1_GetAttachedSurface, + ddraw_surface1_GetBltStatus, + ddraw_surface1_GetCaps, + ddraw_surface1_GetClipper, + ddraw_surface1_GetColorKey, + ddraw_surface1_GetDC, + ddraw_surface1_GetFlipStatus, + ddraw_surface1_GetOverlayPosition, + ddraw_surface1_GetPalette, + ddraw_surface1_GetPixelFormat, + ddraw_surface1_GetSurfaceDesc, + ddraw_surface1_Initialize, + ddraw_surface1_IsLost, + ddraw_surface1_Lock, + ddraw_surface1_ReleaseDC, + ddraw_surface1_Restore, + ddraw_surface1_SetClipper, + ddraw_surface1_SetColorKey, + ddraw_surface1_SetOverlayPosition, + ddraw_surface1_SetPalette, + ddraw_surface1_Unlock, + ddraw_surface1_UpdateOverlay, + ddraw_surface1_UpdateOverlayDisplay, + ddraw_surface1_UpdateOverlayZOrder, +}; + static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl = { ddraw_gamma_control_QueryInterface, @@ -3399,6 +5321,55 @@ static const struct IDirect3DTextureVtbl d3d_texture1_vtbl = d3d_texture1_Unload, }; +IDirectDrawSurfaceImpl *unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7 *iface) +{ + if (!iface) return NULL; + assert(iface->lpVtbl == &ddraw_surface7_vtbl); + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirectDrawSurface7_iface); +} + +IDirectDrawSurfaceImpl *unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4 *iface) +{ + if (!iface) return NULL; + assert(iface->lpVtbl == &ddraw_surface4_vtbl); + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirectDrawSurface4_iface); +} + +static IDirectDrawSurfaceImpl *unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3 *iface) +{ + if (!iface) return NULL; + assert(iface->lpVtbl == &ddraw_surface3_vtbl); + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirectDrawSurface3_iface); +} + +static IDirectDrawSurfaceImpl *unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2 *iface) +{ + if (!iface) return NULL; + assert(iface->lpVtbl == &ddraw_surface2_vtbl); + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirectDrawSurface2_iface); +} + +IDirectDrawSurfaceImpl *unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface *iface) +{ + if (!iface) return NULL; + assert(iface->lpVtbl == &ddraw_surface1_vtbl); + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirectDrawSurface_iface); +} + +IDirectDrawSurfaceImpl *unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2 *iface) +{ + if (!iface) return NULL; + assert(iface->lpVtbl == &d3d_texture2_vtbl); + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirect3DTexture2_iface); +} + +IDirectDrawSurfaceImpl *unsafe_impl_from_IDirect3DTexture(IDirect3DTexture *iface) +{ + if (!iface) return NULL; + assert(iface->lpVtbl == &d3d_texture1_vtbl); + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirect3DTexture_iface); +} + static void STDMETHODCALLTYPE ddraw_surface_wined3d_object_destroyed(void *parent) { IDirectDrawSurfaceImpl *surface = parent; @@ -3408,9 +5379,6 @@ static void STDMETHODCALLTYPE ddraw_surface_wined3d_object_destroyed(void *paren /* Check for attached surfaces and detach them. */ if (surface->first_attached != surface) { - IDirectDrawSurface7 *root = (IDirectDrawSurface7 *)surface->first_attached; - IDirectDrawSurface7 *detach = (IDirectDrawSurface7 *)surface; - /* Well, this shouldn't happen: The surface being attached is * referenced in AddAttachedSurface(), so it shouldn't be released * until DeleteAttachedSurface() is called, because the refcount is @@ -3419,27 +5387,25 @@ static void STDMETHODCALLTYPE ddraw_surface_wined3d_object_destroyed(void *paren WARN("Surface is still attached to surface %p.\n", surface->first_attached); /* The refcount will drop to -1 here */ - if (FAILED(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach))) + if (FAILED(ddraw_surface_delete_attached_surface(surface->first_attached, surface, surface->attached_iface))) ERR("DeleteAttachedSurface failed.\n"); } while (surface->next_attached) - { - IDirectDrawSurface7 *root = (IDirectDrawSurface7 *)surface; - IDirectDrawSurface7 *detach = (IDirectDrawSurface7 *)surface->next_attached; - - if (FAILED(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach))) + if (FAILED(ddraw_surface_delete_attached_surface(surface, + surface->next_attached, surface->next_attached->attached_iface))) ERR("DeleteAttachedSurface failed.\n"); - } /* Having a texture handle set implies that the device still exists. */ if (surface->Handle) ddraw_free_handle(&surface->ddraw->d3ddevice->handle_table, surface->Handle - 1, DDRAW_HANDLE_SURFACE); /* Reduce the ddraw surface count. */ - InterlockedDecrement(&surface->ddraw->surfaces); list_remove(&surface->surface_list_entry); + if (surface == surface->ddraw->primary) + surface->ddraw->primary = NULL; + HeapFree(GetProcessHeap(), 0, surface); } @@ -3466,7 +5432,7 @@ HRESULT ddraw_surface_create_texture(IDirectDrawSurfaceImpl *surface) { const DDSURFACEDESC2 *desc = &surface->surface_desc; enum wined3d_format_id format; - WINED3DPOOL pool; + enum wined3d_pool pool; UINT levels; if (desc->ddsCaps.dwCaps & DDSCAPS_MIPMAP) @@ -3474,12 +5440,12 @@ HRESULT ddraw_surface_create_texture(IDirectDrawSurfaceImpl *surface) else levels = 1; - /* DDSCAPS_SYSTEMMEMORY textures are in WINED3DPOOL_SYSTEMMEM. + /* DDSCAPS_SYSTEMMEMORY textures are in WINED3D_POOL_SYSTEM_MEM. * Should I forward the MANAGED cap to the managed pool? */ if (desc->ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY) - pool = WINED3DPOOL_SYSTEMMEM; + pool = WINED3D_POOL_SYSTEM_MEM; else - pool = WINED3DPOOL_DEFAULT; + pool = WINED3D_POOL_DEFAULT; format = PixelFormat_DD2WineD3D(&surface->surface_desc.u4.ddpfPixelFormat); if (desc->ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP) @@ -3491,11 +5457,10 @@ HRESULT ddraw_surface_create_texture(IDirectDrawSurfaceImpl *surface) } HRESULT ddraw_surface_init(IDirectDrawSurfaceImpl *surface, IDirectDrawImpl *ddraw, - DDSURFACEDESC2 *desc, UINT mip_level, WINED3DSURFTYPE surface_type) + DDSURFACEDESC2 *desc, UINT mip_level, UINT version) { - struct wined3d_resource_desc wined3d_desc; - struct wined3d_resource *wined3d_resource; - WINED3DPOOL pool = WINED3DPOOL_DEFAULT; + enum wined3d_pool pool = WINED3D_POOL_DEFAULT; + DWORD flags = WINED3D_SURFACE_MAPPABLE; enum wined3d_format_id format; DWORD usage = 0; HRESULT hr; @@ -3511,6 +5476,13 @@ HRESULT ddraw_surface_init(IDirectDrawSurfaceImpl *surface, IDirectDrawImpl *ddr if (desc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) { + /* Some applications assume that the primary surface will always be + * mapped at the same address. Some of those also assume that this + * address is valid even when the surface isn't mapped, and that + * updates done this way will be visible on the screen. The game Nox + * is such an application. */ + if (version == 1) + flags |= WINED3D_SURFACE_PIN_SYSMEM; usage |= WINED3DUSAGE_RENDERTARGET; desc->ddsCaps.dwCaps |= DDSCAPS_VISIBLE; } @@ -3525,20 +5497,19 @@ HRESULT ddraw_surface_init(IDirectDrawSurfaceImpl *surface, IDirectDrawImpl *ddr usage |= WINED3DUSAGE_OVERLAY; } - if (ddraw->depthstencil || (desc->ddsCaps.dwCaps & DDSCAPS_ZBUFFER)) - { - /* The depth stencil creation callback sets this flag. Set the - * wined3d usage to let it know it's a depth/stencil surface. */ + if (desc->ddsCaps.dwCaps & DDSCAPS_ZBUFFER) usage |= WINED3DUSAGE_DEPTHSTENCIL; - } + + if (desc->ddsCaps.dwCaps & DDSCAPS_OWNDC) + usage |= WINED3DUSAGE_OWNDC; if (desc->ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY) { - pool = WINED3DPOOL_SYSTEMMEM; + pool = WINED3D_POOL_SYSTEM_MEM; } else if (desc->ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE) { - pool = WINED3DPOOL_MANAGED; + pool = WINED3D_POOL_MANAGED; /* Managed textures have the system memory flag set. */ desc->ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; } @@ -3556,41 +5527,44 @@ HRESULT ddraw_surface_init(IDirectDrawSurfaceImpl *surface, IDirectDrawImpl *ddr return DDERR_INVALIDPIXELFORMAT; } - surface->lpVtbl = &ddraw_surface7_vtbl; - surface->IDirectDrawSurface3_vtbl = &ddraw_surface3_vtbl; - surface->IDirectDrawGammaControl_vtbl = &ddraw_gamma_control_vtbl; - surface->IDirect3DTexture2_vtbl = &d3d_texture2_vtbl; - surface->IDirect3DTexture_vtbl = &d3d_texture1_vtbl; - surface->ref = 1; - surface->version = 7; + surface->IDirectDrawSurface7_iface.lpVtbl = &ddraw_surface7_vtbl; + surface->IDirectDrawSurface4_iface.lpVtbl = &ddraw_surface4_vtbl; + surface->IDirectDrawSurface3_iface.lpVtbl = &ddraw_surface3_vtbl; + surface->IDirectDrawSurface2_iface.lpVtbl = &ddraw_surface2_vtbl; + surface->IDirectDrawSurface_iface.lpVtbl = &ddraw_surface1_vtbl; + surface->IDirectDrawGammaControl_iface.lpVtbl = &ddraw_gamma_control_vtbl; + surface->IDirect3DTexture2_iface.lpVtbl = &d3d_texture2_vtbl; + surface->IDirect3DTexture_iface.lpVtbl = &d3d_texture1_vtbl; + surface->iface_count = 1; + surface->version = version; surface->ddraw = ddraw; + if (version == 7) + { + surface->ref7 = 1; + } + else if (version == 4) + { + surface->ref4 = 1; + } + else + { + surface->ref1 = 1; + } + copy_to_surfacedesc2(&surface->surface_desc, desc); surface->first_attached = surface; - surface->ImplType = surface_type; - hr = wined3d_surface_create(ddraw->wined3d_device, desc->dwWidth, desc->dwHeight, format, - TRUE /* Lockable */, FALSE /* Discard */, mip_level, usage, pool, - WINED3DMULTISAMPLE_NONE, 0 /* MultiSampleQuality */, surface_type, surface, - &ddraw_surface_wined3d_parent_ops, &surface->wined3d_surface); + hr = wined3d_surface_create(ddraw->wined3d_device, desc->dwWidth, desc->dwHeight, format, mip_level, + usage, pool, WINED3D_MULTISAMPLE_NONE, 0, DefaultSurfaceType, flags, + surface, &ddraw_surface_wined3d_parent_ops, &surface->wined3d_surface); if (FAILED(hr)) { WARN("Failed to create wined3d surface, hr %#x.\n", hr); return hr; } - surface->surface_desc.dwFlags |= DDSD_PIXELFORMAT; - wined3d_resource = wined3d_surface_get_resource(surface->wined3d_surface); - wined3d_resource_get_desc(wined3d_resource, &wined3d_desc); - - format = wined3d_desc.format; - if (format == WINED3DFMT_UNKNOWN) - { - FIXME("IWineD3DSurface::GetDesc returned WINED3DFMT_UNKNOWN.\n"); - } - PixelFormat_WineD3DtoDD(&surface->surface_desc.u4.ddpfPixelFormat, format); - /* Anno 1602 stores the pitch right after surface creation, so make sure * it's there. TODO: Test other fourcc formats. */ if (format == WINED3DFMT_DXT1 || format == WINED3DFMT_DXT2 || format == WINED3DFMT_DXT3 @@ -3599,11 +5573,11 @@ HRESULT ddraw_surface_init(IDirectDrawSurfaceImpl *surface, IDirectDrawImpl *ddr surface->surface_desc.dwFlags |= DDSD_LINEARSIZE; if (format == WINED3DFMT_DXT1) { - surface->surface_desc.u1.dwLinearSize = max(4, wined3d_desc.width) * max(4, wined3d_desc.height) / 2; + surface->surface_desc.u1.dwLinearSize = max(4, desc->dwWidth) * max(4, desc->dwHeight) / 2; } else { - surface->surface_desc.u1.dwLinearSize = max(4, wined3d_desc.width) * max(4, wined3d_desc.height); + surface->surface_desc.u1.dwLinearSize = max(4, desc->dwWidth) * max(4, desc->dwHeight); } } else @@ -3615,22 +5589,22 @@ HRESULT ddraw_surface_init(IDirectDrawSurfaceImpl *surface, IDirectDrawImpl *ddr if (desc->dwFlags & DDSD_CKDESTOVERLAY) { wined3d_surface_set_color_key(surface->wined3d_surface, DDCKEY_DESTOVERLAY, - (WINEDDCOLORKEY *)&desc->u3.ddckCKDestOverlay); + (struct wined3d_color_key *)&desc->u3.ddckCKDestOverlay); } if (desc->dwFlags & DDSD_CKDESTBLT) { wined3d_surface_set_color_key(surface->wined3d_surface, DDCKEY_DESTBLT, - (WINEDDCOLORKEY *)&desc->ddckCKDestBlt); + (struct wined3d_color_key *)&desc->ddckCKDestBlt); } if (desc->dwFlags & DDSD_CKSRCOVERLAY) { wined3d_surface_set_color_key(surface->wined3d_surface, DDCKEY_SRCOVERLAY, - (WINEDDCOLORKEY *)&desc->ddckCKSrcOverlay); + (struct wined3d_color_key *)&desc->ddckCKSrcOverlay); } if (desc->dwFlags & DDSD_CKSRCBLT) { wined3d_surface_set_color_key(surface->wined3d_surface, DDCKEY_SRCBLT, - (WINEDDCOLORKEY *)&desc->ddckCKSrcBlt); + (struct wined3d_color_key *)&desc->ddckCKSrcBlt); } if (desc->dwFlags & DDSD_LPSURFACE) { diff --git a/reactos/dll/directx/wine/ddraw/utils.c b/reactos/dll/directx/wine/ddraw/utils.c index 62e4b43ba90..15ce796cfb7 100644 --- a/reactos/dll/directx/wine/ddraw/utils.c +++ b/reactos/dll/directx/wine/ddraw/utils.c @@ -216,10 +216,9 @@ void PixelFormat_WineD3DtoDD(DDPIXELFORMAT *DDPixelFormat, enum wined3d_format_i case WINED3DFMT_D24_UNORM_S8_UINT: DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER; DDPixelFormat->dwFourCC = 0; - /* Should I set dwZBufferBitDepth to 32 here? */ DDPixelFormat->u1.dwZBufferBitDepth = 32; DDPixelFormat->u2.dwStencilBitDepth = 8; - DDPixelFormat->u3.dwZBitMask = 0x00FFFFFFFF; + DDPixelFormat->u3.dwZBitMask = 0x00FFFFFF; DDPixelFormat->u4.dwStencilBitMask = 0xFF000000; DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0; break; @@ -229,7 +228,7 @@ void PixelFormat_WineD3DtoDD(DDPIXELFORMAT *DDPixelFormat, enum wined3d_format_i DDPixelFormat->dwFourCC = 0; DDPixelFormat->u1.dwZBufferBitDepth = 32; DDPixelFormat->u2.dwStencilBitDepth = 0; - DDPixelFormat->u3.dwZBitMask = 0x00FFFFFFFF; + DDPixelFormat->u3.dwZBitMask = 0x00FFFFFF; DDPixelFormat->u4.dwStencilBitMask = 0x00000000; DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0; break; @@ -427,7 +426,7 @@ enum wined3d_format_id PixelFormat_DD2WineD3D(const DDPIXELFORMAT *DDPixelFormat { return WINED3DFMT_B2G3R3A8_UNORM; } - ERR("16 bit RGB Pixel format does not match\n"); + WARN("16 bit RGB Pixel format does not match.\n"); return WINED3DFMT_UNKNOWN; case 24: @@ -446,10 +445,10 @@ enum wined3d_format_id PixelFormat_DD2WineD3D(const DDPIXELFORMAT *DDPixelFormat return WINED3DFMT_B8G8R8X8_UNORM; } - ERR("32 bit RGB pixel format does not match\n"); + WARN("32 bit RGB pixel format does not match.\n"); default: - ERR("Invalid dwRGBBitCount in Pixelformat structure\n"); + WARN("Invalid dwRGBBitCount in Pixelformat structure.\n"); return WINED3DFMT_UNKNOWN; } } @@ -461,12 +460,12 @@ enum wined3d_format_id PixelFormat_DD2WineD3D(const DDPIXELFORMAT *DDPixelFormat case 1: case 2: case 4: - ERR("Unsupported Alpha-Only bit depth 0x%x\n", DDPixelFormat->u1.dwAlphaBitDepth); + FIXME("Unsupported Alpha-Only bit depth 0x%x.\n", DDPixelFormat->u1.dwAlphaBitDepth); case 8: return WINED3DFMT_A8_UNORM; default: - ERR("Invalid AlphaBitDepth in Alpha-Only Pixelformat\n"); + WARN("Invalid AlphaBitDepth in Alpha-Only Pixelformat.\n"); return WINED3DFMT_UNKNOWN; } } @@ -481,17 +480,17 @@ enum wined3d_format_id PixelFormat_DD2WineD3D(const DDPIXELFORMAT *DDPixelFormat case 4: if(DDPixelFormat->u1.dwAlphaBitDepth == 4) return WINED3DFMT_L4A4_UNORM; - ERR("Unknown Alpha / Luminance bit depth combination\n"); + WARN("Unknown Alpha / Luminance bit depth combination.\n"); return WINED3DFMT_UNKNOWN; case 6: - ERR("A luminance Pixelformat shouldn't have 6 luminance bits. Returning D3DFMT_L6V5U5 for now!!\n"); + FIXME("A luminance Pixelformat shouldn't have 6 luminance bits. Returning D3DFMT_L6V5U5 for now.\n"); return WINED3DFMT_R5G5_SNORM_L6_UNORM; case 8: if(DDPixelFormat->u1.dwAlphaBitDepth == 8) return WINED3DFMT_L8A8_UNORM; - ERR("Unknown Alpha / Lumincase bit depth combination\n"); + WARN("Unknown Alpha / Lumincase bit depth combination.\n"); return WINED3DFMT_UNKNOWN; } } @@ -501,14 +500,14 @@ enum wined3d_format_id PixelFormat_DD2WineD3D(const DDPIXELFORMAT *DDPixelFormat switch(DDPixelFormat->u1.dwLuminanceBitCount) { case 6: - ERR("A luminance Pixelformat shouldn't have 6 luminance bits. Returning D3DFMT_L6V5U5 for now!!\n"); + FIXME("A luminance Pixelformat shouldn't have 6 luminance bits. Returning D3DFMT_L6V5U5 for now.\n"); return WINED3DFMT_R5G5_SNORM_L6_UNORM; case 8: return WINED3DFMT_L8_UNORM; default: - ERR("Unknown luminance-only bit depth 0x%x\n", DDPixelFormat->u1.dwLuminanceBitCount); + WARN("Unknown luminance-only bit depth 0x%x.\n", DDPixelFormat->u1.dwLuminanceBitCount); return WINED3DFMT_UNKNOWN; } } @@ -520,31 +519,22 @@ enum wined3d_format_id PixelFormat_DD2WineD3D(const DDPIXELFORMAT *DDPixelFormat { switch(DDPixelFormat->u1.dwZBufferBitDepth) { - case 8: - FIXME("8 Bits Z+Stencil buffer pixelformat is not supported. Returning WINED3DFMT_UNKNOWN\n"); - return WINED3DFMT_UNKNOWN; - - case 15: - FIXME("15 bit depth buffer not handled yet, assuming 16 bit\n"); case 16: - if(DDPixelFormat->u2.dwStencilBitDepth == 1) - return WINED3DFMT_S1_UINT_D15_UNORM; - - FIXME("Don't know how to handle a 16 bit Z buffer with %d bit stencil buffer pixelformat\n", DDPixelFormat->u2.dwStencilBitDepth); + if (DDPixelFormat->u2.dwStencilBitDepth == 1) return WINED3DFMT_S1_UINT_D15_UNORM; + WARN("Unknown depth stenil format: 16 z bits, %u stencil bits\n", + DDPixelFormat->u2.dwStencilBitDepth); return WINED3DFMT_UNKNOWN; - case 24: - FIXME("Don't know how to handle a 24 bit depth buffer with stencil bits\n"); - return WINED3DFMT_D24_UNORM_S8_UINT; - case 32: - if(DDPixelFormat->u2.dwStencilBitDepth == 8) - return WINED3DFMT_D24_UNORM_S8_UINT; - else - return WINED3DFMT_S4X4_UINT_D24_UNORM; + if (DDPixelFormat->u2.dwStencilBitDepth == 8) return WINED3DFMT_D24_UNORM_S8_UINT; + else if (DDPixelFormat->u2.dwStencilBitDepth == 4) return WINED3DFMT_S4X4_UINT_D24_UNORM; + WARN("Unknown depth stenil format: 32 z bits, %u stencil bits\n", + DDPixelFormat->u2.dwStencilBitDepth); + return WINED3DFMT_UNKNOWN; default: - ERR("Unknown Z buffer depth %d\n", DDPixelFormat->u1.dwZBufferBitDepth); + WARN("Unknown depth stenil format: %u z bits, %u stencil bits\n", + DDPixelFormat->u1.dwZBufferBitDepth, DDPixelFormat->u2.dwStencilBitDepth); return WINED3DFMT_UNKNOWN; } } @@ -552,26 +542,23 @@ enum wined3d_format_id PixelFormat_DD2WineD3D(const DDPIXELFORMAT *DDPixelFormat { switch(DDPixelFormat->u1.dwZBufferBitDepth) { - case 8: - ERR("8 Bit Z buffers are not supported. Trying a 16 Bit one\n"); - return WINED3DFMT_D16_UNORM; - case 16: return WINED3DFMT_D16_UNORM; case 24: - FIXME("24 Bit depth buffer, treating like a 32 bit one\n"); + return WINED3DFMT_X8D24_UNORM; + case 32: - if(DDPixelFormat->u3.dwZBitMask == 0x00FFFFFF) { - return WINED3DFMT_X8D24_UNORM; - } else if(DDPixelFormat->u3.dwZBitMask == 0xFFFFFFFF) { - return WINED3DFMT_D32_UNORM; - } - FIXME("Unhandled 32 bit depth buffer bitmasks, returning WINED3DFMT_D24X8\n"); - return WINED3DFMT_X8D24_UNORM; /* That's most likely to make games happy */ + if (DDPixelFormat->u3.dwZBitMask == 0x00FFFFFF) return WINED3DFMT_X8D24_UNORM; + else if (DDPixelFormat->u3.dwZBitMask == 0xFFFFFF00) return WINED3DFMT_X8D24_UNORM; + else if (DDPixelFormat->u3.dwZBitMask == 0xFFFFFFFF) return WINED3DFMT_D32_UNORM; + WARN("Unknown depth-only format: 32 z bits, mask 0x%08x\n", + DDPixelFormat->u3.dwZBitMask); + return WINED3DFMT_UNKNOWN; default: - ERR("Unsupported Z buffer depth %d\n", DDPixelFormat->u1.dwZBufferBitDepth); + WARN("Unknown depth-only format: %u z bits, mask 0x%08x\n", + DDPixelFormat->u1.dwZBufferBitDepth, DDPixelFormat->u3.dwZBitMask); return WINED3DFMT_UNKNOWN; } } @@ -612,7 +599,7 @@ enum wined3d_format_id PixelFormat_DD2WineD3D(const DDPIXELFORMAT *DDPixelFormat } } - ERR("Unknown Pixelformat!\n"); + WARN("Unknown Pixelformat.\n"); return WINED3DFMT_UNKNOWN; } @@ -1181,3 +1168,93 @@ hr_ddraw_from_wined3d(HRESULT hr) default: return hr; } } + +/* Note that this function writes the full sizeof(DDSURFACEDESC2) size, don't use it + * for writing into application-provided DDSURFACEDESC2 structures if the size may + * be different */ +void DDSD_to_DDSD2(const DDSURFACEDESC *in, DDSURFACEDESC2 *out) +{ + /* The output of this function is never passed to the application directly, so + * the memset is not strictly needed. CreateSurface still has problems with this + * though. Don't forget to set ddsCaps.dwCaps2/3/4 to 0 when removing this */ + memset(out, 0x00, sizeof(*out)); + out->dwSize = sizeof(*out); + out->dwFlags = in->dwFlags & ~DDSD_ZBUFFERBITDEPTH; + if (in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth; + if (in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight; + if (in->dwFlags & DDSD_PIXELFORMAT) out->u4.ddpfPixelFormat = in->ddpfPixelFormat; + else if(in->dwFlags & DDSD_ZBUFFERBITDEPTH) + { + out->dwFlags |= DDSD_PIXELFORMAT; + memset(&out->u4.ddpfPixelFormat, 0, sizeof(out->u4.ddpfPixelFormat)); + out->u4.ddpfPixelFormat.dwSize = sizeof(out->u4.ddpfPixelFormat); + out->u4.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER; + out->u4.ddpfPixelFormat.u1.dwZBufferBitDepth = in->u2.dwZBufferBitDepth; + /* 0 is not a valid DDSURFACEDESC / DDPIXELFORMAT on either side of the + * conversion */ + out->u4.ddpfPixelFormat.u3.dwZBitMask = ~0U >> (32 - in->u2.dwZBufferBitDepth); + } + /* ddsCaps is read even without DDSD_CAPS set. See dsurface:no_ddsd_caps_test */ + out->ddsCaps.dwCaps = in->ddsCaps.dwCaps; + if (in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch; + if (in->dwFlags & DDSD_BACKBUFFERCOUNT) out->u5.dwBackBufferCount = in->dwBackBufferCount; + if (in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth; + /* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */ + out->lpSurface = in->lpSurface; + if (in->dwFlags & DDSD_CKDESTOVERLAY) out->u3.ddckCKDestOverlay = in->ddckCKDestOverlay; + if (in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt; + if (in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay; + if (in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt; + if (in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount; + if (in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate; + if (in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize; + /* Does not exist in DDSURFACEDESC: + * DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE, + */ +} + +/* Note that this function writes the full sizeof(DDSURFACEDESC) size, don't use it + * for writing into application-provided DDSURFACEDESC structures if the size may + * be different */ +void DDSD2_to_DDSD(const DDSURFACEDESC2 *in, DDSURFACEDESC *out) +{ + memset(out, 0, sizeof(*out)); + out->dwSize = sizeof(*out); + out->dwFlags = in->dwFlags; + if (in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth; + if (in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight; + if (in->dwFlags & DDSD_PIXELFORMAT) + { + out->ddpfPixelFormat = in->u4.ddpfPixelFormat; + if ((in->dwFlags & DDSD_CAPS) && (in->ddsCaps.dwCaps & DDSCAPS_ZBUFFER)) + { + /* Z buffers have DDSD_ZBUFFERBITDEPTH set, but not DDSD_PIXELFORMAT. They do + * have valid data in ddpfPixelFormat though */ + out->dwFlags &= ~DDSD_PIXELFORMAT; + out->dwFlags |= DDSD_ZBUFFERBITDEPTH; + out->u2.dwZBufferBitDepth = in->u4.ddpfPixelFormat.u1.dwZBufferBitDepth; + } + } + /* ddsCaps is read even without DDSD_CAPS set. See dsurface:no_ddsd_caps_test */ + out->ddsCaps.dwCaps = in->ddsCaps.dwCaps; + if (in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch; + if (in->dwFlags & DDSD_BACKBUFFERCOUNT) out->dwBackBufferCount = in->u5.dwBackBufferCount; + if (in->dwFlags & DDSD_ZBUFFERBITDEPTH) out->u2.dwZBufferBitDepth = in->u2.dwMipMapCount; /* same union */ + if (in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth; + /* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */ + out->lpSurface = in->lpSurface; + if (in->dwFlags & DDSD_CKDESTOVERLAY) out->ddckCKDestOverlay = in->u3.ddckCKDestOverlay; + if (in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt; + if (in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay; + if (in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt; + if (in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount; + if (in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate; + if (in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize; + /* Does not exist in DDSURFACEDESC: + * DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE, + */ + if (in->dwFlags & DDSD_TEXTURESTAGE) WARN("Does not exist in DDSURFACEDESC: DDSD_TEXTURESTAGE\n"); + if (in->dwFlags & DDSD_FVF) WARN("Does not exist in DDSURFACEDESC: DDSD_FVF\n"); + if (in->dwFlags & DDSD_SRCVBHANDLE) WARN("Does not exist in DDSURFACEDESC: DDSD_SRCVBHANDLE\n"); + out->dwFlags &= ~(DDSD_TEXTURESTAGE | DDSD_FVF | DDSD_SRCVBHANDLE); +} diff --git a/reactos/dll/directx/wine/ddraw/vertexbuffer.c b/reactos/dll/directx/wine/ddraw/vertexbuffer.c index af4e8bcab84..fe39e0104bb 100644 --- a/reactos/dll/directx/wine/ddraw/vertexbuffer.c +++ b/reactos/dll/directx/wine/ddraw/vertexbuffer.c @@ -26,6 +26,16 @@ WINE_DEFAULT_DEBUG_CHANNEL(ddraw); +static inline IDirect3DVertexBufferImpl *impl_from_IDirect3DVertexBuffer(IDirect3DVertexBuffer *iface) +{ + return CONTAINING_RECORD(iface, IDirect3DVertexBufferImpl, IDirect3DVertexBuffer_iface); +} + +static inline IDirect3DVertexBufferImpl *impl_from_IDirect3DVertexBuffer7(IDirect3DVertexBuffer7 *iface) +{ + return CONTAINING_RECORD(iface, IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7_iface); +} + /***************************************************************************** * IUnknown Methods *****************************************************************************/ @@ -37,7 +47,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(ddraw); * For a link to QueryInterface rules, see IDirectDraw7::QueryInterface * * Params - * riid: Queryied Interface id + * riid: Queried Interface id * obj: Address to return the interface pointer * * Returns: @@ -45,12 +55,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(ddraw); * E_NOINTERFACE if the interface wasn't found * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DVertexBufferImpl_QueryInterface(IDirect3DVertexBuffer7 *iface, - REFIID riid, - void **obj) +static HRESULT WINAPI IDirect3DVertexBufferImpl_QueryInterface(IDirect3DVertexBuffer7 *iface, + REFIID riid, void **obj) { - IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface; + IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer7(iface); TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj); @@ -67,7 +75,7 @@ IDirect3DVertexBufferImpl_QueryInterface(IDirect3DVertexBuffer7 *iface, if ( IsEqualGUID( &IID_IDirect3DVertexBuffer, riid ) ) { IUnknown_AddRef(iface); - *obj = &This->IDirect3DVertexBuffer_vtbl; + *obj = &This->IDirect3DVertexBuffer_iface; TRACE(" Creating IDirect3DVertexBuffer interface %p\n", *obj); return S_OK; } @@ -85,9 +93,11 @@ IDirect3DVertexBufferImpl_QueryInterface(IDirect3DVertexBuffer7 *iface, static HRESULT WINAPI IDirect3DVertexBufferImpl_1_QueryInterface(IDirect3DVertexBuffer *iface, REFIID riid, void **obj) { + IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer(iface); + TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj); - return IDirect3DVertexBuffer7_QueryInterface((IDirect3DVertexBuffer7 *)vb_from_vb1(iface), riid, obj); + return IDirect3DVertexBuffer7_QueryInterface(&This->IDirect3DVertexBuffer7_iface, riid, obj); } /***************************************************************************** @@ -99,10 +109,9 @@ static HRESULT WINAPI IDirect3DVertexBufferImpl_1_QueryInterface(IDirect3DVertex * The new refcount * *****************************************************************************/ -static ULONG WINAPI -IDirect3DVertexBufferImpl_AddRef(IDirect3DVertexBuffer7 *iface) +static ULONG WINAPI IDirect3DVertexBufferImpl_AddRef(IDirect3DVertexBuffer7 *iface) { - IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface; + IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer7(iface); ULONG ref = InterlockedIncrement(&This->ref); TRACE("%p increasing refcount to %u.\n", This, ref); @@ -112,9 +121,11 @@ IDirect3DVertexBufferImpl_AddRef(IDirect3DVertexBuffer7 *iface) static ULONG WINAPI IDirect3DVertexBufferImpl_1_AddRef(IDirect3DVertexBuffer *iface) { + IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer(iface); + TRACE("iface %p.\n", iface); - return IDirect3DVertexBuffer7_AddRef((IDirect3DVertexBuffer7 *)vb_from_vb1(iface)); + return IDirect3DVertexBuffer7_AddRef(&This->IDirect3DVertexBuffer7_iface); } @@ -127,10 +138,9 @@ static ULONG WINAPI IDirect3DVertexBufferImpl_1_AddRef(IDirect3DVertexBuffer *if * The new refcount * *****************************************************************************/ -static ULONG WINAPI -IDirect3DVertexBufferImpl_Release(IDirect3DVertexBuffer7 *iface) +static ULONG WINAPI IDirect3DVertexBufferImpl_Release(IDirect3DVertexBuffer7 *iface) { - IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface; + IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer7(iface); ULONG ref = InterlockedDecrement(&This->ref); TRACE("%p decreasing refcount to %u.\n", This, ref); @@ -140,11 +150,11 @@ IDirect3DVertexBufferImpl_Release(IDirect3DVertexBuffer7 *iface) struct wined3d_buffer *curVB = NULL; UINT offset, stride; - EnterCriticalSection(&ddraw_cs); /* D3D7 Vertex buffers don't stay bound in the device, they are passed * as a parameter to drawPrimitiveVB. DrawPrimitiveVB sets them as the * stream source in wined3d, and they should get unset there before * they are destroyed. */ + wined3d_mutex_lock(); wined3d_device_get_stream_source(This->ddraw->wined3d_device, 0, &curVB, &offset, &stride); if (curVB == This->wineD3DVertexBuffer) @@ -154,7 +164,8 @@ IDirect3DVertexBufferImpl_Release(IDirect3DVertexBuffer7 *iface) wined3d_vertex_declaration_decref(This->wineD3DVertexDeclaration); wined3d_buffer_decref(This->wineD3DVertexBuffer); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + HeapFree(GetProcessHeap(), 0, This); return 0; @@ -164,9 +175,11 @@ IDirect3DVertexBufferImpl_Release(IDirect3DVertexBuffer7 *iface) static ULONG WINAPI IDirect3DVertexBufferImpl_1_Release(IDirect3DVertexBuffer *iface) { + IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer(iface); + TRACE("iface %p.\n", iface); - return IDirect3DVertexBuffer7_Release((IDirect3DVertexBuffer7 *)vb_from_vb1(iface)); + return IDirect3DVertexBuffer7_Release(&This->IDirect3DVertexBuffer7_iface); } /***************************************************************************** @@ -192,13 +205,10 @@ static ULONG WINAPI IDirect3DVertexBufferImpl_1_Release(IDirect3DVertexBuffer *i * D3DERR_VERTEXBUFFEROPTIMIZED if called on an optimized buffer(WineD3D) * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DVertexBufferImpl_Lock(IDirect3DVertexBuffer7 *iface, - DWORD Flags, - void **Data, - DWORD *Size) +static HRESULT WINAPI IDirect3DVertexBufferImpl_Lock(IDirect3DVertexBuffer7 *iface, DWORD Flags, + void **Data, DWORD *Size) { - IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface; + IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer7(iface); struct wined3d_resource_desc wined3d_desc; struct wined3d_resource *wined3d_resource; HRESULT hr; @@ -214,7 +224,7 @@ IDirect3DVertexBufferImpl_Lock(IDirect3DVertexBuffer7 *iface, if(Flags & DDLOCK_NOOVERWRITE) wined3d_flags |= WINED3DLOCK_NOOVERWRITE; if(Flags & DDLOCK_DISCARDCONTENTS) wined3d_flags |= WINED3DLOCK_DISCARD; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if(Size) { /* Get the size, for returning it, and for locking */ @@ -224,16 +234,19 @@ IDirect3DVertexBufferImpl_Lock(IDirect3DVertexBuffer7 *iface, } hr = wined3d_buffer_map(This->wineD3DVertexBuffer, 0, 0, (BYTE **)Data, wined3d_flags); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } static HRESULT WINAPI IDirect3DVertexBufferImpl_1_Lock(IDirect3DVertexBuffer *iface, DWORD Flags, void **Data, DWORD *Size) { + IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer(iface); + TRACE("iface %p, flags %#x, data %p, data_size %p.\n", iface, Flags, Data, Size); - return IDirect3DVertexBuffer7_Lock((IDirect3DVertexBuffer7 *)vb_from_vb1(iface), Flags, Data, Size); + return IDirect3DVertexBuffer7_Lock(&This->IDirect3DVertexBuffer7_iface, Flags, Data, Size); } /***************************************************************************** @@ -245,25 +258,26 @@ static HRESULT WINAPI IDirect3DVertexBufferImpl_1_Lock(IDirect3DVertexBuffer *if * D3D_OK on success * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DVertexBufferImpl_Unlock(IDirect3DVertexBuffer7 *iface) +static HRESULT WINAPI IDirect3DVertexBufferImpl_Unlock(IDirect3DVertexBuffer7 *iface) { - IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface; + IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer7(iface); TRACE("iface %p.\n", iface); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); wined3d_buffer_unmap(This->wineD3DVertexBuffer); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } static HRESULT WINAPI IDirect3DVertexBufferImpl_1_Unlock(IDirect3DVertexBuffer *iface) { + IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer(iface); + TRACE("iface %p.\n", iface); - return IDirect3DVertexBuffer7_Unlock((IDirect3DVertexBuffer7 *)vb_from_vb1(iface)); + return IDirect3DVertexBuffer7_Unlock(&This->IDirect3DVertexBuffer7_iface); } @@ -289,24 +303,18 @@ static HRESULT WINAPI IDirect3DVertexBufferImpl_1_Unlock(IDirect3DVertexBuffer * * DDERR_INVALIDPARAMS If D3DVOP_TRANSFORM wasn't passed * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DVertexBufferImpl_ProcessVertices(IDirect3DVertexBuffer7 *iface, - DWORD VertexOp, - DWORD DestIndex, - DWORD Count, - IDirect3DVertexBuffer7 *SrcBuffer, - DWORD SrcIndex, - IDirect3DDevice7 *D3DDevice, - DWORD Flags) +static HRESULT WINAPI IDirect3DVertexBufferImpl_ProcessVertices(IDirect3DVertexBuffer7 *iface, + DWORD VertexOp, DWORD DestIndex, DWORD Count, IDirect3DVertexBuffer7 *SrcBuffer, + DWORD SrcIndex, IDirect3DDevice7 *device, DWORD Flags) { - IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface; - IDirect3DVertexBufferImpl *Src = (IDirect3DVertexBufferImpl *)SrcBuffer; - IDirect3DDeviceImpl *D3D = (IDirect3DDeviceImpl *)D3DDevice; + IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer7(iface); + IDirect3DVertexBufferImpl *Src = unsafe_impl_from_IDirect3DVertexBuffer7(SrcBuffer); + IDirect3DDeviceImpl *device_impl = unsafe_impl_from_IDirect3DDevice7(device); BOOL oldClip, doClip; HRESULT hr; TRACE("iface %p, vertex_op %#x, dst_idx %u, count %u, src_buffer %p, src_idx %u, device %p, flags %#x.\n", - iface, VertexOp, DestIndex, Count, SrcBuffer, SrcIndex, D3DDevice, Flags); + iface, VertexOp, DestIndex, Count, SrcBuffer, SrcIndex, device, Flags); /* Vertex operations: * D3DVOP_CLIP: Clips vertices outside the viewing frustrum. Needs clipping information @@ -320,41 +328,46 @@ IDirect3DVertexBufferImpl_ProcessVertices(IDirect3DVertexBuffer7 *iface, */ if( !(VertexOp & D3DVOP_TRANSFORM) ) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); + /* WineD3D doesn't know d3d7 vertex operation, it uses * render states instead. Set the render states according to * the vertex ops */ doClip = VertexOp & D3DVOP_CLIP ? TRUE : FALSE; - wined3d_device_get_render_state(D3D->wined3d_device, WINED3DRS_CLIPPING, (DWORD *)&oldClip); + wined3d_device_get_render_state(device_impl->wined3d_device, WINED3D_RS_CLIPPING, (DWORD *)&oldClip); if (doClip != oldClip) - wined3d_device_set_render_state(D3D->wined3d_device, WINED3DRS_CLIPPING, doClip); + wined3d_device_set_render_state(device_impl->wined3d_device, WINED3D_RS_CLIPPING, doClip); - wined3d_device_set_stream_source(D3D->wined3d_device, + wined3d_device_set_stream_source(device_impl->wined3d_device, 0, Src->wineD3DVertexBuffer, 0, get_flexible_vertex_size(Src->fvf)); - wined3d_device_set_vertex_declaration(D3D->wined3d_device, Src->wineD3DVertexDeclaration); - hr = wined3d_device_process_vertices(D3D->wined3d_device, SrcIndex, DestIndex, + wined3d_device_set_vertex_declaration(device_impl->wined3d_device, Src->wineD3DVertexDeclaration); + hr = wined3d_device_process_vertices(device_impl->wined3d_device, SrcIndex, DestIndex, Count, This->wineD3DVertexBuffer, NULL, Flags, This->fvf); /* Restore the states if needed */ if (doClip != oldClip) - wined3d_device_set_render_state(D3D->wined3d_device, WINED3DRS_CLIPPING, oldClip); - LeaveCriticalSection(&ddraw_cs); + wined3d_device_set_render_state(device_impl->wined3d_device, WINED3D_RS_CLIPPING, oldClip); + + wined3d_mutex_unlock(); + return hr; } static HRESULT WINAPI IDirect3DVertexBufferImpl_1_ProcessVertices(IDirect3DVertexBuffer *iface, DWORD VertexOp, DWORD DestIndex, DWORD Count, IDirect3DVertexBuffer *SrcBuffer, - DWORD SrcIndex, IDirect3DDevice3 *D3DDevice, DWORD Flags) + DWORD SrcIndex, IDirect3DDevice3 *device, DWORD Flags) { - IDirect3DVertexBufferImpl *Src = SrcBuffer ? vb_from_vb1(SrcBuffer) : NULL; - IDirect3DDeviceImpl *D3D = D3DDevice ? device_from_device3(D3DDevice) : NULL; + IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer(iface); + IDirect3DVertexBufferImpl *Src = unsafe_impl_from_IDirect3DVertexBuffer(SrcBuffer); + IDirect3DDeviceImpl *device_impl = unsafe_impl_from_IDirect3DDevice3(device); TRACE("iface %p, vertex_op %#x, dst_idx %u, count %u, src_buffer %p, src_idx %u, device %p, flags %#x.\n", - iface, VertexOp, DestIndex, Count, SrcBuffer, SrcIndex, D3DDevice, Flags); + iface, VertexOp, DestIndex, Count, SrcBuffer, SrcIndex, device, Flags); - return IDirect3DVertexBuffer7_ProcessVertices((IDirect3DVertexBuffer7 *)vb_from_vb1(iface), VertexOp, - DestIndex, Count, (IDirect3DVertexBuffer7 *)Src, SrcIndex, (IDirect3DDevice7 *)D3D, Flags); + return IDirect3DVertexBuffer7_ProcessVertices(&This->IDirect3DVertexBuffer7_iface, VertexOp, + DestIndex, Count, &Src->IDirect3DVertexBuffer7_iface, SrcIndex, + device_impl ? &device_impl->IDirect3DDevice7_iface : NULL, Flags); } /***************************************************************************** @@ -370,11 +383,10 @@ static HRESULT WINAPI IDirect3DVertexBufferImpl_1_ProcessVertices(IDirect3DVerte * D3D_OK on success * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DVertexBufferImpl_GetVertexBufferDesc(IDirect3DVertexBuffer7 *iface, - D3DVERTEXBUFFERDESC *Desc) +static HRESULT WINAPI IDirect3DVertexBufferImpl_GetVertexBufferDesc(IDirect3DVertexBuffer7 *iface, + D3DVERTEXBUFFERDESC *Desc) { - IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface; + IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer7(iface); struct wined3d_resource_desc wined3d_desc; struct wined3d_resource *wined3d_resource; @@ -382,10 +394,10 @@ IDirect3DVertexBufferImpl_GetVertexBufferDesc(IDirect3DVertexBuffer7 *iface, if(!Desc) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); wined3d_resource = wined3d_buffer_get_resource(This->wineD3DVertexBuffer); wined3d_resource_get_desc(wined3d_resource, &wined3d_desc); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); /* Now fill the Desc structure */ Desc->dwCaps = This->Caps; @@ -398,9 +410,11 @@ IDirect3DVertexBufferImpl_GetVertexBufferDesc(IDirect3DVertexBuffer7 *iface, static HRESULT WINAPI IDirect3DVertexBufferImpl_1_GetVertexBufferDesc(IDirect3DVertexBuffer *iface, D3DVERTEXBUFFERDESC *Desc) { + IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer(iface); + TRACE("iface %p, desc %p.\n", iface, Desc); - return IDirect3DVertexBuffer7_GetVertexBufferDesc((IDirect3DVertexBuffer7 *)vb_from_vb1(iface), Desc); + return IDirect3DVertexBuffer7_GetVertexBufferDesc(&This->IDirect3DVertexBuffer7_iface, Desc); } @@ -417,12 +431,10 @@ static HRESULT WINAPI IDirect3DVertexBufferImpl_1_GetVertexBufferDesc(IDirect3DV * D3D_OK, because it's a stub * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DVertexBufferImpl_Optimize(IDirect3DVertexBuffer7 *iface, - IDirect3DDevice7 *D3DDevice, - DWORD Flags) +static HRESULT WINAPI IDirect3DVertexBufferImpl_Optimize(IDirect3DVertexBuffer7 *iface, + IDirect3DDevice7 *D3DDevice, DWORD Flags) { - IDirect3DVertexBufferImpl *This = (IDirect3DVertexBufferImpl *)iface; + IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer7(iface); static BOOL hide = FALSE; TRACE("iface %p, device %p, flags %#x.\n", iface, D3DDevice, Flags); @@ -436,22 +448,23 @@ IDirect3DVertexBufferImpl_Optimize(IDirect3DVertexBuffer7 *iface, /* We could forward this call to WineD3D and take advantage * of it once we use OpenGL vertex buffers */ - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); This->Caps |= D3DVBCAPS_OPTIMIZED; - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DD_OK; } static HRESULT WINAPI IDirect3DVertexBufferImpl_1_Optimize(IDirect3DVertexBuffer *iface, - IDirect3DDevice3 *D3DDevice, DWORD Flags) + IDirect3DDevice3 *device, DWORD Flags) { - IDirect3DDeviceImpl *D3D = D3DDevice ? device_from_device3(D3DDevice) : NULL; + IDirect3DVertexBufferImpl *This = impl_from_IDirect3DVertexBuffer(iface); + IDirect3DDeviceImpl *device_impl = unsafe_impl_from_IDirect3DDevice3(device); - TRACE("iface %p, device %p, flags %#x.\n", iface, D3DDevice, Flags); + TRACE("iface %p, device %p, flags %#x.\n", iface, device, Flags); - return IDirect3DVertexBuffer7_Optimize((IDirect3DVertexBuffer7 *)vb_from_vb1(iface), - (IDirect3DDevice7 *)D3D, Flags); + return IDirect3DVertexBuffer7_Optimize(&This->IDirect3DVertexBuffer7_iface, + device_impl ? &device_impl->IDirect3DDevice7_iface : NULL, Flags); } /***************************************************************************** @@ -526,14 +539,25 @@ static const struct IDirect3DVertexBufferVtbl d3d_vertex_buffer1_vtbl = IDirect3DVertexBufferImpl_1_Optimize }; -HRESULT d3d_vertex_buffer_init(IDirect3DVertexBufferImpl *buffer, - IDirectDrawImpl *ddraw, D3DVERTEXBUFFERDESC *desc) +HRESULT d3d_vertex_buffer_create(IDirect3DVertexBufferImpl **vertex_buf, IDirectDrawImpl *ddraw, + D3DVERTEXBUFFERDESC *desc) { + IDirect3DVertexBufferImpl *buffer; DWORD usage; - HRESULT hr; + HRESULT hr = D3D_OK; - buffer->lpVtbl = &d3d_vertex_buffer7_vtbl; - buffer->IDirect3DVertexBuffer_vtbl = &d3d_vertex_buffer1_vtbl; + TRACE("Vertex buffer description:\n"); + TRACE(" dwSize %u\n", desc->dwSize); + TRACE(" dwCaps %#x\n", desc->dwCaps); + TRACE(" FVF %#x\n", desc->dwFVF); + TRACE(" dwNumVertices %u\n", desc->dwNumVertices); + + buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*buffer)); + if (!buffer) + return DDERR_OUTOFMEMORY; + + buffer->IDirect3DVertexBuffer7_iface.lpVtbl = &d3d_vertex_buffer7_vtbl; + buffer->IDirect3DVertexBuffer_iface.lpVtbl = &d3d_vertex_buffer1_vtbl; buffer->ref = 1; buffer->ddraw = ddraw; @@ -543,21 +567,18 @@ HRESULT d3d_vertex_buffer_init(IDirect3DVertexBufferImpl *buffer, usage = desc->dwCaps & D3DVBCAPS_WRITEONLY ? WINED3DUSAGE_WRITEONLY : 0; usage |= WINED3DUSAGE_STATICDECL; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); hr = wined3d_buffer_create_vb(ddraw->wined3d_device, get_flexible_vertex_size(desc->dwFVF) * desc->dwNumVertices, - usage, desc->dwCaps & D3DVBCAPS_SYSTEMMEMORY ? WINED3DPOOL_SYSTEMMEM : WINED3DPOOL_DEFAULT, + usage, desc->dwCaps & D3DVBCAPS_SYSTEMMEMORY ? WINED3D_POOL_SYSTEM_MEM : WINED3D_POOL_DEFAULT, buffer, &ddraw_null_wined3d_parent_ops, &buffer->wineD3DVertexBuffer); if (FAILED(hr)) { WARN("Failed to create wined3d vertex buffer, hr %#x.\n", hr); - LeaveCriticalSection(&ddraw_cs); - if (hr == WINED3DERR_INVALIDCALL) - return DDERR_INVALIDPARAMS; - else - return hr; + hr = DDERR_INVALIDPARAMS; + goto end; } buffer->wineD3DVertexDeclaration = ddraw_find_decl(ddraw, desc->dwFVF); @@ -565,13 +586,35 @@ HRESULT d3d_vertex_buffer_init(IDirect3DVertexBufferImpl *buffer, { ERR("Failed to find vertex declaration for fvf %#x.\n", desc->dwFVF); wined3d_buffer_decref(buffer->wineD3DVertexBuffer); - LeaveCriticalSection(&ddraw_cs); - - return DDERR_INVALIDPARAMS; + hr = DDERR_INVALIDPARAMS; + goto end; } wined3d_vertex_declaration_incref(buffer->wineD3DVertexDeclaration); - LeaveCriticalSection(&ddraw_cs); +end: + wined3d_mutex_unlock(); + if (hr == D3D_OK) + *vertex_buf = buffer; + else + HeapFree(GetProcessHeap(), 0, buffer); - return D3D_OK; + return hr; +} + +IDirect3DVertexBufferImpl *unsafe_impl_from_IDirect3DVertexBuffer(IDirect3DVertexBuffer *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &d3d_vertex_buffer1_vtbl); + + return impl_from_IDirect3DVertexBuffer(iface); +} + +IDirect3DVertexBufferImpl *unsafe_impl_from_IDirect3DVertexBuffer7(IDirect3DVertexBuffer7 *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &d3d_vertex_buffer7_vtbl); + + return impl_from_IDirect3DVertexBuffer7(iface); } diff --git a/reactos/dll/directx/wine/ddraw/viewport.c b/reactos/dll/directx/wine/ddraw/viewport.c index 08af7e2380f..1523ac6a743 100644 --- a/reactos/dll/directx/wine/ddraw/viewport.c +++ b/reactos/dll/directx/wine/ddraw/viewport.c @@ -30,6 +30,26 @@ WINE_DEFAULT_DEBUG_CHANNEL(ddraw); * Helper functions *****************************************************************************/ +static void update_clip_space(IDirect3DDeviceImpl *device, + struct wined3d_vec3 *scale, struct wined3d_vec3 *offset) +{ + D3DMATRIX clip_space = + { + scale->x, 0.0f, 0.0f, 0.0f, + 0.0f, scale->y, 0.0f, 0.0f, + 0.0f, 0.0f, scale->z, 0.0f, + offset->x, offset->y, offset->z, 1.0f, + }; + D3DMATRIX projection; + HRESULT hr; + + multiply_matrix(&projection, &clip_space, &device->legacy_projection); + hr = wined3d_device_set_transform(device->wined3d_device, + WINED3D_TS_PROJECTION, (struct wined3d_matrix *)&projection); + if (SUCCEEDED(hr)) + device->legacy_clipspace = clip_space; +} + /***************************************************************************** * viewport_activate * @@ -38,6 +58,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(ddraw); *****************************************************************************/ void viewport_activate(IDirect3DViewportImpl *This, BOOL ignore_lights) { + struct wined3d_vec3 scale, offset; D3DVIEWPORT7 vp; if (!ignore_lights) @@ -58,8 +79,15 @@ void viewport_activate(IDirect3DViewportImpl *This, BOOL ignore_lights) vp.dwY = This->viewports.vp2.dwY; vp.dwHeight = This->viewports.vp2.dwHeight; vp.dwWidth = This->viewports.vp2.dwWidth; - vp.dvMinZ = This->viewports.vp2.dvMinZ; - vp.dvMaxZ = This->viewports.vp2.dvMaxZ; + vp.dvMinZ = 0.0f; + vp.dvMaxZ = 1.0f; + + scale.x = 2.0f / This->viewports.vp2.dvClipWidth; + scale.y = 2.0f / This->viewports.vp2.dvClipHeight; + scale.z = 1.0f / (This->viewports.vp2.dvMaxZ - This->viewports.vp2.dvMinZ); + offset.x = -2.0f * This->viewports.vp2.dvClipX / This->viewports.vp2.dvClipWidth - 1.0f; + offset.y = -2.0f * This->viewports.vp2.dvClipY / This->viewports.vp2.dvClipHeight + 1.0f; + offset.z = -This->viewports.vp2.dvMinZ / (This->viewports.vp2.dvMaxZ - This->viewports.vp2.dvMinZ); } else { @@ -67,12 +95,19 @@ void viewport_activate(IDirect3DViewportImpl *This, BOOL ignore_lights) vp.dwY = This->viewports.vp1.dwY; vp.dwHeight = This->viewports.vp1.dwHeight; vp.dwWidth = This->viewports.vp1.dwWidth; - vp.dvMinZ = This->viewports.vp1.dvMinZ; - vp.dvMaxZ = This->viewports.vp1.dvMaxZ; + vp.dvMinZ = 0.0f; + vp.dvMaxZ = 1.0f; + + scale.x = 2.0f * This->viewports.vp1.dvScaleX / This->viewports.vp1.dwWidth; + scale.y = 2.0f * This->viewports.vp1.dvScaleY / This->viewports.vp1.dwHeight; + scale.z = 1.0f; + offset.x = 0.0f; + offset.y = 0.0f; + offset.z = 0.0f; } - /* And also set the viewport */ - IDirect3DDevice7_SetViewport((IDirect3DDevice7 *)This->active_device, &vp); + update_clip_space(This->active_device, &scale, &offset); + IDirect3DDevice7_SetViewport(&This->active_device->IDirect3DDevice7_iface, &vp); } /***************************************************************************** @@ -109,6 +144,11 @@ static void _dump_D3DVIEWPORT2(const D3DVIEWPORT2 *lpvp) lpvp->dvMinZ, lpvp->dvMaxZ); } +static inline IDirect3DViewportImpl *impl_from_IDirect3DViewport3(IDirect3DViewport3 *iface) +{ + return CONTAINING_RECORD(iface, IDirect3DViewportImpl, IDirect3DViewport3_iface); +} + /***************************************************************************** * IUnknown Methods. *****************************************************************************/ @@ -161,7 +201,7 @@ static HRESULT WINAPI IDirect3DViewportImpl_QueryInterface(IDirect3DViewport3 *i static ULONG WINAPI IDirect3DViewportImpl_AddRef(IDirect3DViewport3 *iface) { - IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface; + IDirect3DViewportImpl *This = impl_from_IDirect3DViewport3(iface); ULONG ref = InterlockedIncrement(&This->ref); TRACE("%p increasing refcount to %u.\n", This, ref); @@ -181,7 +221,7 @@ IDirect3DViewportImpl_AddRef(IDirect3DViewport3 *iface) static ULONG WINAPI IDirect3DViewportImpl_Release(IDirect3DViewport3 *iface) { - IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface; + IDirect3DViewportImpl *This = impl_from_IDirect3DViewport3(iface); ULONG ref = InterlockedDecrement(&This->ref); TRACE("%p decreasing refcount to %u.\n", This, ref); @@ -235,12 +275,13 @@ static HRESULT WINAPI IDirect3DViewportImpl_GetViewport(IDirect3DViewport3 *iface, D3DVIEWPORT *lpData) { - IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface; + IDirect3DViewportImpl *This = impl_from_IDirect3DViewport3(iface); DWORD dwSize; TRACE("iface %p, data %p.\n", iface, lpData); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); + dwSize = lpData->dwSize; memset(lpData, 0, dwSize); if (!This->use_vp2) @@ -266,7 +307,8 @@ IDirect3DViewportImpl_GetViewport(IDirect3DViewport3 *iface, TRACE(" returning D3DVIEWPORT :\n"); _dump_D3DVIEWPORT(lpData); } - LeaveCriticalSection(&ddraw_cs); + + wined3d_mutex_unlock(); return DD_OK; } @@ -288,8 +330,8 @@ static HRESULT WINAPI IDirect3DViewportImpl_SetViewport(IDirect3DViewport3 *iface, D3DVIEWPORT *lpData) { - IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface; - LPDIRECT3DVIEWPORT3 current_viewport; + IDirect3DViewportImpl *This = impl_from_IDirect3DViewport3(iface); + IDirect3DViewport3 *current_viewport; TRACE("iface %p, data %p.\n", iface, lpData); @@ -299,7 +341,8 @@ IDirect3DViewportImpl_SetViewport(IDirect3DViewport3 *iface, _dump_D3DVIEWPORT(lpData); } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); + This->use_vp2 = 0; memset(&(This->viewports.vp1), 0, sizeof(This->viewports.vp1)); memcpy(&(This->viewports.vp1), lpData, lpData->dwSize); @@ -311,15 +354,16 @@ IDirect3DViewportImpl_SetViewport(IDirect3DViewport3 *iface, This->viewports.vp1.dvMaxZ = 1.0; if (This->active_device) { - IDirect3DDevice3 *d3d_device3 = (IDirect3DDevice3 *)&This->active_device->IDirect3DDevice3_vtbl; + IDirect3DDevice3 *d3d_device3 = &This->active_device->IDirect3DDevice3_iface; IDirect3DDevice3_GetCurrentViewport(d3d_device3, ¤t_viewport); if (current_viewport) { - if ((IDirect3DViewportImpl *)current_viewport == This) viewport_activate(This, FALSE); + if (current_viewport == iface) viewport_activate(This, FALSE); IDirect3DViewport3_Release(current_viewport); } } - LeaveCriticalSection(&ddraw_cs); + + wined3d_mutex_unlock(); return DD_OK; } @@ -358,8 +402,8 @@ IDirect3DViewportImpl_TransformVertices(IDirect3DViewport3 *iface, DWORD dwFlags, DWORD *lpOffScreen) { - IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface; - D3DMATRIX view_mat, world_mat, proj_mat, mat; + IDirect3DViewportImpl *This = impl_from_IDirect3DViewport3(iface); + D3DMATRIX view_mat, world_mat, mat; float *in; float *out; float x, y, z, w; @@ -386,15 +430,13 @@ IDirect3DViewportImpl_TransformVertices(IDirect3DViewport3 *iface, } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); wined3d_device_get_transform(This->active_device->wined3d_device, - D3DTRANSFORMSTATE_VIEW, (WINED3DMATRIX *)&view_mat); + D3DTRANSFORMSTATE_VIEW, (struct wined3d_matrix *)&view_mat); wined3d_device_get_transform(This->active_device->wined3d_device, - D3DTRANSFORMSTATE_PROJECTION, (WINED3DMATRIX *)&proj_mat); - wined3d_device_get_transform(This->active_device->wined3d_device, - WINED3DTS_WORLDMATRIX(0), (WINED3DMATRIX *)&world_mat); - multiply_matrix(&mat,&view_mat,&world_mat); - multiply_matrix(&mat,&proj_mat,&mat); + WINED3D_TS_WORLD_MATRIX(0), (struct wined3d_matrix *)&world_mat); + multiply_matrix(&mat, &view_mat, &world_mat); + multiply_matrix(&mat, &This->active_device->legacy_projection, &mat); in = lpData->lpIn; out = lpData->lpOut; @@ -471,7 +513,7 @@ IDirect3DViewportImpl_TransformVertices(IDirect3DViewport3 *iface, { *lpOffScreen = 0; } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); TRACE("All done\n"); return DD_OK; @@ -515,18 +557,18 @@ static HRESULT WINAPI IDirect3DViewportImpl_SetBackground(IDirect3DViewport3 *iface, D3DMATERIALHANDLE hMat) { - IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface; + IDirect3DViewportImpl *This = impl_from_IDirect3DViewport3(iface); IDirect3DMaterialImpl *m; TRACE("iface %p, material %#x.\n", iface, hMat); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if (!hMat) { This->background = NULL; TRACE("Setting background to NULL\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } @@ -534,7 +576,7 @@ IDirect3DViewportImpl_SetBackground(IDirect3DViewport3 *iface, if (!m) { WARN("Invalid material handle.\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } @@ -543,7 +585,8 @@ IDirect3DViewportImpl_SetBackground(IDirect3DViewport3 *iface, m->mat.u.diffuse.u3.b, m->mat.u.diffuse.u4.a); This->background = m; - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } @@ -565,11 +608,11 @@ IDirect3DViewportImpl_GetBackground(IDirect3DViewport3 *iface, D3DMATERIALHANDLE *lphMat, BOOL *lpValid) { - IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface; + IDirect3DViewportImpl *This = impl_from_IDirect3DViewport3(iface); TRACE("iface %p, material %p, valid %p.\n", iface, lphMat, lpValid); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if(lpValid) { *lpValid = This->background != NULL; @@ -585,7 +628,7 @@ IDirect3DViewportImpl_GetBackground(IDirect3DViewport3 *iface, *lphMat = 0; } } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } @@ -655,10 +698,10 @@ IDirect3DViewportImpl_GetBackgroundDepth(IDirect3DViewport3 *iface, static HRESULT WINAPI IDirect3DViewportImpl_Clear(IDirect3DViewport3 *iface, DWORD dwCount, D3DRECT *lpRects, DWORD dwFlags) { - IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface; + IDirect3DViewportImpl *This = impl_from_IDirect3DViewport3(iface); DWORD color = 0x00000000; HRESULT hr; - LPDIRECT3DVIEWPORT3 current_viewport; + IDirect3DViewport3 *current_viewport; IDirect3DDevice3 *d3d_device3; TRACE("iface %p, rect_count %u, rects %p, flags %#x.\n", iface, dwCount, lpRects, dwFlags); @@ -667,9 +710,10 @@ static HRESULT WINAPI IDirect3DViewportImpl_Clear(IDirect3DViewport3 *iface, ERR(" Trying to clear a viewport not attached to a device !\n"); return D3DERR_VIEWPORTHASNODEVICE; } - d3d_device3 = (IDirect3DDevice3 *)&This->active_device->IDirect3DDevice3_vtbl; + d3d_device3 = &This->active_device->IDirect3DDevice3_iface; + + wined3d_mutex_lock(); - EnterCriticalSection(&ddraw_cs); if (dwFlags & D3DCLEAR_TARGET) { if (This->background == NULL) { ERR(" Trying to clear the color buffer without background material !\n"); @@ -687,17 +731,18 @@ static HRESULT WINAPI IDirect3DViewportImpl_Clear(IDirect3DViewport3 *iface, afterwards. */ viewport_activate(This, TRUE); - hr = IDirect3DDevice7_Clear((IDirect3DDevice7 *)This->active_device, dwCount, lpRects, + hr = IDirect3DDevice7_Clear(&This->active_device->IDirect3DDevice7_iface, dwCount, lpRects, dwFlags & (D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET), color, 1.0, 0x00000000); IDirect3DDevice3_GetCurrentViewport(d3d_device3, ¤t_viewport); if(current_viewport) { - IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)current_viewport; + IDirect3DViewportImpl *vp = impl_from_IDirect3DViewport3(current_viewport); viewport_activate(vp, TRUE); IDirect3DViewport3_Release(current_viewport); } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return hr; } @@ -715,21 +760,21 @@ static HRESULT WINAPI IDirect3DViewportImpl_Clear(IDirect3DViewport3 *iface, * DDERR_INVALIDPARAMS if there are 8 lights or more * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DViewportImpl_AddLight(IDirect3DViewport3 *iface, - IDirect3DLight *lpDirect3DLight) +static HRESULT WINAPI IDirect3DViewportImpl_AddLight(IDirect3DViewport3 *iface, + IDirect3DLight *lpDirect3DLight) { - IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface; - IDirect3DLightImpl *lpDirect3DLightImpl = (IDirect3DLightImpl *)lpDirect3DLight; + IDirect3DViewportImpl *This = impl_from_IDirect3DViewport3(iface); + IDirect3DLightImpl *lpDirect3DLightImpl = unsafe_impl_from_IDirect3DLight(lpDirect3DLight); DWORD i = 0; DWORD map = This->map_lights; TRACE("iface %p, light %p.\n", iface, lpDirect3DLight); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); + if (This->num_lights >= 8) { - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } @@ -754,7 +799,8 @@ IDirect3DViewportImpl_AddLight(IDirect3DViewport3 *iface, if (This->active_device) light_activate(lpDirect3DLightImpl); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } @@ -771,21 +817,20 @@ IDirect3DViewportImpl_AddLight(IDirect3DViewport3 *iface, * DDERR_INVALIDPARAMS if the light wasn't found * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DViewportImpl_DeleteLight(IDirect3DViewport3 *iface, - IDirect3DLight *lpDirect3DLight) +static HRESULT WINAPI IDirect3DViewportImpl_DeleteLight(IDirect3DViewport3 *iface, + IDirect3DLight *lpDirect3DLight) { - IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface; - IDirect3DLightImpl *l = (IDirect3DLightImpl *)lpDirect3DLight; + IDirect3DViewportImpl *This = impl_from_IDirect3DViewport3(iface); + IDirect3DLightImpl *l = unsafe_impl_from_IDirect3DLight(lpDirect3DLight); TRACE("iface %p, light %p.\n", iface, lpDirect3DLight); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); if (l->active_viewport != This) { WARN("Light %p active viewport is %p.\n", l, l->active_viewport); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return DDERR_INVALIDPARAMS; } @@ -796,7 +841,7 @@ IDirect3DViewportImpl_DeleteLight(IDirect3DViewport3 *iface, --This->num_lights; This->map_lights &= ~(1 << l->dwLightIndex); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3D_OK; } @@ -814,14 +859,11 @@ IDirect3DViewportImpl_DeleteLight(IDirect3DViewport3 *iface, * D3D_OK, because it's a stub * *****************************************************************************/ -static HRESULT WINAPI -IDirect3DViewportImpl_NextLight(IDirect3DViewport3 *iface, - IDirect3DLight *lpDirect3DLight, - IDirect3DLight **lplpDirect3DLight, - DWORD dwFlags) +static HRESULT WINAPI IDirect3DViewportImpl_NextLight(IDirect3DViewport3 *iface, + IDirect3DLight *lpDirect3DLight, IDirect3DLight **lplpDirect3DLight, DWORD dwFlags) { - IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface; - IDirect3DLightImpl *l = (IDirect3DLightImpl *)lpDirect3DLight; + IDirect3DViewportImpl *This = impl_from_IDirect3DViewport3(iface); + IDirect3DLightImpl *l = unsafe_impl_from_IDirect3DLight(lpDirect3DLight); struct list *entry; HRESULT hr; @@ -831,7 +873,7 @@ IDirect3DViewportImpl_NextLight(IDirect3DViewport3 *iface, if (!lplpDirect3DLight) return DDERR_INVALIDPARAMS; - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); switch (dwFlags) { @@ -872,7 +914,7 @@ IDirect3DViewportImpl_NextLight(IDirect3DViewport3 *iface, hr = DDERR_INVALIDPARAMS; } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return hr; } @@ -901,12 +943,12 @@ static HRESULT WINAPI IDirect3DViewportImpl_GetViewport2(IDirect3DViewport3 *iface, D3DVIEWPORT2 *lpData) { - IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface; + IDirect3DViewportImpl *This = impl_from_IDirect3DViewport3(iface); DWORD dwSize; TRACE("iface %p, data %p.\n", iface, lpData); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); dwSize = lpData->dwSize; memset(lpData, 0, dwSize); if (This->use_vp2) @@ -933,7 +975,8 @@ IDirect3DViewportImpl_GetViewport2(IDirect3DViewport3 *iface, _dump_D3DVIEWPORT2(lpData); } - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); + return D3D_OK; } @@ -953,8 +996,8 @@ static HRESULT WINAPI IDirect3DViewportImpl_SetViewport2(IDirect3DViewport3 *iface, D3DVIEWPORT2 *lpData) { - IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface; - LPDIRECT3DVIEWPORT3 current_viewport; + IDirect3DViewportImpl *This = impl_from_IDirect3DViewport3(iface); + IDirect3DViewport3 *current_viewport; TRACE("iface %p, data %p.\n", iface, lpData); @@ -964,21 +1007,23 @@ IDirect3DViewportImpl_SetViewport2(IDirect3DViewport3 *iface, _dump_D3DVIEWPORT2(lpData); } - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); + This->use_vp2 = 1; memset(&(This->viewports.vp2), 0, sizeof(This->viewports.vp2)); memcpy(&(This->viewports.vp2), lpData, lpData->dwSize); if (This->active_device) { - IDirect3DDevice3 *d3d_device3 = (IDirect3DDevice3 *)&This->active_device->IDirect3DDevice3_vtbl; + IDirect3DDevice3 *d3d_device3 = &This->active_device->IDirect3DDevice3_iface; IDirect3DDevice3_GetCurrentViewport(d3d_device3, ¤t_viewport); if (current_viewport) { - if ((IDirect3DViewportImpl *)current_viewport == This) viewport_activate(This, FALSE); + if (current_viewport == iface) viewport_activate(This, FALSE); IDirect3DViewport3_Release(current_viewport); } } - LeaveCriticalSection(&ddraw_cs); + + wined3d_mutex_unlock(); return D3D_OK; } @@ -1056,34 +1101,37 @@ IDirect3DViewportImpl_Clear2(IDirect3DViewport3 *iface, D3DVALUE dvZ, DWORD dwStencil) { - IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface; + IDirect3DViewportImpl *This = impl_from_IDirect3DViewport3(iface); HRESULT hr; - LPDIRECT3DVIEWPORT3 current_viewport; + IDirect3DViewport3 *current_viewport; IDirect3DDevice3 *d3d_device3; TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, depth %.8e, stencil %u.\n", iface, dwCount, lpRects, dwFlags, dwColor, dvZ, dwStencil); - EnterCriticalSection(&ddraw_cs); + wined3d_mutex_lock(); + if (This->active_device == NULL) { ERR(" Trying to clear a viewport not attached to a device !\n"); - LeaveCriticalSection(&ddraw_cs); + wined3d_mutex_unlock(); return D3DERR_VIEWPORTHASNODEVICE; } - d3d_device3 = (IDirect3DDevice3 *)&This->active_device->IDirect3DDevice3_vtbl; + d3d_device3 = &This->active_device->IDirect3DDevice3_iface; /* Need to temporarily activate viewport to clear it. Previously active * one will be restored afterwards. */ viewport_activate(This, TRUE); - hr = IDirect3DDevice7_Clear((IDirect3DDevice7 *)This->active_device, + hr = IDirect3DDevice7_Clear(&This->active_device->IDirect3DDevice7_iface, dwCount, lpRects, dwFlags, dwColor, dvZ, dwStencil); IDirect3DDevice3_GetCurrentViewport(d3d_device3, ¤t_viewport); if(current_viewport) { - IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)current_viewport; + IDirect3DViewportImpl *vp = impl_from_IDirect3DViewport3(current_viewport); viewport_activate(vp, TRUE); IDirect3DViewport3_Release(current_viewport); } - LeaveCriticalSection(&ddraw_cs); + + wined3d_mutex_unlock(); + return hr; } @@ -1120,9 +1168,32 @@ static const struct IDirect3DViewport3Vtbl d3d_viewport_vtbl = IDirect3DViewportImpl_Clear2, }; +IDirect3DViewportImpl *unsafe_impl_from_IDirect3DViewport3(IDirect3DViewport3 *iface) +{ + if (!iface) return NULL; + assert(iface->lpVtbl == &d3d_viewport_vtbl); + return CONTAINING_RECORD(iface, IDirect3DViewportImpl, IDirect3DViewport3_iface); +} + +IDirect3DViewportImpl *unsafe_impl_from_IDirect3DViewport2(IDirect3DViewport2 *iface) +{ + /* IDirect3DViewport and IDirect3DViewport3 use the same iface. */ + if (!iface) return NULL; + assert(iface->lpVtbl == (IDirect3DViewport2Vtbl *)&d3d_viewport_vtbl); + return CONTAINING_RECORD(iface, IDirect3DViewportImpl, IDirect3DViewport3_iface); +} + +IDirect3DViewportImpl *unsafe_impl_from_IDirect3DViewport(IDirect3DViewport *iface) +{ + /* IDirect3DViewport and IDirect3DViewport3 use the same iface. */ + if (!iface) return NULL; + assert(iface->lpVtbl == (IDirect3DViewportVtbl *)&d3d_viewport_vtbl); + return CONTAINING_RECORD(iface, IDirect3DViewportImpl, IDirect3DViewport3_iface); +} + void d3d_viewport_init(IDirect3DViewportImpl *viewport, IDirectDrawImpl *ddraw) { - viewport->lpVtbl = &d3d_viewport_vtbl; + viewport->IDirect3DViewport3_iface.lpVtbl = &d3d_viewport_vtbl; viewport->ref = 1; viewport->ddraw = ddraw; viewport->use_vp2 = 0xff; diff --git a/reactos/dll/directx/wine/wined3d/CMakeLists.txt b/reactos/dll/directx/wine/wined3d/CMakeLists.txt index 910ebdf0dd7..5926ab03ce0 100644 --- a/reactos/dll/directx/wine/wined3d/CMakeLists.txt +++ b/reactos/dll/directx/wine/wined3d/CMakeLists.txt @@ -19,7 +19,6 @@ list(APPEND SOURCE ati_fragment_shader.c arb_program_shader.c buffer.c - clipper.c context.c device.c directx.c @@ -53,7 +52,7 @@ list(APPEND SOURCE endif() add_library(wined3d SHARED ${SOURCE}) -set_module_type(wined3d win32dll) +set_module_type(wined3d win32dll ENTRYPOINT 0) target_link_libraries(wined3d wine) diff --git a/reactos/dll/directx/wine/wined3d/arb_program_shader.c b/reactos/dll/directx/wine/wined3d/arb_program_shader.c index ee5bf86d88a..5510a7777ec 100644 --- a/reactos/dll/directx/wine/wined3d/arb_program_shader.c +++ b/reactos/dll/directx/wine/wined3d/arb_program_shader.c @@ -285,7 +285,6 @@ struct ps_signature struct arb_pshader_private { struct arb_ps_compiled_shader *gl_shaders; UINT num_gl_shaders, shader_array_size; - BOOL has_signature_idx; DWORD input_signature_idx; DWORD clipplane_emulation; BOOL clamp_consts; @@ -313,6 +312,10 @@ struct shader_arb_priv struct wine_rb_tree signature_tree; DWORD ps_sig_number; + + unsigned int highest_dirty_ps_const, highest_dirty_vs_const; + char *vshader_const_dirty, *pshader_const_dirty; + const struct wined3d_context *last_context; }; /* GL locking for state handlers is done by the caller. */ @@ -362,10 +365,11 @@ static unsigned int reserved_vs_const(const struct arb_vshader_private *shader_d * or GL_FRAGMENT_PROGRAM_ARB (for pixel shaders) */ /* GL locking is done by the caller */ -static unsigned int shader_arb_load_constantsF(struct wined3d_shader *shader, const struct wined3d_gl_info *gl_info, - GLuint target_type, unsigned int max_constants, const float *constants, char *dirty_consts) +static unsigned int shader_arb_load_constantsF(const struct wined3d_shader *shader, + const struct wined3d_gl_info *gl_info, GLuint target_type, unsigned int max_constants, + const float *constants, char *dirty_consts) { - local_constant* lconst; + struct wined3d_shader_lconst *lconst; DWORD i, j; unsigned int ret; @@ -455,7 +459,7 @@ static unsigned int shader_arb_load_constantsF(struct wined3d_shader *shader, co { if (TRACE_ON(d3d_shader)) { - LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, local_constant, entry) + LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry) { GLfloat* values = (GLfloat*)lconst->value; TRACE_(d3d_constants)("Loading local constants %i: %f, %f, %f, %f\n", lconst->idx, @@ -464,7 +468,7 @@ static unsigned int shader_arb_load_constantsF(struct wined3d_shader *shader, co } /* Immediate constants are clamped for 1.X shaders at loading times */ ret = 0; - LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, local_constant, entry) + LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry) { dirty_consts[lconst->idx] = 1; /* Dirtify so the non-immediate constant overwrites it next time */ ret = max(ret, lconst->idx + 1); @@ -538,18 +542,18 @@ static void shader_arb_ps_local_constants(const struct arb_ps_compiled_shader *g int texunit = gl_shader->bumpenvmatconst[i].texunit; /* The state manager takes care that this function is always called if the bump env matrix changes */ - const float *data = (const float *)&state->texture_states[texunit][WINED3DTSS_BUMPENVMAT00]; + const float *data = (const float *)&state->texture_states[texunit][WINED3D_TSS_BUMPENV_MAT00]; GL_EXTCALL(glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, gl_shader->bumpenvmatconst[i].const_num, data)); if (gl_shader->luminanceconst[i].const_num != WINED3D_CONST_NUM_UNUSED) { - /* WINED3DTSS_BUMPENVLSCALE and WINED3DTSS_BUMPENVLOFFSET are next to each other. + /* WINED3D_TSS_BUMPENVLSCALE and WINED3D_TSS_BUMPENVLOFFSET are next to each other. * point gl to the scale, and load 4 floats. x = scale, y = offset, z and w are junk, we * don't care about them. The pointers are valid for sure because the stateblock is bigger. - * (they're WINED3DTSS_TEXTURETRANSFORMFLAGS and WINED3DTSS_ADDRESSW, so most likely 0 or NaN + * (they're WINED3D_TSS_TEXTURETRANSFORMFLAGS and WINED3D_TSS_ADDRESSW, so most likely 0 or NaN */ - const float *scale = (const float *)&state->texture_states[texunit][WINED3DTSS_BUMPENVLSCALE]; + const float *scale = (const float *)&state->texture_states[texunit][WINED3D_TSS_BUMPENV_LSCALE]; GL_EXTCALL(glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, gl_shader->luminanceconst[i].const_num, scale)); } @@ -630,63 +634,78 @@ static void shader_arb_vs_local_constants(const struct arb_vs_compiled_shader *g static void shader_arb_load_constants(const struct wined3d_context *context, char usePixelShader, char useVertexShader) { struct wined3d_device *device = context->swapchain->device; - struct wined3d_stateblock *stateBlock = device->stateBlock; + const struct wined3d_state *state = &device->stateBlock->state; const struct wined3d_gl_info *gl_info = context->gl_info; struct shader_arb_priv *priv = device->shader_priv; + if (context != priv->last_context) + { + memset(priv->vshader_const_dirty, 1, + sizeof(*priv->vshader_const_dirty) * device->d3d_vshader_constantF); + priv->highest_dirty_vs_const = device->d3d_vshader_constantF; + + memset(priv->pshader_const_dirty, 1, + sizeof(*priv->pshader_const_dirty) * device->d3d_pshader_constantF); + priv->highest_dirty_ps_const = device->d3d_pshader_constantF; + + priv->last_context = context; + } + if (useVertexShader) { - struct wined3d_shader *vshader = stateBlock->state.vertex_shader; + struct wined3d_shader *vshader = state->vertex_shader; const struct arb_vs_compiled_shader *gl_shader = priv->compiled_vprog; /* Load DirectX 9 float constants for vertex shader */ - device->highest_dirty_vs_const = shader_arb_load_constantsF(vshader, gl_info, GL_VERTEX_PROGRAM_ARB, - device->highest_dirty_vs_const, stateBlock->state.vs_consts_f, context->vshader_const_dirty); - shader_arb_vs_local_constants(gl_shader, context, &stateBlock->state); + priv->highest_dirty_vs_const = shader_arb_load_constantsF(vshader, gl_info, GL_VERTEX_PROGRAM_ARB, + priv->highest_dirty_vs_const, state->vs_consts_f, priv->vshader_const_dirty); + shader_arb_vs_local_constants(gl_shader, context, state); } if (usePixelShader) { - struct wined3d_shader *pshader = stateBlock->state.pixel_shader; + struct wined3d_shader *pshader = state->pixel_shader; const struct arb_ps_compiled_shader *gl_shader = priv->compiled_fprog; - UINT rt_height = device->fb.render_targets[0]->resource.height; + UINT rt_height = state->fb->render_targets[0]->resource.height; /* Load DirectX 9 float constants for pixel shader */ - device->highest_dirty_ps_const = shader_arb_load_constantsF(pshader, gl_info, GL_FRAGMENT_PROGRAM_ARB, - device->highest_dirty_ps_const, stateBlock->state.ps_consts_f, context->pshader_const_dirty); - shader_arb_ps_local_constants(gl_shader, context, &stateBlock->state, rt_height); + priv->highest_dirty_ps_const = shader_arb_load_constantsF(pshader, gl_info, GL_FRAGMENT_PROGRAM_ARB, + priv->highest_dirty_ps_const, state->ps_consts_f, priv->pshader_const_dirty); + shader_arb_ps_local_constants(gl_shader, context, state, rt_height); } } static void shader_arb_update_float_vertex_constants(struct wined3d_device *device, UINT start, UINT count) { struct wined3d_context *context = context_get_current(); + struct shader_arb_priv *priv = device->shader_priv; /* We don't want shader constant dirtification to be an O(contexts), so just dirtify the active * context. On a context switch the old context will be fully dirtified */ if (!context || context->swapchain->device != device) return; - memset(context->vshader_const_dirty + start, 1, sizeof(*context->vshader_const_dirty) * count); - device->highest_dirty_vs_const = max(device->highest_dirty_vs_const, start + count); + memset(priv->vshader_const_dirty + start, 1, sizeof(*priv->vshader_const_dirty) * count); + priv->highest_dirty_vs_const = max(priv->highest_dirty_vs_const, start + count); } static void shader_arb_update_float_pixel_constants(struct wined3d_device *device, UINT start, UINT count) { struct wined3d_context *context = context_get_current(); + struct shader_arb_priv *priv = device->shader_priv; /* We don't want shader constant dirtification to be an O(contexts), so just dirtify the active * context. On a context switch the old context will be fully dirtified */ if (!context || context->swapchain->device != device) return; - memset(context->pshader_const_dirty + start, 1, sizeof(*context->pshader_const_dirty) * count); - device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, start + count); + memset(priv->pshader_const_dirty + start, 1, sizeof(*priv->pshader_const_dirty) * count); + priv->highest_dirty_ps_const = max(priv->highest_dirty_ps_const, start + count); } static DWORD *local_const_mapping(const struct wined3d_shader *shader) { + const struct wined3d_shader_lconst *lconst; DWORD *ret; DWORD idx = 0; - const local_constant *lconst; if (shader->load_local_constsF || list_empty(&shader->constantsF)) return NULL; @@ -698,7 +717,7 @@ static DWORD *local_const_mapping(const struct wined3d_shader *shader) return NULL; } - LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, local_constant, entry) + LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry) { ret[lconst->idx] = idx++; } @@ -706,15 +725,15 @@ static DWORD *local_const_mapping(const struct wined3d_shader *shader) } /* Generate the variable & register declarations for the ARB_vertex_program output target */ -static DWORD shader_generate_arb_declarations(struct wined3d_shader *shader, +static DWORD shader_generate_arb_declarations(const struct wined3d_shader *shader, const struct wined3d_shader_reg_maps *reg_maps, struct wined3d_shader_buffer *buffer, - const struct wined3d_gl_info *gl_info, DWORD *lconst_map, - DWORD *num_clipplanes, struct shader_arb_ctx_priv *ctx) + const struct wined3d_gl_info *gl_info, const DWORD *lconst_map, + DWORD *num_clipplanes, const struct shader_arb_ctx_priv *ctx) { DWORD i, next_local = 0; char pshader = shader_is_pshader_version(reg_maps->shader_version.type); + const struct wined3d_shader_lconst *lconst; unsigned max_constantsF; - const local_constant *lconst; DWORD map; /* In pixel shaders, all private constants are program local, we don't need anything @@ -724,7 +743,7 @@ static DWORD shader_generate_arb_declarations(struct wined3d_shader *shader, * With vertex shaders we need the posFixup and on some GL implementations 4 helper * immediate values. The posFixup is loaded using program.env for now, so always * subtract one from the number of constants. If the shader uses indirect addressing, - * account for the helper const too because we have to declare all availabke d3d constants + * account for the helper const too because we have to declare all available d3d constants * and don't know which are actually used. */ if (pshader) @@ -807,7 +826,7 @@ static DWORD shader_generate_arb_declarations(struct wined3d_shader *shader, */ if (lconst_map) { - LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, local_constant, entry) + LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry) { shader_addline(buffer, "PARAM C%u = program.local[%u];\n", lconst->idx, lconst_map[lconst->idx]); @@ -944,7 +963,7 @@ static void shader_arb_get_register_name(const struct wined3d_shader_instruction { /* oPos, oFog and oPts in D3D */ static const char * const rastout_reg_names[] = {"TMP_OUT", "result.fogcoord", "result.pointsize"}; - struct wined3d_shader *shader = ins->ctx->shader; + const struct wined3d_shader *shader = ins->ctx->shader; const struct wined3d_shader_reg_maps *reg_maps = ins->ctx->reg_maps; BOOL pshader = shader_is_pshader_version(reg_maps->shader_version.type); struct shader_arb_ctx_priv *ctx = ins->ctx->backend_data; @@ -1337,10 +1356,10 @@ static void shader_hw_sample(const struct wined3d_shader_instruction *ins, DWORD { struct wined3d_shader_buffer *buffer = ins->ctx->buffer; DWORD sampler_type = ins->ctx->reg_maps->sampler_type[sampler_idx]; + const struct wined3d_shader *shader = ins->ctx->shader; const struct wined3d_texture *texture; const char *tex_type; BOOL np2_fixup = FALSE; - struct wined3d_shader *shader = ins->ctx->shader; struct wined3d_device *device = shader->device; struct shader_arb_ctx_priv *priv = ins->ctx->backend_data; const char *mod; @@ -1742,7 +1761,7 @@ static void shader_hw_nop(const struct wined3d_shader_instruction *ins) static void shader_hw_mov(const struct wined3d_shader_instruction *ins) { - struct wined3d_shader *shader = ins->ctx->shader; + const struct wined3d_shader *shader = ins->ctx->shader; const struct wined3d_shader_reg_maps *reg_maps = ins->ctx->reg_maps; BOOL pshader = shader_is_pshader_version(reg_maps->shader_version.type); struct shader_arb_ctx_priv *ctx = ins->ctx->backend_data; @@ -1837,7 +1856,7 @@ static void pshader_hw_texkill(const struct wined3d_shader_instruction *ins) char reg_dest[40]; /* No swizzles are allowed in d3d's texkill. PS 1.x ignores the 4th component as documented, - * but >= 2.0 honors it(undocumented, but tested by the d3d9 testsuit) + * but >= 2.0 honors it (undocumented, but tested by the d3d9 testsuite) */ shader_arb_get_dst_param(ins, dst, reg_dest); @@ -1918,7 +1937,7 @@ static void pshader_hw_tex(const struct wined3d_shader_instruction *ins) } /* projection flag: - * 1.1, 1.2, 1.3: Use WINED3DTSS_TEXTURETRANSFORMFLAGS + * 1.1, 1.2, 1.3: Use WINED3D_TSS_TEXTURETRANSFORMFLAGS * 1.4: Use WINED3DSPSM_DZ or WINED3DSPSM_DW on src[0] * 2.0+: Use WINED3DSI_TEXLD_PROJECT on the opcode */ @@ -1932,8 +1951,9 @@ static void pshader_hw_tex(const struct wined3d_shader_instruction *ins) } else if (shader_version < WINED3D_SHADER_VERSION(2,0)) { - DWORD src_mod = ins->src[0].modifiers; - if (src_mod == WINED3DSPSM_DZ) { + enum wined3d_shader_src_modifier src_mod = ins->src[0].modifiers; + if (src_mod == WINED3DSPSM_DZ) + { /* TXP cannot handle DZ natively, so move the z coordinate to .w. reg_coord is a read-only * varying register, so we need a temp reg */ @@ -2114,7 +2134,7 @@ static void pshader_hw_texm3x2tex(const struct wined3d_shader_instruction *ins) shader_arb_get_src_param(ins, &ins->src[0], 0, src0_name); shader_addline(buffer, "DP3 %s.y, fragment.texcoord[%u], %s;\n", dst_reg, reg, src0_name); flags = reg < MAX_TEXTURES ? priv->cur_ps_args->super.tex_transform >> reg * WINED3D_PSARGS_TEXTRANSFORM_SHIFT : 0; - shader_hw_sample(ins, reg, dst_str, dst_reg, flags & WINED3DTTFF_PROJECTED ? TEX_PROJ : 0, NULL, NULL); + shader_hw_sample(ins, reg, dst_str, dst_reg, flags & WINED3D_PSARGS_PROJECTED ? TEX_PROJ : 0, NULL, NULL); } static void pshader_hw_texm3x3pad(const struct wined3d_shader_instruction *ins) @@ -2157,7 +2177,7 @@ static void pshader_hw_texm3x3tex(const struct wined3d_shader_instruction *ins) /* Sample the texture using the calculated coordinates */ shader_arb_get_dst_param(ins, &ins->dst[0], dst_str); flags = reg < MAX_TEXTURES ? priv->cur_ps_args->super.tex_transform >> reg * WINED3D_PSARGS_TEXTRANSFORM_SHIFT : 0; - shader_hw_sample(ins, reg, dst_str, dst_name, flags & WINED3DTTFF_PROJECTED ? TEX_PROJ : 0, NULL, NULL); + shader_hw_sample(ins, reg, dst_str, dst_name, flags & WINED3D_PSARGS_PROJECTED ? TEX_PROJ : 0, NULL, NULL); tex_mx->current_row = 0; } @@ -2198,7 +2218,7 @@ static void pshader_hw_texm3x3vspec(const struct wined3d_shader_instruction *ins /* Sample the texture using the calculated coordinates */ shader_arb_get_dst_param(ins, &ins->dst[0], dst_str); flags = reg < MAX_TEXTURES ? priv->cur_ps_args->super.tex_transform >> reg * WINED3D_PSARGS_TEXTRANSFORM_SHIFT : 0; - shader_hw_sample(ins, reg, dst_str, dst_reg, flags & WINED3DTTFF_PROJECTED ? TEX_PROJ : 0, NULL, NULL); + shader_hw_sample(ins, reg, dst_str, dst_reg, flags & WINED3D_PSARGS_PROJECTED ? TEX_PROJ : 0, NULL, NULL); tex_mx->current_row = 0; } @@ -2239,7 +2259,7 @@ static void pshader_hw_texm3x3spec(const struct wined3d_shader_instruction *ins) /* Sample the texture using the calculated coordinates */ shader_arb_get_dst_param(ins, &ins->dst[0], dst_str); flags = reg < MAX_TEXTURES ? priv->cur_ps_args->super.tex_transform >> reg * WINED3D_PSARGS_TEXTRANSFORM_SHIFT : 0; - shader_hw_sample(ins, reg, dst_str, dst_reg, flags & WINED3DTTFF_PROJECTED ? TEX_PROJ : 0, NULL, NULL); + shader_hw_sample(ins, reg, dst_str, dst_reg, flags & WINED3D_PSARGS_PROJECTED ? TEX_PROJ : 0, NULL, NULL); tex_mx->current_row = 0; } @@ -2924,34 +2944,34 @@ static void shader_hw_break(const struct wined3d_shader_instruction *ins) } } -static const char *get_compare(COMPARISON_TYPE flags) +static const char *get_compare(enum wined3d_shader_rel_op op) { - switch (flags) + switch (op) { - case COMPARISON_GT: return "GT"; - case COMPARISON_EQ: return "EQ"; - case COMPARISON_GE: return "GE"; - case COMPARISON_LT: return "LT"; - case COMPARISON_NE: return "NE"; - case COMPARISON_LE: return "LE"; + case WINED3D_SHADER_REL_OP_GT: return "GT"; + case WINED3D_SHADER_REL_OP_EQ: return "EQ"; + case WINED3D_SHADER_REL_OP_GE: return "GE"; + case WINED3D_SHADER_REL_OP_LT: return "LT"; + case WINED3D_SHADER_REL_OP_NE: return "NE"; + case WINED3D_SHADER_REL_OP_LE: return "LE"; default: - FIXME("Unrecognized comparison value: %u\n", flags); + FIXME("Unrecognized operator %#x.\n", op); return "(\?\?)"; } } -static COMPARISON_TYPE invert_compare(COMPARISON_TYPE flags) +static enum wined3d_shader_rel_op invert_compare(enum wined3d_shader_rel_op op) { - switch (flags) + switch (op) { - case COMPARISON_GT: return COMPARISON_LE; - case COMPARISON_EQ: return COMPARISON_NE; - case COMPARISON_GE: return COMPARISON_LT; - case COMPARISON_LT: return COMPARISON_GE; - case COMPARISON_NE: return COMPARISON_EQ; - case COMPARISON_LE: return COMPARISON_GT; + case WINED3D_SHADER_REL_OP_GT: return WINED3D_SHADER_REL_OP_LE; + case WINED3D_SHADER_REL_OP_EQ: return WINED3D_SHADER_REL_OP_NE; + case WINED3D_SHADER_REL_OP_GE: return WINED3D_SHADER_REL_OP_LT; + case WINED3D_SHADER_REL_OP_LT: return WINED3D_SHADER_REL_OP_GE; + case WINED3D_SHADER_REL_OP_NE: return WINED3D_SHADER_REL_OP_EQ; + case WINED3D_SHADER_REL_OP_LE: return WINED3D_SHADER_REL_OP_GT; default: - FIXME("Unrecognized comparison value: %u\n", flags); + FIXME("Unrecognized operator %#x.\n", op); return -1; } } @@ -3202,7 +3222,7 @@ static void shader_hw_ret(const struct wined3d_shader_instruction *ins) { struct wined3d_shader_buffer *buffer = ins->ctx->buffer; struct shader_arb_ctx_priv *priv = ins->ctx->backend_data; - struct wined3d_shader *shader = ins->ctx->shader; + const struct wined3d_shader *shader = ins->ctx->shader; BOOL vshader = shader_is_vshader_version(ins->ctx->reg_maps->shader_version.type); if(priv->target_version == ARB) return; @@ -3411,9 +3431,9 @@ static void arbfp_add_sRGB_correction(struct wined3d_shader_buffer *buffer, cons static const DWORD *find_loop_control_values(const struct wined3d_shader *shader, DWORD idx) { - const local_constant *constant; + const struct wined3d_shader_lconst *constant; - LIST_FOR_EACH_ENTRY(constant, &shader->constantsI, local_constant, entry) + LIST_FOR_EACH_ENTRY(constant, &shader->constantsI, struct wined3d_shader_lconst, entry) { if (constant->idx == idx) { @@ -3498,13 +3518,13 @@ static void init_ps_input(const struct wined3d_shader *shader, } /* GL locking is done by the caller */ -static GLuint shader_arb_generate_pshader(struct wined3d_shader *shader, +static GLuint shader_arb_generate_pshader(const struct wined3d_shader *shader, const struct wined3d_gl_info *gl_info, struct wined3d_shader_buffer *buffer, const struct arb_ps_compile_args *args, struct arb_ps_compiled_shader *compiled) { const struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps; + const struct wined3d_shader_lconst *lconst; const DWORD *function = shader->function; - const local_constant *lconst; GLuint retval; char fragcolor[16]; DWORD *lconst_map = local_const_mapping(shader), next_local; @@ -3778,8 +3798,6 @@ static GLuint shader_arb_generate_pshader(struct wined3d_shader *shader, shader_addline(buffer, "PARAM np2fixup[%u] = { program.env[%u..%u] };\n", fixup->super.num_consts, fixup->offset, fixup->super.num_consts + fixup->offset - 1); } - - next_local += fixup->super.num_consts; } if (shader_priv->clipplane_emulation != ~0U && args->clip) @@ -3832,7 +3850,7 @@ static GLuint shader_arb_generate_pshader(struct wined3d_shader *shader, /* Load immediate constants */ if (lconst_map) { - LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, local_constant, entry) + LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry) { const float *value = (const float *)lconst->value; GL_EXTCALL(glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, lconst_map[lconst->idx], value)); @@ -3863,7 +3881,7 @@ static int compare_sig(const struct wined3d_shader_signature_element *sig1, cons if(sig1[i].sysval_semantic != sig2[i].sysval_semantic) return sig1[i].sysval_semantic < sig2[i].sysval_semantic ? -1 : 1; if(sig1[i].component_type != sig2[i].component_type) return sig1[i].component_type < sig2[i].component_type ? -1 : 1; if(sig1[i].register_idx != sig2[i].register_idx) return sig1[i].register_idx < sig2[i].register_idx ? -1 : 1; - if(sig1[i].mask != sig2->mask) return sig1[i].mask < sig2[i].mask ? -1 : 1; + if(sig1[i].mask != sig2[i].mask) return sig1[i].mask < sig2[i].mask ? -1 : 1; } return 0; } @@ -3910,7 +3928,7 @@ static DWORD find_input_signature(struct shader_arb_priv *priv, const struct win return found_sig->idx; } -static void init_output_registers(struct wined3d_shader *shader, DWORD sig_num, +static void init_output_registers(const struct wined3d_shader *shader, DWORD sig_num, struct shader_arb_ctx_priv *priv_ctx, struct arb_vs_compiled_shader *compiled) { unsigned int i, j; @@ -4086,14 +4104,14 @@ static void init_output_registers(struct wined3d_shader *shader, DWORD sig_num, } /* GL locking is done by the caller */ -static GLuint shader_arb_generate_vshader(struct wined3d_shader *shader, +static GLuint shader_arb_generate_vshader(const struct wined3d_shader *shader, const struct wined3d_gl_info *gl_info, struct wined3d_shader_buffer *buffer, const struct arb_vs_compile_args *args, struct arb_vs_compiled_shader *compiled) { const struct arb_vshader_private *shader_data = shader->backend_data; const struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps; + const struct wined3d_shader_lconst *lconst; const DWORD *function = shader->function; - const local_constant *lconst; GLuint ret; DWORD next_local, *lconst_map = local_const_mapping(shader); struct shader_arb_ctx_priv priv_ctx; @@ -4239,7 +4257,7 @@ static GLuint shader_arb_generate_vshader(struct wined3d_shader *shader, /* Load immediate constants */ if (lconst_map) { - LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, local_constant, entry) + LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry) { const float *value = (const float *)lconst->value; GL_EXTCALL(glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, lconst_map[lconst->idx], value)); @@ -4277,7 +4295,6 @@ static struct arb_ps_compiled_shader *find_arb_pshader(struct wined3d_shader *sh else shader_data->input_signature_idx = find_input_signature(priv, shader->input_signature); - shader_data->has_signature_idx = TRUE; TRACE("Shader got assigned input signature index %u\n", shader_data->input_signature_idx); if (!device->vs_clipping) @@ -4459,8 +4476,8 @@ static void find_arb_ps_compile_args(const struct wined3d_state *state, * duplicate the shader than have a no-op KIL instruction in every shader */ if (!device->vs_clipping && use_vs(state) - && state->render_states[WINED3DRS_CLIPPING] - && state->render_states[WINED3DRS_CLIPPLANEENABLE]) + && state->render_states[WINED3D_RS_CLIPPING] + && state->render_states[WINED3D_RS_CLIPPLANEENABLE]) args->clip = 1; else args->clip = 0; @@ -4469,7 +4486,7 @@ static void find_arb_ps_compile_args(const struct wined3d_state *state, int_skip = ~shader->reg_maps.integer_constants | shader->reg_maps.local_int_consts; if (int_skip == 0xffff || gl_info->supported[NV_FRAGMENT_PROGRAM_OPTION]) { - memset(&args->loop_ctrl, 0, sizeof(args->loop_ctrl)); + memset(args->loop_ctrl, 0, sizeof(args->loop_ctrl)); return; } @@ -4512,7 +4529,7 @@ static void find_arb_vs_compile_args(const struct wined3d_state *state, else { args->ps_signature = ~0; - if (!device->vs_clipping) + if (!device->vs_clipping && device->adapter->fragment_pipe == &arbfp_fragment_pipeline) { args->clip.boolclip.clip_texcoord = ffp_clip_emul(state) ? gl_info->limits.texture_stages : 0; } @@ -4521,8 +4538,8 @@ static void find_arb_vs_compile_args(const struct wined3d_state *state, if (args->clip.boolclip.clip_texcoord) { - if (state->render_states[WINED3DRS_CLIPPING]) - args->clip.boolclip.clipplane_mask = (unsigned char)state->render_states[WINED3DRS_CLIPPLANEENABLE]; + if (state->render_states[WINED3D_RS_CLIPPING]) + args->clip.boolclip.clipplane_mask = (unsigned char)state->render_states[WINED3D_RS_CLIPPLANEENABLE]; /* clipplane_mask was set to 0 by setting boolclip_compare to 0 */ } @@ -4545,7 +4562,7 @@ static void find_arb_vs_compile_args(const struct wined3d_state *state, /* This is about flow control, not clipping. */ if (int_skip == 0xffff || gl_info->supported[NV_VERTEX_PROGRAM2_OPTION]) { - memset(&args->loop_ctrl, 0, sizeof(args->loop_ctrl)); + memset(args->loop_ctrl, 0, sizeof(args->loop_ctrl)); return; } @@ -4606,17 +4623,17 @@ static void shader_arb_select(const struct wined3d_context *context, BOOL usePS, if (priv->last_ps_const_clamped != ((struct arb_pshader_private *)ps->backend_data)->clamp_consts) { priv->last_ps_const_clamped = ((struct arb_pshader_private *)ps->backend_data)->clamp_consts; - device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, 8); + priv->highest_dirty_ps_const = max(priv->highest_dirty_ps_const, 8); for(i = 0; i < 8; i++) { - context->pshader_const_dirty[i] = 1; + priv->pshader_const_dirty[i] = 1; } /* Also takes care of loading local constants */ shader_arb_load_constants(context, TRUE, FALSE); } else { - UINT rt_height = device->fb.render_targets[0]->resource.height; + UINT rt_height = state->fb->render_targets[0]->resource.height; shader_arb_ps_local_constants(compiled, context, state, rt_height); } @@ -4803,14 +4820,34 @@ static const struct wine_rb_functions sig_tree_functions = static HRESULT shader_arb_alloc(struct wined3d_device *device) { struct shader_arb_priv *priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*priv)); + + priv->vshader_const_dirty = HeapAlloc(GetProcessHeap(), 0, + sizeof(*priv->vshader_const_dirty) * device->d3d_vshader_constantF); + if (!priv->vshader_const_dirty) + goto fail; + memset(priv->vshader_const_dirty, 1, + sizeof(*priv->vshader_const_dirty) * device->d3d_vshader_constantF); + + priv->pshader_const_dirty = HeapAlloc(GetProcessHeap(), 0, + sizeof(*priv->pshader_const_dirty) * device->d3d_pshader_constantF); + if (!priv->pshader_const_dirty) + goto fail; + memset(priv->pshader_const_dirty, 1, + sizeof(*priv->pshader_const_dirty) * device->d3d_pshader_constantF); + if(wine_rb_init(&priv->signature_tree, &sig_tree_functions) == -1) { ERR("RB tree init failed\n"); - HeapFree(GetProcessHeap(), 0, priv); - return E_OUTOFMEMORY; + goto fail; } device->shader_priv = priv; return WINED3D_OK; + +fail: + HeapFree(GetProcessHeap(), 0, priv->pshader_const_dirty); + HeapFree(GetProcessHeap(), 0, priv->vshader_const_dirty); + HeapFree(GetProcessHeap(), 0, priv); + return E_OUTOFMEMORY; } static void release_signature(struct wine_rb_entry *entry, void *context) @@ -4850,12 +4887,17 @@ static void shader_arb_free(struct wined3d_device *device) LEAVE_GL(); wine_rb_destroy(&priv->signature_tree, release_signature, NULL); + HeapFree(GetProcessHeap(), 0, priv->pshader_const_dirty); + HeapFree(GetProcessHeap(), 0, priv->vshader_const_dirty); HeapFree(GetProcessHeap(), 0, device->shader_priv); } -static BOOL shader_arb_dirty_const(void) +static void shader_arb_context_destroyed(void *shader_priv, const struct wined3d_context *context) { - return TRUE; + struct shader_arb_priv *priv = shader_priv; + + if (priv->last_context == context) + priv->last_context = NULL; } static void shader_arb_get_caps(const struct wined3d_gl_info *gl_info, struct shader_caps *caps) @@ -4875,18 +4917,18 @@ static void shader_arb_get_caps(const struct wined3d_gl_info *gl_info, struct sh if (gl_info->supported[NV_VERTEX_PROGRAM3]) { - caps->VertexShaderVersion = WINED3DVS_VERSION(3,0); + caps->VertexShaderVersion = 3; TRACE_(d3d_caps)("Hardware vertex shader version 3.0 enabled (NV_VERTEX_PROGRAM3)\n"); } else if (vs_consts >= 256) { /* Shader Model 2.0 requires at least 256 vertex shader constants */ - caps->VertexShaderVersion = WINED3DVS_VERSION(2,0); + caps->VertexShaderVersion = 2; TRACE_(d3d_caps)("Hardware vertex shader version 2.0 enabled (ARB_PROGRAM)\n"); } else { - caps->VertexShaderVersion = WINED3DVS_VERSION(1,1); + caps->VertexShaderVersion = 1; TRACE_(d3d_caps)("Hardware vertex shader version 1.1 enabled (ARB_PROGRAM)\n"); } caps->MaxVertexShaderConst = vs_consts; @@ -4910,18 +4952,18 @@ static void shader_arb_get_caps(const struct wined3d_gl_info *gl_info, struct sh if (gl_info->supported[NV_FRAGMENT_PROGRAM2]) { - caps->PixelShaderVersion = WINED3DPS_VERSION(3,0); + caps->PixelShaderVersion = 3; TRACE_(d3d_caps)("Hardware pixel shader version 3.0 enabled (NV_FRAGMENT_PROGRAM2)\n"); } else if (ps_consts >= 32) { /* Shader Model 2.0 requires at least 32 pixel shader constants */ - caps->PixelShaderVersion = WINED3DPS_VERSION(2,0); + caps->PixelShaderVersion = 2; TRACE_(d3d_caps)("Hardware pixel shader version 2.0 enabled (ARB_PROGRAM)\n"); } else { - caps->PixelShaderVersion = WINED3DPS_VERSION(1,4); + caps->PixelShaderVersion = 1; TRACE_(d3d_caps)("Hardware pixel shader version 1.4 enabled (ARB_PROGRAM)\n"); } caps->PixelShader1xMaxValue = 8.0f; @@ -5011,10 +5053,12 @@ static const SHADER_HANDLER shader_arb_instruction_handler_table[WINED3DSIH_TABL /* WINED3DSIH_ENDIF */ shader_hw_endif, /* WINED3DSIH_ENDLOOP */ shader_hw_endloop, /* WINED3DSIH_ENDREP */ shader_hw_endrep, + /* WINED3DSIH_EQ */ NULL, /* WINED3DSIH_EXP */ shader_hw_scalar_op, /* WINED3DSIH_EXPP */ shader_hw_scalar_op, /* WINED3DSIH_FRC */ shader_hw_map2gl, /* WINED3DSIH_FTOI */ NULL, + /* WINED3DSIH_GE */ NULL, /* WINED3DSIH_IADD */ NULL, /* WINED3DSIH_IEQ */ NULL, /* WINED3DSIH_IF */ NULL /* Hardcoded into the shader */, @@ -5049,6 +5093,7 @@ static const SHADER_HANDLER shader_arb_instruction_handler_table[WINED3DSIH_TABL /* WINED3DSIH_RCP */ shader_hw_rcp, /* WINED3DSIH_REP */ shader_hw_rep, /* WINED3DSIH_RET */ shader_hw_ret, + /* WINED3DSIH_ROUND_NI */ NULL, /* WINED3DSIH_RSQ */ shader_hw_scalar_op, /* WINED3DSIH_SAMPLE */ NULL, /* WINED3DSIH_SAMPLE_GRAD */ NULL, @@ -5082,7 +5127,10 @@ static const SHADER_HANDLER shader_arb_instruction_handler_table[WINED3DSIH_TABL /* WINED3DSIH_TEXREG2AR */ pshader_hw_texreg2ar, /* WINED3DSIH_TEXREG2GB */ pshader_hw_texreg2gb, /* WINED3DSIH_TEXREG2RGB */ pshader_hw_texreg2rgb, + /* WINED3DSIH_UDIV */ NULL, + /* WINED3DSIH_USHR */ NULL, /* WINED3DSIH_UTOF */ NULL, + /* WINED3DSIH_XOR */ NULL, }; static BOOL get_bool_const(const struct wined3d_shader_instruction *ins, @@ -5090,15 +5138,15 @@ static BOOL get_bool_const(const struct wined3d_shader_instruction *ins, { const struct wined3d_shader_reg_maps *reg_maps = ins->ctx->reg_maps; BOOL vshader = shader_is_vshader_version(reg_maps->shader_version.type); + const struct wined3d_shader_lconst *constant; WORD bools = 0; WORD flag = (1 << idx); - const local_constant *constant; struct shader_arb_ctx_priv *priv = ins->ctx->backend_data; if (reg_maps->local_bool_consts & flag) { /* What good is a if(bool) with a hardcoded local constant? I don't know, but handle it */ - LIST_FOR_EACH_ENTRY(constant, &shader->constantsB, local_constant, entry) + LIST_FOR_EACH_ENTRY(constant, &shader->constantsB, struct wined3d_shader_lconst, entry) { if (constant->idx == idx) { @@ -5126,9 +5174,9 @@ static void get_loop_control_const(const struct wined3d_shader_instruction *ins, * type specific compile args. */ if (reg_maps->local_int_consts & (1 << idx)) { - const local_constant *constant; + const struct wined3d_shader_lconst *constant; - LIST_FOR_EACH_ENTRY(constant, &shader->constantsI, local_constant, entry) + LIST_FOR_EACH_ENTRY(constant, &shader->constantsI, struct wined3d_shader_lconst, entry) { if (constant->idx == idx) { @@ -5257,7 +5305,7 @@ static void free_recorded_instruction(struct list *list) static void shader_arb_handle_instruction(const struct wined3d_shader_instruction *ins) { SHADER_HANDLER hw_fct; struct shader_arb_ctx_priv *priv = ins->ctx->backend_data; - struct wined3d_shader *shader = ins->ctx->shader; + const struct wined3d_shader *shader = ins->ctx->shader; struct control_frame *control_frame; struct wined3d_shader_buffer *buffer = ins->ctx->buffer; BOOL bool_const; @@ -5485,7 +5533,7 @@ const struct wined3d_shader_backend_ops arb_program_shader_backend = shader_arb_destroy, shader_arb_alloc, shader_arb_free, - shader_arb_dirty_const, + shader_arb_context_destroyed, shader_arb_get_caps, shader_arb_color_fixup_supported, }; @@ -5605,37 +5653,36 @@ static void arbfp_get_caps(const struct wined3d_gl_info *gl_info, struct fragmen caps->MaxSimultaneousTextures = min(gl_info->limits.fragment_samplers, 8); } -static void state_texfactor_arbfp(DWORD state_id, - struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_texfactor_arbfp(struct wined3d_context *context, + const struct wined3d_state *state, DWORD state_id) { + struct wined3d_device *device = context->swapchain->device; const struct wined3d_gl_info *gl_info = context->gl_info; - const struct wined3d_state *state = &stateblock->state; - struct wined3d_device *device = stateblock->device; float col[4]; - /* Don't load the parameter if we're using an arbfp pixel shader, otherwise we'll overwrite - * application provided constants - */ + /* Don't load the parameter if we're using an arbfp pixel shader, + * otherwise we'll overwrite application provided constants. */ if (device->shader_backend == &arb_program_shader_backend) { + struct shader_arb_priv *priv; + if (use_ps(state)) return; - context->pshader_const_dirty[ARB_FFP_CONST_TFACTOR] = 1; - device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_TFACTOR + 1); + priv = device->shader_priv; + priv->pshader_const_dirty[ARB_FFP_CONST_TFACTOR] = 1; + priv->highest_dirty_ps_const = max(priv->highest_dirty_ps_const, ARB_FFP_CONST_TFACTOR + 1); } - D3DCOLORTOGLFLOAT4(state->render_states[WINED3DRS_TEXTUREFACTOR], col); + D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_TEXTUREFACTOR], col); GL_EXTCALL(glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_TFACTOR, col)); checkGLcall("glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_TFACTOR, col)"); - } -static void state_arb_specularenable(DWORD state_id, - struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_arb_specularenable(struct wined3d_context *context, + const struct wined3d_state *state, DWORD state_id) { + struct wined3d_device *device = context->swapchain->device; const struct wined3d_gl_info *gl_info = context->gl_info; - const struct wined3d_state *state = &stateblock->state; - struct wined3d_device *device = stateblock->device; float col[4]; /* Don't load the parameter if we're using an arbfp pixel shader, otherwise we'll overwrite @@ -5643,13 +5690,16 @@ static void state_arb_specularenable(DWORD state_id, */ if (device->shader_backend == &arb_program_shader_backend) { + struct shader_arb_priv *priv; + if (use_ps(state)) return; - context->pshader_const_dirty[ARB_FFP_CONST_SPECULAR_ENABLE] = 1; - device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_SPECULAR_ENABLE + 1); + priv = device->shader_priv; + priv->pshader_const_dirty[ARB_FFP_CONST_SPECULAR_ENABLE] = 1; + priv->highest_dirty_ps_const = max(priv->highest_dirty_ps_const, ARB_FFP_CONST_SPECULAR_ENABLE + 1); } - if (state->render_states[WINED3DRS_SPECULARENABLE]) + if (state->render_states[WINED3D_RS_SPECULARENABLE]) { /* The specular color has no alpha */ col[0] = 1.0f; col[1] = 1.0f; @@ -5662,12 +5712,11 @@ static void state_arb_specularenable(DWORD state_id, checkGLcall("glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_SPECULAR_ENABLE, col)"); } -static void set_bumpmat_arbfp(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void set_bumpmat_arbfp(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); + struct wined3d_device *device = context->swapchain->device; const struct wined3d_gl_info *gl_info = context->gl_info; - const struct wined3d_state *state = &stateblock->state; - struct wined3d_device *device = stateblock->device; float mat[2][2]; if (use_ps(state)) @@ -5678,34 +5727,36 @@ static void set_bumpmat_arbfp(DWORD state_id, struct wined3d_stateblock *statebl * anyway */ if (!isStateDirty(context, STATE_PIXELSHADERCONSTANT)) - stateblock_apply_state(STATE_PIXELSHADERCONSTANT, stateblock, context); + context_apply_state(context, state, STATE_PIXELSHADERCONSTANT); } if(device->shader_backend == &arb_program_shader_backend) { /* Exit now, don't set the bumpmat below, otherwise we may overwrite pixel shader constants */ return; } - } else if(device->shader_backend == &arb_program_shader_backend) { - context->pshader_const_dirty[ARB_FFP_CONST_BUMPMAT(stage)] = 1; - device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_BUMPMAT(stage) + 1); + } + else if (device->shader_backend == &arb_program_shader_backend) + { + struct shader_arb_priv *priv = device->shader_priv; + priv->pshader_const_dirty[ARB_FFP_CONST_BUMPMAT(stage)] = 1; + priv->highest_dirty_ps_const = max(priv->highest_dirty_ps_const, ARB_FFP_CONST_BUMPMAT(stage) + 1); } - mat[0][0] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVMAT00]); - mat[0][1] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVMAT01]); - mat[1][0] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVMAT10]); - mat[1][1] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVMAT11]); + mat[0][0] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT00]); + mat[0][1] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT01]); + mat[1][0] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT10]); + mat[1][1] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT11]); GL_EXTCALL(glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_BUMPMAT(stage), &mat[0][0])); checkGLcall("glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_BUMPMAT(stage), &mat[0][0])"); } -static void tex_bumpenvlum_arbfp(DWORD state_id, - struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void tex_bumpenvlum_arbfp(struct wined3d_context *context, + const struct wined3d_state *state, DWORD state_id) { DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); + struct wined3d_device *device = context->swapchain->device; const struct wined3d_gl_info *gl_info = context->gl_info; - const struct wined3d_state *state = &stateblock->state; - struct wined3d_device *device = stateblock->device; float param[4]; if (use_ps(state)) @@ -5716,20 +5767,23 @@ static void tex_bumpenvlum_arbfp(DWORD state_id, * isn't scheduled anyway */ if (!isStateDirty(context, STATE_PIXELSHADERCONSTANT)) - stateblock_apply_state(STATE_PIXELSHADERCONSTANT, stateblock, context); + context_apply_state(context, state, STATE_PIXELSHADERCONSTANT); } if(device->shader_backend == &arb_program_shader_backend) { /* Exit now, don't set the bumpmat below, otherwise we may overwrite pixel shader constants */ return; } - } else if(device->shader_backend == &arb_program_shader_backend) { - context->pshader_const_dirty[ARB_FFP_CONST_LUMINANCE(stage)] = 1; - device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_LUMINANCE(stage) + 1); + } + else if (device->shader_backend == &arb_program_shader_backend) + { + struct shader_arb_priv *priv = device->shader_priv; + priv->pshader_const_dirty[ARB_FFP_CONST_LUMINANCE(stage)] = 1; + priv->highest_dirty_ps_const = max(priv->highest_dirty_ps_const, ARB_FFP_CONST_LUMINANCE(stage) + 1); } - param[0] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVLSCALE]); - param[1] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVLOFFSET]); + param[0] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_LSCALE]); + param[1] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_LOFFSET]); param[2] = 0.0f; param[3] = 0.0f; @@ -5827,22 +5881,24 @@ static void gen_ffp_instr(struct wined3d_shader_buffer *buffer, unsigned int sta arg1 = get_argreg(buffer, 1, stage, dw_arg1); arg2 = get_argreg(buffer, 2, stage, dw_arg2); - switch(op) { - case WINED3DTOP_DISABLE: - if (!stage) shader_addline(buffer, "MOV %s%s, fragment.color.primary;\n", dstreg, dstmask); + switch (op) + { + case WINED3D_TOP_DISABLE: + if (!stage) + shader_addline(buffer, "MOV %s%s, fragment.color.primary;\n", dstreg, dstmask); break; - case WINED3DTOP_SELECTARG2: + case WINED3D_TOP_SELECT_ARG2: arg1 = arg2; /* FALLTHROUGH */ - case WINED3DTOP_SELECTARG1: + case WINED3D_TOP_SELECT_ARG1: shader_addline(buffer, "MOV %s%s, %s;\n", dstreg, dstmask, arg1); break; - case WINED3DTOP_MODULATE4X: + case WINED3D_TOP_MODULATE_4X: mul = 2; /* FALLTHROUGH */ - case WINED3DTOP_MODULATE2X: + case WINED3D_TOP_MODULATE_2X: mul *= 2; if (!strcmp(dstreg, "result.color")) { @@ -5850,11 +5906,11 @@ static void gen_ffp_instr(struct wined3d_shader_buffer *buffer, unsigned int sta mul_final_dest = TRUE; } /* FALLTHROUGH */ - case WINED3DTOP_MODULATE: + case WINED3D_TOP_MODULATE: shader_addline(buffer, "MUL %s%s, %s, %s;\n", dstreg, dstmask, arg1, arg2); break; - case WINED3DTOP_ADDSIGNED2X: + case WINED3D_TOP_ADD_SIGNED_2X: mul = 2; if (!strcmp(dstreg, "result.color")) { @@ -5862,41 +5918,41 @@ static void gen_ffp_instr(struct wined3d_shader_buffer *buffer, unsigned int sta mul_final_dest = TRUE; } /* FALLTHROUGH */ - case WINED3DTOP_ADDSIGNED: + case WINED3D_TOP_ADD_SIGNED: shader_addline(buffer, "SUB arg2, %s, const.w;\n", arg2); arg2 = "arg2"; /* FALLTHROUGH */ - case WINED3DTOP_ADD: + case WINED3D_TOP_ADD: shader_addline(buffer, "ADD_SAT %s%s, %s, %s;\n", dstreg, dstmask, arg1, arg2); break; - case WINED3DTOP_SUBTRACT: + case WINED3D_TOP_SUBTRACT: shader_addline(buffer, "SUB_SAT %s%s, %s, %s;\n", dstreg, dstmask, arg1, arg2); break; - case WINED3DTOP_ADDSMOOTH: + case WINED3D_TOP_ADD_SMOOTH: shader_addline(buffer, "SUB arg1, const.x, %s;\n", arg1); shader_addline(buffer, "MAD_SAT %s%s, arg1, %s, %s;\n", dstreg, dstmask, arg2, arg1); break; - case WINED3DTOP_BLENDCURRENTALPHA: + case WINED3D_TOP_BLEND_CURRENT_ALPHA: arg0 = get_argreg(buffer, 0, stage, WINED3DTA_CURRENT); shader_addline(buffer, "LRP %s%s, %s.w, %s, %s;\n", dstreg, dstmask, arg0, arg1, arg2); break; - case WINED3DTOP_BLENDFACTORALPHA: + case WINED3D_TOP_BLEND_FACTOR_ALPHA: arg0 = get_argreg(buffer, 0, stage, WINED3DTA_TFACTOR); shader_addline(buffer, "LRP %s%s, %s.w, %s, %s;\n", dstreg, dstmask, arg0, arg1, arg2); break; - case WINED3DTOP_BLENDTEXTUREALPHA: + case WINED3D_TOP_BLEND_TEXTURE_ALPHA: arg0 = get_argreg(buffer, 0, stage, WINED3DTA_TEXTURE); shader_addline(buffer, "LRP %s%s, %s.w, %s, %s;\n", dstreg, dstmask, arg0, arg1, arg2); break; - case WINED3DTOP_BLENDDIFFUSEALPHA: + case WINED3D_TOP_BLEND_DIFFUSE_ALPHA: arg0 = get_argreg(buffer, 0, stage, WINED3DTA_DIFFUSE); shader_addline(buffer, "LRP %s%s, %s.w, %s, %s;\n", dstreg, dstmask, arg0, arg1, arg2); break; - case WINED3DTOP_BLENDTEXTUREALPHAPM: + case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM: arg0 = get_argreg(buffer, 0, stage, WINED3DTA_TEXTURE); shader_addline(buffer, "SUB arg0.w, const.x, %s.w;\n", arg0); shader_addline(buffer, "MAD_SAT %s%s, %s, arg0.w, %s;\n", dstreg, dstmask, arg2, arg1); @@ -5904,22 +5960,22 @@ static void gen_ffp_instr(struct wined3d_shader_buffer *buffer, unsigned int sta /* D3DTOP_PREMODULATE ???? */ - case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR: + case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR: shader_addline(buffer, "SUB arg0.w, const.x, %s;\n", arg1); shader_addline(buffer, "MAD_SAT %s%s, arg0.w, %s, %s;\n", dstreg, dstmask, arg2, arg1); break; - case WINED3DTOP_MODULATEALPHA_ADDCOLOR: + case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR: shader_addline(buffer, "MAD_SAT %s%s, %s.w, %s, %s;\n", dstreg, dstmask, arg1, arg2, arg1); break; - case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA: + case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA: shader_addline(buffer, "SUB arg0, const.x, %s;\n", arg1); shader_addline(buffer, "MAD_SAT %s%s, arg0, %s, %s.w;\n", dstreg, dstmask, arg2, arg1); break; - case WINED3DTOP_MODULATECOLOR_ADDALPHA: + case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA: shader_addline(buffer, "MAD_SAT %s%s, %s, %s, %s.w;\n", dstreg, dstmask, arg1, arg2, arg1); break; - case WINED3DTOP_DOTPRODUCT3: + case WINED3D_TOP_DOTPRODUCT3: mul = 4; if (!strcmp(dstreg, "result.color")) { @@ -5931,17 +5987,17 @@ static void gen_ffp_instr(struct wined3d_shader_buffer *buffer, unsigned int sta shader_addline(buffer, "DP3_SAT %s%s, arg1, arg2;\n", dstreg, dstmask); break; - case WINED3DTOP_MULTIPLYADD: + case WINED3D_TOP_MULTIPLY_ADD: shader_addline(buffer, "MAD_SAT %s%s, %s, %s, %s;\n", dstreg, dstmask, arg1, arg2, arg0); break; - case WINED3DTOP_LERP: + case WINED3D_TOP_LERP: /* The msdn is not quite right here */ shader_addline(buffer, "LRP %s%s, %s, %s, %s;\n", dstreg, dstmask, arg0, arg1, arg2); break; - case WINED3DTOP_BUMPENVMAP: - case WINED3DTOP_BUMPENVMAPLUMINANCE: + case WINED3D_TOP_BUMPENVMAP: + case WINED3D_TOP_BUMPENVMAP_LUMINANCE: /* Those are handled in the first pass of the shader(generation pass 1 and 2) already */ break; @@ -5956,14 +6012,14 @@ static void gen_ffp_instr(struct wined3d_shader_buffer *buffer, unsigned int sta } } -static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, struct wined3d_stateblock *stateblock) +static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, const struct wined3d_gl_info *gl_info) { - const struct wined3d_gl_info *gl_info = &stateblock->device->adapter->gl_info; unsigned int stage; struct wined3d_shader_buffer buffer; BOOL tex_read[MAX_TEXTURES] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE}; BOOL bump_used[MAX_TEXTURES] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE}; BOOL luminance_used[MAX_TEXTURES] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE}; + UINT lowest_disabled_stage; const char *textype; const char *instr, *sat; char colorcor_dst[8]; @@ -5975,8 +6031,10 @@ static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, str GLint pos; /* Find out which textures are read */ - for(stage = 0; stage < MAX_TEXTURES; stage++) { - if(settings->op[stage].cop == WINED3DTOP_DISABLE) break; + for (stage = 0; stage < MAX_TEXTURES; ++stage) + { + if (settings->op[stage].cop == WINED3D_TOP_DISABLE) + break; arg0 = settings->op[stage].carg0 & WINED3DTA_SELECTMASK; arg1 = settings->op[stage].carg1 & WINED3DTA_SELECTMASK; arg2 = settings->op[stage].carg2 & WINED3DTA_SELECTMASK; @@ -5984,17 +6042,23 @@ static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, str if(arg1 == WINED3DTA_TEXTURE) tex_read[stage] = TRUE; if(arg2 == WINED3DTA_TEXTURE) tex_read[stage] = TRUE; - if(settings->op[stage].cop == WINED3DTOP_BLENDTEXTUREALPHA) tex_read[stage] = TRUE; - if(settings->op[stage].cop == WINED3DTOP_BLENDTEXTUREALPHAPM) tex_read[stage] = TRUE; - if(settings->op[stage].cop == WINED3DTOP_BUMPENVMAP) { + if (settings->op[stage].cop == WINED3D_TOP_BLEND_TEXTURE_ALPHA) + tex_read[stage] = TRUE; + if (settings->op[stage].cop == WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM) + tex_read[stage] = TRUE; + if (settings->op[stage].cop == WINED3D_TOP_BUMPENVMAP) + { bump_used[stage] = TRUE; tex_read[stage] = TRUE; } - if(settings->op[stage].cop == WINED3DTOP_BUMPENVMAPLUMINANCE) { + if (settings->op[stage].cop == WINED3D_TOP_BUMPENVMAP_LUMINANCE) + { bump_used[stage] = TRUE; tex_read[stage] = TRUE; luminance_used[stage] = TRUE; - } else if(settings->op[stage].cop == WINED3DTOP_BLENDFACTORALPHA) { + } + else if (settings->op[stage].cop == WINED3D_TOP_BLEND_FACTOR_ALPHA) + { tfactor_used = TRUE; } @@ -6007,7 +6071,8 @@ static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, str tempreg_used = TRUE; } - if(settings->op[stage].aop == WINED3DTOP_DISABLE) continue; + if (settings->op[stage].aop == WINED3D_TOP_DISABLE) + continue; arg0 = settings->op[stage].aarg0 & WINED3DTA_SELECTMASK; arg1 = settings->op[stage].aarg1 & WINED3DTA_SELECTMASK; arg2 = settings->op[stage].aarg2 & WINED3DTA_SELECTMASK; @@ -6022,6 +6087,7 @@ static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, str tfactor_used = TRUE; } } + lowest_disabled_stage = stage; /* Shader header */ if (!shader_buffer_init(&buffer)) @@ -6067,12 +6133,14 @@ static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, str srgb_sub_high, 0.0, 0.0, 0.0); } - if (ffp_clip_emul(&stateblock->state) && settings->emul_clipplanes) + if (lowest_disabled_stage < 7 && settings->emul_clipplanes) shader_addline(&buffer, "KIL fragment.texcoord[7];\n"); /* Generate texture sampling instructions) */ - for(stage = 0; stage < MAX_TEXTURES && settings->op[stage].cop != WINED3DTOP_DISABLE; stage++) { - if(!tex_read[stage]) continue; + for (stage = 0; stage < MAX_TEXTURES && settings->op[stage].cop != WINED3D_TOP_DISABLE; ++stage) + { + if (!tex_read[stage]) + continue; switch(settings->op[stage].tex_type) { case tex_1d: textype = "1D"; break; @@ -6083,12 +6151,11 @@ static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, str default: textype = "unexpected_textype"; break; } - if(settings->op[stage].cop == WINED3DTOP_BUMPENVMAP || - settings->op[stage].cop == WINED3DTOP_BUMPENVMAPLUMINANCE) { + if (settings->op[stage].cop == WINED3D_TOP_BUMPENVMAP + || settings->op[stage].cop == WINED3D_TOP_BUMPENVMAP_LUMINANCE) sat = ""; - } else { + else sat = "_SAT"; - } if(settings->op[stage].projected == proj_none) { instr = "TEX"; @@ -6100,9 +6167,10 @@ static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, str instr = "TXP"; } - if(stage > 0 && - (settings->op[stage - 1].cop == WINED3DTOP_BUMPENVMAP || - settings->op[stage - 1].cop == WINED3DTOP_BUMPENVMAPLUMINANCE)) { + if (stage > 0 + && (settings->op[stage - 1].cop == WINED3D_TOP_BUMPENVMAP + || settings->op[stage - 1].cop == WINED3D_TOP_BUMPENVMAP_LUMINANCE)) + { shader_addline(&buffer, "SWZ arg1, bumpmat%u, x, z, 0, 0;\n", stage - 1); shader_addline(&buffer, "DP3 ret.x, arg1, tex%u;\n", stage - 1); shader_addline(&buffer, "SWZ arg1, bumpmat%u, y, w, 0, 0;\n", stage - 1); @@ -6124,8 +6192,9 @@ static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, str } shader_addline(&buffer, "%s%s tex%u, ret, texture[%u], %s;\n", - instr, sat, stage, stage, textype); - if(settings->op[stage - 1].cop == WINED3DTOP_BUMPENVMAPLUMINANCE) { + instr, sat, stage, stage, textype); + if (settings->op[stage - 1].cop == WINED3D_TOP_BUMPENVMAP_LUMINANCE) + { shader_addline(&buffer, "MAD_SAT ret.x, tex%u.z, luminance%u.x, luminance%u.y;\n", stage - 1, stage - 1, stage - 1); shader_addline(&buffer, "MUL tex%u, tex%u, ret.x;\n", stage, stage); @@ -6148,32 +6217,33 @@ static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, str /* Generate the main shader */ for (stage = 0; stage < MAX_TEXTURES; ++stage) { - if (settings->op[stage].cop == WINED3DTOP_DISABLE) + if (settings->op[stage].cop == WINED3D_TOP_DISABLE) { - if (!stage) final_combiner_src = "fragment.color.primary"; + if (!stage) + final_combiner_src = "fragment.color.primary"; break; } - if(settings->op[stage].cop == WINED3DTOP_SELECTARG1 && - settings->op[stage].aop == WINED3DTOP_SELECTARG1) { + if (settings->op[stage].cop == WINED3D_TOP_SELECT_ARG1 + && settings->op[stage].aop == WINED3D_TOP_SELECT_ARG1) op_equal = settings->op[stage].carg1 == settings->op[stage].aarg1; - } else if(settings->op[stage].cop == WINED3DTOP_SELECTARG1 && - settings->op[stage].aop == WINED3DTOP_SELECTARG2) { + else if (settings->op[stage].cop == WINED3D_TOP_SELECT_ARG1 + && settings->op[stage].aop == WINED3D_TOP_SELECT_ARG2) op_equal = settings->op[stage].carg1 == settings->op[stage].aarg2; - } else if(settings->op[stage].cop == WINED3DTOP_SELECTARG2 && - settings->op[stage].aop == WINED3DTOP_SELECTARG1) { + else if (settings->op[stage].cop == WINED3D_TOP_SELECT_ARG2 + && settings->op[stage].aop == WINED3D_TOP_SELECT_ARG1) op_equal = settings->op[stage].carg2 == settings->op[stage].aarg1; - } else if(settings->op[stage].cop == WINED3DTOP_SELECTARG2 && - settings->op[stage].aop == WINED3DTOP_SELECTARG2) { + else if (settings->op[stage].cop == WINED3D_TOP_SELECT_ARG2 + && settings->op[stage].aop == WINED3D_TOP_SELECT_ARG2) op_equal = settings->op[stage].carg2 == settings->op[stage].aarg2; - } else { - op_equal = settings->op[stage].aop == settings->op[stage].cop && - settings->op[stage].carg0 == settings->op[stage].aarg0 && - settings->op[stage].carg1 == settings->op[stage].aarg1 && - settings->op[stage].carg2 == settings->op[stage].aarg2; - } + else + op_equal = settings->op[stage].aop == settings->op[stage].cop + && settings->op[stage].carg0 == settings->op[stage].aarg0 + && settings->op[stage].carg1 == settings->op[stage].aarg1 + && settings->op[stage].carg2 == settings->op[stage].aarg2; - if(settings->op[stage].aop == WINED3DTOP_DISABLE) { + if (settings->op[stage].aop == WINED3D_TOP_DISABLE) + { gen_ffp_instr(&buffer, stage, TRUE, FALSE, settings->op[stage].dst, settings->op[stage].cop, settings->op[stage].carg0, settings->op[stage].carg1, settings->op[stage].carg2); @@ -6233,11 +6303,10 @@ static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, str return ret; } -static void fragment_prog_arbfp(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void fragment_prog_arbfp(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { + const struct wined3d_device *device = context->swapchain->device; const struct wined3d_gl_info *gl_info = context->gl_info; - const struct wined3d_state *state = &stateblock->state; - struct wined3d_device *device = stateblock->device; struct shader_arb_priv *priv = device->fragment_priv; BOOL use_vshader = use_vs(state); BOOL use_pshader = use_ps(state); @@ -6245,25 +6314,33 @@ static void fragment_prog_arbfp(DWORD state_id, struct wined3d_stateblock *state const struct arbfp_ffp_desc *desc; unsigned int i; - TRACE("state_id %#x, stateblock %p, context %p\n", state_id, stateblock, context); + TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id); - if(isStateDirty(context, STATE_RENDER(WINED3DRS_FOGENABLE))) { - if(!use_pshader && device->shader_backend == &arb_program_shader_backend && context->last_was_pshader) { - /* Reload fixed function constants since they collide with the pixel shader constants */ - for(i = 0; i < MAX_TEXTURES; i++) { - set_bumpmat_arbfp(STATE_TEXTURESTAGE(i, WINED3DTSS_BUMPENVMAT00), stateblock, context); + if (isStateDirty(context, STATE_RENDER(WINED3D_RS_FOGENABLE))) + { + if (!use_pshader && device->shader_backend == &arb_program_shader_backend && context->last_was_pshader) + { + /* Reload fixed function constants since they collide with the + * pixel shader constants. */ + for (i = 0; i < MAX_TEXTURES; ++i) + { + set_bumpmat_arbfp(context, state, STATE_TEXTURESTAGE(i, WINED3D_TSS_BUMPENV_MAT00)); } - state_texfactor_arbfp(STATE_RENDER(WINED3DRS_TEXTUREFACTOR), stateblock, context); - state_arb_specularenable(STATE_RENDER(WINED3DRS_SPECULARENABLE), stateblock, context); - } else if(use_pshader && !isStateDirty(context, device->StateTable[STATE_VSHADER].representative)) { + state_texfactor_arbfp(context, state, STATE_RENDER(WINED3D_RS_TEXTUREFACTOR)); + state_arb_specularenable(context, state, STATE_RENDER(WINED3D_RS_SPECULARENABLE)); + } + else if (use_pshader && !isStateDirty(context, context->state_table[STATE_VSHADER].representative)) + { device->shader_backend->shader_select(context, use_pshader, use_vshader); } return; } - if(!use_pshader) { - /* Find or create a shader implementing the fixed function pipeline settings, then activate it */ - gen_ffp_frag_op(stateblock, &settings, FALSE); + if (!use_pshader) + { + /* Find or create a shader implementing the fixed function pipeline + * settings, then activate it. */ + gen_ffp_frag_op(device, state, &settings, FALSE); desc = (const struct arbfp_ffp_desc *)find_ffp_frag_shader(&priv->fragment_shaders, &settings); if(!desc) { struct arbfp_ffp_desc *new_desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_desc)); @@ -6275,12 +6352,13 @@ static void fragment_prog_arbfp(DWORD state_id, struct wined3d_stateblock *state new_desc->num_textures_used = 0; for (i = 0; i < gl_info->limits.texture_stages; ++i) { - if(settings.op[i].cop == WINED3DTOP_DISABLE) break; + if (settings.op[i].cop == WINED3D_TOP_DISABLE) + break; new_desc->num_textures_used = i; } memcpy(&new_desc->parent.settings, &settings, sizeof(settings)); - new_desc->shader = gen_arbfp_ffp_shader(&settings, stateblock); + new_desc->shader = gen_arbfp_ffp_shader(&settings, gl_info); add_ffp_frag_shader(&priv->fragment_shaders, &new_desc->parent); TRACE("Allocated fixed function replacement shader descriptor %p\n", new_desc); desc = new_desc; @@ -6294,13 +6372,16 @@ static void fragment_prog_arbfp(DWORD state_id, struct wined3d_stateblock *state checkGLcall("glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, desc->shader)"); priv->current_fprogram_id = desc->shader; - if(device->shader_backend == &arb_program_shader_backend && context->last_was_pshader) { - /* Reload fixed function constants since they collide with the pixel shader constants */ - for(i = 0; i < MAX_TEXTURES; i++) { - set_bumpmat_arbfp(STATE_TEXTURESTAGE(i, WINED3DTSS_BUMPENVMAT00), stateblock, context); + if (device->shader_backend == &arb_program_shader_backend && context->last_was_pshader) + { + /* Reload fixed function constants since they collide with the + * pixel shader constants. */ + for (i = 0; i < MAX_TEXTURES; ++i) + { + set_bumpmat_arbfp(context, state, STATE_TEXTURESTAGE(i, WINED3D_TSS_BUMPENV_MAT00)); } - state_texfactor_arbfp(STATE_RENDER(WINED3DRS_TEXTUREFACTOR), stateblock, context); - state_arb_specularenable(STATE_RENDER(WINED3DRS_SPECULARENABLE), stateblock, context); + state_texfactor_arbfp(context, state, STATE_RENDER(WINED3D_RS_TEXTUREFACTOR)); + state_arb_specularenable(context, state, STATE_RENDER(WINED3D_RS_SPECULARENABLE)); } context->last_was_pshader = FALSE; } else { @@ -6316,35 +6397,37 @@ static void fragment_prog_arbfp(DWORD state_id, struct wined3d_stateblock *state * Don't call shader_select if the vertex shader is dirty, because it will be called later on by the vertex * shader handler */ - if(!isStateDirty(context, device->StateTable[STATE_VSHADER].representative)) { + if (!isStateDirty(context, context->state_table[STATE_VSHADER].representative)) + { device->shader_backend->shader_select(context, use_pshader, use_vshader); if (!isStateDirty(context, STATE_VERTEXSHADERCONSTANT) && (use_vshader || use_pshader)) - stateblock_apply_state(STATE_VERTEXSHADERCONSTANT, stateblock, context); + context_apply_state(context, state, STATE_VERTEXSHADERCONSTANT); } - if (use_pshader) stateblock_apply_state(STATE_PIXELSHADERCONSTANT, stateblock, context); + if (use_pshader) + context_apply_state(context, state, STATE_PIXELSHADERCONSTANT); } -/* We can't link the fog states to the fragment state directly since the vertex pipeline links them - * to FOGENABLE. A different linking in different pipeline parts can't be expressed in the combined - * state table, so we need to handle that with a forwarding function. The other invisible side effect - * is that changing the fog start and fog end(which links to FOGENABLE in vertex) results in the - * fragment_prog_arbfp function being called because FOGENABLE is dirty, which calls this function here - */ -static void state_arbfp_fog(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +/* We can't link the fog states to the fragment state directly since the + * vertex pipeline links them to FOGENABLE. A different linking in different + * pipeline parts can't be expressed in the combined state table, so we need + * to handle that with a forwarding function. The other invisible side effect + * is that changing the fog start and fog end (which links to FOGENABLE in + * vertex) results in the fragment_prog_arbfp function being called because + * FOGENABLE is dirty, which calls this function here. */ +static void state_arbfp_fog(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - const struct wined3d_state *state = &stateblock->state; enum fogsource new_source; - TRACE("state_id %#x, stateblock %p, context %p\n", state_id, stateblock, context); + TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id); - if(!isStateDirty(context, STATE_PIXELSHADER)) { - fragment_prog_arbfp(state_id, stateblock, context); - } + if (!isStateDirty(context, STATE_PIXELSHADER)) + fragment_prog_arbfp(context, state, state_id); - if (!state->render_states[WINED3DRS_FOGENABLE]) return; + if (!state->render_states[WINED3D_RS_FOGENABLE]) + return; - if (state->render_states[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) + if (state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE) { if (use_vs(state)) { @@ -6352,166 +6435,171 @@ static void state_arbfp_fog(DWORD state_id, struct wined3d_stateblock *statebloc } else { - if (state->render_states[WINED3DRS_FOGVERTEXMODE] == WINED3DFOG_NONE || context->last_was_rhw) + if (state->render_states[WINED3D_RS_FOGVERTEXMODE] == WINED3D_FOG_NONE || context->last_was_rhw) new_source = FOGSOURCE_COORD; else new_source = FOGSOURCE_FFP; } - } else { + } + else + { new_source = FOGSOURCE_FFP; } - if(new_source != context->fog_source) { + + if (new_source != context->fog_source) + { context->fog_source = new_source; - state_fogstartend(STATE_RENDER(WINED3DRS_FOGSTART), stateblock, context); + state_fogstartend(context, state, STATE_RENDER(WINED3D_RS_FOGSTART)); } } -static void textransform(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void textransform(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { if (!isStateDirty(context, STATE_PIXELSHADER)) - fragment_prog_arbfp(state, stateblock, context); + fragment_prog_arbfp(context, state, state_id); } -static const struct StateEntryTemplate arbfp_fragmentstate_template[] = { - {STATE_RENDER(WINED3DRS_TEXTUREFACTOR), { STATE_RENDER(WINED3DRS_TEXTUREFACTOR), state_texfactor_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_RESULTARG), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), set_bumpmat_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVLSCALE), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlum_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVLOFFSET), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVLSCALE), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_RESULTARG), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), set_bumpmat_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVLSCALE), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlum_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVLOFFSET), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVLSCALE), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_RESULTARG), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), set_bumpmat_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVLSCALE), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlum_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVLOFFSET), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVLSCALE), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_RESULTARG), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), set_bumpmat_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVLSCALE), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlum_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVLOFFSET), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVLSCALE), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_RESULTARG), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), set_bumpmat_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVLSCALE), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlum_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVLOFFSET), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVLSCALE), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_RESULTARG), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), set_bumpmat_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVLSCALE), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlum_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVLOFFSET), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVLSCALE), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_RESULTARG), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), set_bumpmat_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVLSCALE), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlum_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVLOFFSET), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVLSCALE), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_RESULTARG), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), set_bumpmat_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVLSCALE), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlum_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVLOFFSET), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVLSCALE), NULL }, WINED3D_GL_EXT_NONE }, +static const struct StateEntryTemplate arbfp_fragmentstate_template[] = +{ + {STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), state_texfactor_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_RESULT_ARG), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), tex_bumpenvlum_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_RESULT_ARG), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), tex_bumpenvlum_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_RESULT_ARG), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), tex_bumpenvlum_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_RESULT_ARG), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), tex_bumpenvlum_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_RESULT_ARG), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), tex_bumpenvlum_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_RESULT_ARG), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), tex_bumpenvlum_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_RESULT_ARG), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), tex_bumpenvlum_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG1), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG2), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG0), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_RESULT_ARG), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), tex_bumpenvlum_arbfp }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE }, {STATE_PIXELSHADER, { STATE_PIXELSHADER, fragment_prog_arbfp }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_FOGENABLE), { STATE_RENDER(WINED3DRS_FOGENABLE), state_arbfp_fog }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_FOGTABLEMODE), { STATE_RENDER(WINED3DRS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_FOGVERTEXMODE), { STATE_RENDER(WINED3DRS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_FOGSTART), { STATE_RENDER(WINED3DRS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_FOGEND), { STATE_RENDER(WINED3DRS_FOGSTART), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_SRGBWRITEENABLE), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_FOGCOLOR), { STATE_RENDER(WINED3DRS_FOGCOLOR), state_fogcolor }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_FOGDENSITY), { STATE_RENDER(WINED3DRS_FOGDENSITY), state_fogdensity }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(0, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(1, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(2, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(3, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(4, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(5, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(6, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(7, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_SPECULARENABLE), { STATE_RENDER(WINED3DRS_SPECULARENABLE), state_arb_specularenable}, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_FOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), state_arbfp_fog }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_FOGTABLEMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_FOGVERTEXMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_FOGSTART), { STATE_RENDER(WINED3D_RS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_FOGEND), { STATE_RENDER(WINED3D_RS_FOGSTART), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_FOGCOLOR), { STATE_RENDER(WINED3D_RS_FOGCOLOR), state_fogcolor }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_FOGDENSITY), { STATE_RENDER(WINED3D_RS_FOGDENSITY), state_fogdensity }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_SPECULARENABLE), { STATE_RENDER(WINED3D_RS_SPECULARENABLE), state_arb_specularenable}, WINED3D_GL_EXT_NONE }, {0 /* Terminate */, { 0, 0 }, WINED3D_GL_EXT_NONE }, }; @@ -6868,7 +6956,7 @@ static GLuint gen_p8_shader(struct arbfp_blit_priv *priv, } /* Context activation is done by the caller. */ -static void upload_palette(struct wined3d_surface *surface) +static void upload_palette(const struct wined3d_surface *surface, struct wined3d_context *context) { BYTE table[256][4]; struct wined3d_device *device = surface->resource.device; @@ -6879,6 +6967,13 @@ static void upload_palette(struct wined3d_surface *surface) d3dfmt_p8_init_palette(surface, table, colorkey); ENTER_GL(); + + if (gl_info->supported[APPLE_CLIENT_STORAGE]) + { + glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE); + checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)"); + } + if (!priv->palette_texture) glGenTextures(1, &priv->palette_texture); @@ -6892,11 +6987,17 @@ static void upload_palette(struct wined3d_surface *surface) glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); /* Upload the palette */ - /* TODO: avoid unneeed uploads in the future by adding some SFLAG_PALETTE_DIRTY mechanism */ + /* TODO: avoid unneeded uploads in the future by adding some SFLAG_PALETTE_DIRTY mechanism */ glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, table); + if (gl_info->supported[APPLE_CLIENT_STORAGE]) + { + glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE); + checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)"); + } + /* Switch back to unit 0 in which the 2D texture will be stored. */ - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0)); + context_active_texture(context, gl_info, 0); LEAVE_GL(); } @@ -7057,13 +7158,23 @@ static GLuint gen_yuv_shader(struct arbfp_blit_priv *priv, const struct wined3d_ } /* Context activation is done by the caller. */ -static HRESULT arbfp_blit_set(void *blit_priv, const struct wined3d_gl_info *gl_info, struct wined3d_surface *surface) +static HRESULT arbfp_blit_set(void *blit_priv, struct wined3d_context *context, const struct wined3d_surface *surface) { GLenum shader; float size[4] = {(float) surface->pow2Width, (float) surface->pow2Height, 1.0f, 1.0f}; struct arbfp_blit_priv *priv = blit_priv; enum complex_fixup fixup; GLenum textype = surface->texture_target; + const struct wined3d_gl_info *gl_info = context->gl_info; + + if (surface->flags & SFLAG_CONVERTED) + { + ENTER_GL(); + glEnable(textype); + checkGLcall("glEnable(textype)"); + LEAVE_GL(); + return WINED3D_OK; + } if (!is_complex_fixup(surface->resource.format->color_fixup)) { @@ -7097,7 +7208,7 @@ static HRESULT arbfp_blit_set(void *blit_priv, const struct wined3d_gl_info *gl_ shader = textype == GL_TEXTURE_RECTANGLE_ARB ? priv->p8_rect_shader : priv->p8_2d_shader; if (!shader) shader = gen_p8_shader(priv, gl_info, textype); - upload_palette(surface); + upload_palette(surface, context); break; default: @@ -7145,8 +7256,8 @@ static void arbfp_blit_unset(const struct wined3d_gl_info *gl_info) } static BOOL arbfp_blit_supported(const struct wined3d_gl_info *gl_info, enum wined3d_blit_op blit_op, - const RECT *src_rect, DWORD src_usage, WINED3DPOOL src_pool, const struct wined3d_format *src_format, - const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool, const struct wined3d_format *dst_format) + const RECT *src_rect, DWORD src_usage, enum wined3d_pool src_pool, const struct wined3d_format *src_format, + const RECT *dst_rect, DWORD dst_usage, enum wined3d_pool dst_pool, const struct wined3d_format *dst_format) { enum complex_fixup src_fixup; @@ -7159,6 +7270,9 @@ static BOOL arbfp_blit_supported(const struct wined3d_gl_info *gl_info, enum win return FALSE; } + if (src_pool == WINED3D_POOL_SYSTEM_MEM || dst_pool == WINED3D_POOL_SYSTEM_MEM) + return FALSE; + src_fixup = get_complex_fixup(src_format->color_fixup); if (TRACE_ON(d3d_shader) && TRACE_ON(d3d)) { @@ -7201,14 +7315,30 @@ static BOOL arbfp_blit_supported(const struct wined3d_gl_info *gl_info, enum win } } -HRESULT arbfp_blit_surface(struct wined3d_device *device, struct wined3d_surface *src_surface, const RECT *src_rect, - struct wined3d_surface *dst_surface, const RECT *dst_rect_in, enum wined3d_blit_op blit_op, DWORD Filter) +HRESULT arbfp_blit_surface(struct wined3d_device *device, DWORD filter, + struct wined3d_surface *src_surface, const RECT *src_rect_in, + struct wined3d_surface *dst_surface, const RECT *dst_rect_in) { struct wined3d_context *context; + RECT src_rect = *src_rect_in; RECT dst_rect = *dst_rect_in; /* Now load the surface */ - surface_internal_preload(src_surface, SRGB_RGB); + if (wined3d_settings.offscreen_rendering_mode != ORM_FBO + && (src_surface->flags & (SFLAG_INTEXTURE | SFLAG_INDRAWABLE)) == SFLAG_INDRAWABLE) + { + /* Without FBO blits transferring from the drawable to the texture is + * expensive, because we have to flip the data in sysmem. Since we can + * flip in the blitter, we don't actually need that flip anyway. So we + * use the surface's texture as scratch texture, and flip the source + * rectangle instead. */ + surface_load_fb_texture(src_surface, FALSE); + + src_rect.top = src_surface->resource.height - src_rect.top; + src_rect.bottom = src_surface->resource.height - src_rect.bottom; + } + else + surface_internal_preload(src_surface, SRGB_RGB); /* Activate the destination context, set it up for blitting */ context = context_acquire(device, dst_surface); @@ -7217,12 +7347,12 @@ HRESULT arbfp_blit_surface(struct wined3d_device *device, struct wined3d_surface if (!surface_is_offscreen(dst_surface)) surface_translate_drawable_coords(dst_surface, context->win_handle, &dst_rect); - arbfp_blit_set(device->blit_priv, context->gl_info, src_surface); + arbfp_blit_set(device->blit_priv, context, src_surface); ENTER_GL(); /* Draw a textured quad */ - draw_textured_quad(src_surface, src_rect, &dst_rect, Filter); + draw_textured_quad(src_surface, context, &src_rect, &dst_rect, filter); LEAVE_GL(); @@ -7236,13 +7366,13 @@ HRESULT arbfp_blit_surface(struct wined3d_device *device, struct wined3d_surface context_release(context); - surface_modify_location(dst_surface, SFLAG_INDRAWABLE, TRUE); + surface_modify_location(dst_surface, dst_surface->draw_binding, TRUE); return WINED3D_OK; } /* Do not call while under the GL lock. */ static HRESULT arbfp_blit_color_fill(struct wined3d_device *device, struct wined3d_surface *dst_surface, - const RECT *dst_rect, const WINED3DCOLORVALUE *color) + const RECT *dst_rect, const struct wined3d_color *color) { FIXME("Color filling not implemented by arbfp_blit\n"); return WINED3DERR_INVALIDCALL; diff --git a/reactos/dll/directx/wine/wined3d/ati_fragment_shader.c b/reactos/dll/directx/wine/wined3d/ati_fragment_shader.c index 02817573cb8..f1bf231fad3 100644 --- a/reactos/dll/directx/wine/wined3d/ati_fragment_shader.c +++ b/reactos/dll/directx/wine/wined3d/ati_fragment_shader.c @@ -321,10 +321,10 @@ static GLuint find_tmpreg(const struct texture_stage_op op[MAX_TEXTURES]) BOOL tex_used[MAX_TEXTURES]; memset(tex_used, 0, sizeof(tex_used)); - for(i = 0; i < MAX_TEXTURES; i++) { - if(op[i].cop == WINED3DTOP_DISABLE) { + for (i = 0; i < MAX_TEXTURES; ++i) + { + if (op[i].cop == WINED3D_TOP_DISABLE) break; - } if(lowest_read == -1 && (op[i].carg1 == WINED3DTA_TEMP || op[i].carg2 == WINED3DTA_TEMP || op[i].carg0 == WINED3DTA_TEMP || @@ -399,9 +399,11 @@ static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], con /* Pass 1: Generate sampling instructions for perturbation maps */ for (stage = 0; stage < gl_info->limits.textures; ++stage) { - if(op[stage].cop == WINED3DTOP_DISABLE) break; - if(op[stage].cop != WINED3DTOP_BUMPENVMAP && - op[stage].cop != WINED3DTOP_BUMPENVMAPLUMINANCE) continue; + if (op[stage].cop == WINED3D_TOP_DISABLE) + break; + if (op[stage].cop != WINED3D_TOP_BUMPENVMAP + && op[stage].cop != WINED3D_TOP_BUMPENVMAP_LUMINANCE) + continue; TRACE("glSampleMapATI(GL_REG_%d_ATI, GL_TEXTURE_%d_ARB, GL_SWIZZLE_STR_ATI)\n", stage, stage); @@ -428,9 +430,11 @@ static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], con GLuint argmodextra_x, argmodextra_y; struct color_fixup_desc fixup; - if(op[stage].cop == WINED3DTOP_DISABLE) break; - if(op[stage].cop != WINED3DTOP_BUMPENVMAP && - op[stage].cop != WINED3DTOP_BUMPENVMAPLUMINANCE) continue; + if (op[stage].cop == WINED3D_TOP_DISABLE) + break; + if (op[stage].cop != WINED3D_TOP_BUMPENVMAP + && op[stage].cop != WINED3D_TOP_BUMPENVMAP_LUMINANCE) + continue; fixup = op[stage].color_fixup; if (fixup.x_source != CHANNEL_SOURCE_X || fixup.y_source != CHANNEL_SOURCE_Y) @@ -474,9 +478,8 @@ static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], con /* Pass 3: Generate sampling instructions for regular textures */ for (stage = 0; stage < gl_info->limits.textures; ++stage) { - if(op[stage].cop == WINED3DTOP_DISABLE) { + if (op[stage].cop == WINED3D_TOP_DISABLE) break; - } if(op[stage].projected == proj_none) { swizzle = GL_SWIZZLE_STR_ATI; @@ -486,17 +489,18 @@ static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], con swizzle = GL_SWIZZLE_STQ_DQ_ATI; } - if((op[stage].carg0 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE || - (op[stage].carg1 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE || - (op[stage].carg2 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE || - (op[stage].aarg0 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE || - (op[stage].aarg1 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE || - (op[stage].aarg2 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE || - op[stage].cop == WINED3DTOP_BLENDTEXTUREALPHA) { - - if(stage > 0 && - (op[stage - 1].cop == WINED3DTOP_BUMPENVMAP || - op[stage - 1].cop == WINED3DTOP_BUMPENVMAPLUMINANCE)) { + if ((op[stage].carg0 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE + || (op[stage].carg1 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE + || (op[stage].carg2 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE + || (op[stage].aarg0 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE + || (op[stage].aarg1 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE + || (op[stage].aarg2 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE + || op[stage].cop == WINED3D_TOP_BLEND_TEXTURE_ALPHA) + { + if (stage > 0 + && (op[stage - 1].cop == WINED3D_TOP_BUMPENVMAP + || op[stage - 1].cop == WINED3D_TOP_BUMPENVMAP_LUMINANCE)) + { TRACE("glSampleMapATI(GL_REG_%d_ATI, GL_REG_%d_ATI, GL_SWIZZLE_STR_ATI)\n", stage, stage); GL_EXTCALL(glSampleMapATI(GL_REG_0_ATI + stage, @@ -515,7 +519,7 @@ static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], con /* Pass 4: Generate the arithmetic instructions */ for (stage = 0; stage < MAX_TEXTURES; ++stage) { - if (op[stage].cop == WINED3DTOP_DISABLE) + if (op[stage].cop == WINED3D_TOP_DISABLE) { if (!stage) { @@ -546,46 +550,52 @@ static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], con argmodextra = GL_NONE; extrarg = GL_NONE; - switch(op[stage].cop) { - case WINED3DTOP_SELECTARG2: + switch (op[stage].cop) + { + case WINED3D_TOP_SELECT_ARG2: arg1 = arg2; argmod1 = argmod2; rep1 = rep2; - case WINED3DTOP_SELECTARG1: + /* fall through */ + case WINED3D_TOP_SELECT_ARG1: wrap_op1(gl_info, GL_MOV_ATI, dstreg, GL_NONE, GL_NONE, arg1, rep1, argmod1); break; - case WINED3DTOP_MODULATE4X: + case WINED3D_TOP_MODULATE_4X: if(dstmod == GL_NONE) dstmod = GL_4X_BIT_ATI; - case WINED3DTOP_MODULATE2X: + /* fall through */ + case WINED3D_TOP_MODULATE_2X: if(dstmod == GL_NONE) dstmod = GL_2X_BIT_ATI; dstmod |= GL_SATURATE_BIT_ATI; - case WINED3DTOP_MODULATE: + /* fall through */ + case WINED3D_TOP_MODULATE: wrap_op2(gl_info, GL_MUL_ATI, dstreg, GL_NONE, dstmod, arg1, rep1, argmod1, arg2, rep2, argmod2); break; - case WINED3DTOP_ADDSIGNED2X: + case WINED3D_TOP_ADD_SIGNED_2X: dstmod = GL_2X_BIT_ATI; - case WINED3DTOP_ADDSIGNED: + /* fall through */ + case WINED3D_TOP_ADD_SIGNED: argmodextra = GL_BIAS_BIT_ATI; - case WINED3DTOP_ADD: + /* fall through */ + case WINED3D_TOP_ADD: dstmod |= GL_SATURATE_BIT_ATI; wrap_op2(gl_info, GL_ADD_ATI, GL_REG_0_ATI, GL_NONE, dstmod, arg1, rep1, argmod1, arg2, rep2, argmodextra | argmod2); break; - case WINED3DTOP_SUBTRACT: + case WINED3D_TOP_SUBTRACT: dstmod |= GL_SATURATE_BIT_ATI; wrap_op2(gl_info, GL_SUB_ATI, dstreg, GL_NONE, dstmod, arg1, rep1, argmod1, arg2, rep2, argmod2); break; - case WINED3DTOP_ADDSMOOTH: + case WINED3D_TOP_ADD_SMOOTH: argmodextra = argmod1 & GL_COMP_BIT_ATI ? argmod1 & ~GL_COMP_BIT_ATI : argmod1 | GL_COMP_BIT_ATI; /* Dst = arg1 + * arg2(1 -arg 1) * = arg2 * (1 - arg1) + arg1 @@ -596,21 +606,28 @@ static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], con arg1, rep1, argmod1); break; - case WINED3DTOP_BLENDCURRENTALPHA: - if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_CURRENT, gl_info, stage, NULL, NULL, -1); - case WINED3DTOP_BLENDFACTORALPHA: - if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_TFACTOR, gl_info, stage, NULL, NULL, -1); - case WINED3DTOP_BLENDTEXTUREALPHA: - if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1); - case WINED3DTOP_BLENDDIFFUSEALPHA: - if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_DIFFUSE, gl_info, stage, NULL, NULL, -1); + case WINED3D_TOP_BLEND_CURRENT_ALPHA: + if (extrarg == GL_NONE) + extrarg = register_for_arg(WINED3DTA_CURRENT, gl_info, stage, NULL, NULL, -1); + /* fall through */ + case WINED3D_TOP_BLEND_FACTOR_ALPHA: + if (extrarg == GL_NONE) + extrarg = register_for_arg(WINED3DTA_TFACTOR, gl_info, stage, NULL, NULL, -1); + /* fall through */ + case WINED3D_TOP_BLEND_TEXTURE_ALPHA: + if (extrarg == GL_NONE) + extrarg = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1); + /* fall through */ + case WINED3D_TOP_BLEND_DIFFUSE_ALPHA: + if (extrarg == GL_NONE) + extrarg = register_for_arg(WINED3DTA_DIFFUSE, gl_info, stage, NULL, NULL, -1); wrap_op3(gl_info, GL_LERP_ATI, dstreg, GL_NONE, GL_NONE, extrarg, GL_ALPHA, GL_NONE, arg1, rep1, argmod1, arg2, rep2, argmod2); break; - case WINED3DTOP_BLENDTEXTUREALPHAPM: + case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM: arg0 = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1); wrap_op3(gl_info, GL_MAD_ATI, dstreg, GL_NONE, GL_NONE, arg2, rep2, argmod2, @@ -620,48 +637,52 @@ static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], con /* D3DTOP_PREMODULATE ???? */ - case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR: + case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR: argmodextra = argmod1 & GL_COMP_BIT_ATI ? argmod1 & ~GL_COMP_BIT_ATI : argmod1 | GL_COMP_BIT_ATI; - case WINED3DTOP_MODULATEALPHA_ADDCOLOR: - if(!argmodextra) argmodextra = argmod1; + /* fall through */ + case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR: + if (!argmodextra) + argmodextra = argmod1; wrap_op3(gl_info, GL_MAD_ATI, dstreg, GL_NONE, GL_SATURATE_BIT_ATI, arg2, rep2, argmod2, arg1, GL_ALPHA, argmodextra, arg1, rep1, argmod1); break; - case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA: + case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA: argmodextra = argmod1 & GL_COMP_BIT_ATI ? argmod1 & ~GL_COMP_BIT_ATI : argmod1 | GL_COMP_BIT_ATI; - case WINED3DTOP_MODULATECOLOR_ADDALPHA: - if(!argmodextra) argmodextra = argmod1; + /* fall through */ + case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA: + if (!argmodextra) + argmodextra = argmod1; wrap_op3(gl_info, GL_MAD_ATI, dstreg, GL_NONE, GL_SATURATE_BIT_ATI, arg2, rep2, argmod2, arg1, rep1, argmodextra, arg1, GL_ALPHA, argmod1); break; - case WINED3DTOP_DOTPRODUCT3: + case WINED3D_TOP_DOTPRODUCT3: wrap_op2(gl_info, GL_DOT3_ATI, dstreg, GL_NONE, GL_4X_BIT_ATI | GL_SATURATE_BIT_ATI, arg1, rep1, argmod1 | GL_BIAS_BIT_ATI, arg2, rep2, argmod2 | GL_BIAS_BIT_ATI); break; - case WINED3DTOP_MULTIPLYADD: + case WINED3D_TOP_MULTIPLY_ADD: wrap_op3(gl_info, GL_MAD_ATI, dstreg, GL_NONE, GL_SATURATE_BIT_ATI, arg1, rep1, argmod1, arg2, rep2, argmod2, arg0, rep0, argmod0); break; - case WINED3DTOP_LERP: + case WINED3D_TOP_LERP: wrap_op3(gl_info, GL_LERP_ATI, dstreg, GL_NONE, GL_NONE, arg0, rep0, argmod0, arg1, rep1, argmod1, arg2, rep2, argmod2); break; - case WINED3DTOP_BUMPENVMAP: - case WINED3DTOP_BUMPENVMAPLUMINANCE: + case WINED3D_TOP_BUMPENVMAP: + case WINED3D_TOP_BUMPENVMAP_LUMINANCE: /* Those are handled in the first pass of the shader(generation pass 1 and 2) already */ break; @@ -675,8 +696,9 @@ static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], con argmodextra = GL_NONE; extrarg = GL_NONE; - switch(op[stage].aop) { - case WINED3DTOP_DISABLE: + switch (op[stage].aop) + { + case WINED3D_TOP_DISABLE: /* Get the primary color to the output if on stage 0, otherwise leave register 0 untouched */ if (!stage) { @@ -685,44 +707,51 @@ static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], con } break; - case WINED3DTOP_SELECTARG2: + case WINED3D_TOP_SELECT_ARG2: arg1 = arg2; argmod1 = argmod2; - case WINED3DTOP_SELECTARG1: + /* fall through */ + case WINED3D_TOP_SELECT_ARG1: wrap_op1(gl_info, GL_MOV_ATI, dstreg, GL_ALPHA, GL_NONE, arg1, GL_NONE, argmod1); break; - case WINED3DTOP_MODULATE4X: - if(dstmod == GL_NONE) dstmod = GL_4X_BIT_ATI; - case WINED3DTOP_MODULATE2X: - if(dstmod == GL_NONE) dstmod = GL_2X_BIT_ATI; + case WINED3D_TOP_MODULATE_4X: + if (dstmod == GL_NONE) + dstmod = GL_4X_BIT_ATI; + /* fall through */ + case WINED3D_TOP_MODULATE_2X: + if (dstmod == GL_NONE) + dstmod = GL_2X_BIT_ATI; dstmod |= GL_SATURATE_BIT_ATI; - case WINED3DTOP_MODULATE: + /* fall through */ + case WINED3D_TOP_MODULATE: wrap_op2(gl_info, GL_MUL_ATI, dstreg, GL_ALPHA, dstmod, arg1, GL_NONE, argmod1, arg2, GL_NONE, argmod2); break; - case WINED3DTOP_ADDSIGNED2X: + case WINED3D_TOP_ADD_SIGNED_2X: dstmod = GL_2X_BIT_ATI; - case WINED3DTOP_ADDSIGNED: + /* fall through */ + case WINED3D_TOP_ADD_SIGNED: argmodextra = GL_BIAS_BIT_ATI; - case WINED3DTOP_ADD: + /* fall through */ + case WINED3D_TOP_ADD: dstmod |= GL_SATURATE_BIT_ATI; wrap_op2(gl_info, GL_ADD_ATI, dstreg, GL_ALPHA, dstmod, arg1, GL_NONE, argmod1, arg2, GL_NONE, argmodextra | argmod2); break; - case WINED3DTOP_SUBTRACT: + case WINED3D_TOP_SUBTRACT: dstmod |= GL_SATURATE_BIT_ATI; wrap_op2(gl_info, GL_SUB_ATI, dstreg, GL_ALPHA, dstmod, arg1, GL_NONE, argmod1, arg2, GL_NONE, argmod2); break; - case WINED3DTOP_ADDSMOOTH: + case WINED3D_TOP_ADD_SMOOTH: argmodextra = argmod1 & GL_COMP_BIT_ATI ? argmod1 & ~GL_COMP_BIT_ATI : argmod1 | GL_COMP_BIT_ATI; /* Dst = arg1 + * arg2(1 -arg 1) * = arg2 * (1 - arg1) + arg1 @@ -733,21 +762,28 @@ static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], con arg1, GL_NONE, argmod1); break; - case WINED3DTOP_BLENDCURRENTALPHA: - if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_CURRENT, gl_info, stage, NULL, NULL, -1); - case WINED3DTOP_BLENDFACTORALPHA: - if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_TFACTOR, gl_info, stage, NULL, NULL, -1); - case WINED3DTOP_BLENDTEXTUREALPHA: - if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1); - case WINED3DTOP_BLENDDIFFUSEALPHA: - if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_DIFFUSE, gl_info, stage, NULL, NULL, -1); + case WINED3D_TOP_BLEND_CURRENT_ALPHA: + if (extrarg == GL_NONE) + extrarg = register_for_arg(WINED3DTA_CURRENT, gl_info, stage, NULL, NULL, -1); + /* fall through */ + case WINED3D_TOP_BLEND_FACTOR_ALPHA: + if (extrarg == GL_NONE) + extrarg = register_for_arg(WINED3DTA_TFACTOR, gl_info, stage, NULL, NULL, -1); + /* fall through */ + case WINED3D_TOP_BLEND_TEXTURE_ALPHA: + if (extrarg == GL_NONE) + extrarg = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1); + /* fall through */ + case WINED3D_TOP_BLEND_DIFFUSE_ALPHA: + if (extrarg == GL_NONE) + extrarg = register_for_arg(WINED3DTA_DIFFUSE, gl_info, stage, NULL, NULL, -1); wrap_op3(gl_info, GL_LERP_ATI, dstreg, GL_ALPHA, GL_NONE, extrarg, GL_ALPHA, GL_NONE, arg1, GL_NONE, argmod1, arg2, GL_NONE, argmod2); break; - case WINED3DTOP_BLENDTEXTUREALPHAPM: + case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM: arg0 = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1); wrap_op3(gl_info, GL_MAD_ATI, dstreg, GL_ALPHA, GL_NONE, arg2, GL_NONE, argmod2, @@ -757,32 +793,32 @@ static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], con /* D3DTOP_PREMODULATE ???? */ - case WINED3DTOP_DOTPRODUCT3: + case WINED3D_TOP_DOTPRODUCT3: wrap_op2(gl_info, GL_DOT3_ATI, dstreg, GL_ALPHA, GL_4X_BIT_ATI | GL_SATURATE_BIT_ATI, arg1, GL_NONE, argmod1 | GL_BIAS_BIT_ATI, arg2, GL_NONE, argmod2 | GL_BIAS_BIT_ATI); break; - case WINED3DTOP_MULTIPLYADD: + case WINED3D_TOP_MULTIPLY_ADD: wrap_op3(gl_info, GL_MAD_ATI, dstreg, GL_ALPHA, GL_SATURATE_BIT_ATI, arg1, GL_NONE, argmod1, arg2, GL_NONE, argmod2, arg0, GL_NONE, argmod0); break; - case WINED3DTOP_LERP: + case WINED3D_TOP_LERP: wrap_op3(gl_info, GL_LERP_ATI, dstreg, GL_ALPHA, GL_SATURATE_BIT_ATI, arg1, GL_NONE, argmod1, arg2, GL_NONE, argmod2, arg0, GL_NONE, argmod0); break; - case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR: - case WINED3DTOP_MODULATEALPHA_ADDCOLOR: - case WINED3DTOP_MODULATECOLOR_ADDALPHA: - case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA: - case WINED3DTOP_BUMPENVMAP: - case WINED3DTOP_BUMPENVMAPLUMINANCE: + case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR: + case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR: + case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA: + case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA: + case WINED3D_TOP_BUMPENVMAP: + case WINED3D_TOP_BUMPENVMAP_LUMINANCE: ERR("Application uses an invalid alpha operation\n"); break; @@ -796,17 +832,17 @@ static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], con return ret; } -static void set_tex_op_atifs(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void set_tex_op_atifs(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { + const struct wined3d_device *device = context->swapchain->device; const struct wined3d_gl_info *gl_info = context->gl_info; - struct wined3d_device *device = stateblock->device; const struct atifs_ffp_desc *desc; struct ffp_frag_settings settings; struct atifs_private_data *priv = device->fragment_priv; DWORD mapped_stage; unsigned int i; - gen_ffp_frag_op(stateblock, &settings, TRUE); + gen_ffp_frag_op(device, state, &settings, TRUE); desc = (const struct atifs_ffp_desc *)find_ffp_frag_shader(&priv->fragment_shaders, &settings); if(!desc) { struct atifs_ffp_desc *new_desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_desc)); @@ -818,7 +854,8 @@ static void set_tex_op_atifs(DWORD state, struct wined3d_stateblock *stateblock, new_desc->num_textures_used = 0; for (i = 0; i < gl_info->limits.texture_stages; ++i) { - if(settings.op[i].cop == WINED3DTOP_DISABLE) break; + if (settings.op[i].cop == WINED3D_TOP_DISABLE) + break; new_desc->num_textures_used = i; } @@ -837,35 +874,34 @@ static void set_tex_op_atifs(DWORD state, struct wined3d_stateblock *stateblock, mapped_stage = device->texUnitMap[i]; if (mapped_stage != WINED3D_UNMAPPED_STAGE) { - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); - checkGLcall("glActiveTextureARB"); - texture_activate_dimensions(stateblock->state.textures[i], gl_info); + context_active_texture(context, gl_info, mapped_stage); + texture_activate_dimensions(state->textures[i], gl_info); } } GL_EXTCALL(glBindFragmentShaderATI(desc->shader)); } -static void state_texfactor_atifs(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_texfactor_atifs(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { const struct wined3d_gl_info *gl_info = context->gl_info; float col[4]; - D3DCOLORTOGLFLOAT4(stateblock->state.render_states[WINED3DRS_TEXTUREFACTOR], col); + D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_TEXTUREFACTOR], col); GL_EXTCALL(glSetFragmentShaderConstantATI(ATI_FFP_CONST_TFACTOR, col)); checkGLcall("glSetFragmentShaderConstantATI(ATI_FFP_CONST_TFACTOR, col)"); } -static void set_bumpmat(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void set_bumpmat(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); + DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); const struct wined3d_gl_info *gl_info = context->gl_info; float mat[2][2]; - mat[0][0] = *((float *)&stateblock->state.texture_states[stage][WINED3DTSS_BUMPENVMAT00]); - mat[1][0] = *((float *)&stateblock->state.texture_states[stage][WINED3DTSS_BUMPENVMAT01]); - mat[0][1] = *((float *)&stateblock->state.texture_states[stage][WINED3DTSS_BUMPENVMAT10]); - mat[1][1] = *((float *)&stateblock->state.texture_states[stage][WINED3DTSS_BUMPENVMAT11]); + mat[0][0] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT00]); + mat[1][0] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT01]); + mat[0][1] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT10]); + mat[1][1] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT11]); /* GL_ATI_fragment_shader allows only constants from 0.0 to 1.0, but the bumpmat * constants can be in any range. While they should stay between [-1.0 and 1.0] because * Shader Model 1.x pixel shaders are clamped to that range negative values are used occasionally, @@ -881,159 +917,160 @@ static void set_bumpmat(DWORD state, struct wined3d_stateblock *stateblock, stru checkGLcall("glSetFragmentShaderConstantATI(ATI_FFP_CONST_BUMPMAT(stage), mat)"); } -static void textransform(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void textransform(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { if (!isStateDirty(context, STATE_PIXELSHADER)) - set_tex_op_atifs(state, stateblock, context); + set_tex_op_atifs(context, state, state_id); } -static void atifs_apply_pixelshader(DWORD state_id, - struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void atifs_apply_pixelshader(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - const struct wined3d_state *state = &stateblock->state; - struct wined3d_device *device = stateblock->device; + const struct wined3d_device *device = context->swapchain->device; BOOL use_vshader = use_vs(state); context->last_was_pshader = use_ps(state); - /* The ATIFS code does not support pixel shaders currently, but we have to provide a state handler - * to call shader_select to select a vertex shader if one is applied because the vertex shader state - * may defer calling the shader backend if the pshader state is dirty. + /* The ATIFS code does not support pixel shaders currently, but we have to + * provide a state handler to call shader_select to select a vertex shader + * if one is applied because the vertex shader state may defer calling the + * shader backend if the pshader state is dirty. * - * In theory the application should not be able to mark the pixel shader dirty because it cannot - * create a shader, and thus has no way to set the state to something != NULL. However, a different - * pipeline part may link a different state to its pixelshader handler, thus a pshader state exists - * and can be dirtified. Also the pshader is always dirtified at startup, and blitting disables all - * shaders and dirtifies all shader states. If atifs can deal with this it keeps the rest of the code - * simpler. - */ - if(!isStateDirty(context, device->StateTable[STATE_VSHADER].representative)) { + * In theory the application should not be able to mark the pixel shader + * dirty because it cannot create a shader, and thus has no way to set the + * state to something != NULL. However, a different pipeline part may link + * a different state to its pixelshader handler, thus a pshader state + * exists and can be dirtified. Also the pshader is always dirtified at + * startup, and blitting disables all shaders and dirtifies all shader + * states. If atifs can deal with this it keeps the rest of the code + * simpler. */ + if (!isStateDirty(context, context->state_table[STATE_VSHADER].representative)) + { device->shader_backend->shader_select(context, FALSE, use_vshader); if (!isStateDirty(context, STATE_VERTEXSHADERCONSTANT) && use_vshader) - stateblock_apply_state(STATE_VERTEXSHADERCONSTANT, stateblock, context); + context_apply_state(context, state, STATE_VERTEXSHADERCONSTANT); } } -static void atifs_srgbwriteenable(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void atifs_srgbwriteenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_SRGBWRITEENABLE]) + if (state->render_states[WINED3D_RS_SRGBWRITEENABLE]) WARN("sRGB writes are not supported by this fragment pipe.\n"); } static const struct StateEntryTemplate atifs_fragmentstate_template[] = { - {STATE_RENDER(WINED3DRS_TEXTUREFACTOR), { STATE_RENDER(WINED3DRS_TEXTUREFACTOR), state_texfactor_atifs }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_FOGCOLOR), { STATE_RENDER(WINED3DRS_FOGCOLOR), state_fogcolor }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_FOGDENSITY), { STATE_RENDER(WINED3DRS_FOGDENSITY), state_fogdensity }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_FOGENABLE), { STATE_RENDER(WINED3DRS_FOGENABLE), state_fog_fragpart }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_FOGTABLEMODE), { STATE_RENDER(WINED3DRS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_FOGVERTEXMODE), { STATE_RENDER(WINED3DRS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_FOGSTART), { STATE_RENDER(WINED3DRS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_FOGEND), { STATE_RENDER(WINED3DRS_FOGSTART), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_RENDER(WINED3DRS_SRGBWRITEENABLE), { STATE_RENDER(WINED3DRS_SRGBWRITEENABLE), atifs_srgbwriteenable }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), state_texfactor_atifs }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_FOGCOLOR), { STATE_RENDER(WINED3D_RS_FOGCOLOR), state_fogcolor }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_FOGDENSITY), { STATE_RENDER(WINED3D_RS_FOGDENSITY), state_fogdensity }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_FOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), state_fog_fragpart }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_FOGTABLEMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_FOGVERTEXMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_FOGSTART), { STATE_RENDER(WINED3D_RS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_FOGEND), { STATE_RENDER(WINED3D_RS_FOGSTART), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE), { STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE), atifs_srgbwriteenable }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), set_tex_op_atifs }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler_texdim }, WINED3D_GL_EXT_NONE }, { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler_texdim }, WINED3D_GL_EXT_NONE }, { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler_texdim }, WINED3D_GL_EXT_NONE }, @@ -1042,14 +1079,14 @@ static const struct StateEntryTemplate atifs_fragmentstate_template[] = { { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler_texdim }, WINED3D_GL_EXT_NONE }, { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler_texdim }, WINED3D_GL_EXT_NONE }, { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler_texdim }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(0,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(0, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(1,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(1, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(2,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(2, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(3,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(3, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(4,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(4, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(5,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(5, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(6,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(6, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, WINED3D_GL_EXT_NONE }, - {STATE_TEXTURESTAGE(7,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(7, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(0,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(1,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(2,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(3,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(4,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(5,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(6,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE }, + {STATE_TEXTURESTAGE(7,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE }, {STATE_PIXELSHADER, { STATE_PIXELSHADER, atifs_apply_pixelshader }, WINED3D_GL_EXT_NONE }, {0 /* Terminate */, { 0, 0 }, WINED3D_GL_EXT_NONE }, }; diff --git a/reactos/dll/directx/wine/wined3d/buffer.c b/reactos/dll/directx/wine/wined3d/buffer.c index f2f806ec3e5..495fe2f6900 100644 --- a/reactos/dll/directx/wine/wined3d/buffer.c +++ b/reactos/dll/directx/wine/wined3d/buffer.c @@ -76,21 +76,19 @@ static inline void buffer_clear_dirty_areas(struct wined3d_buffer *This) This->modified_areas = 0; } -static inline BOOL buffer_is_dirty(struct wined3d_buffer *This) +static BOOL buffer_is_dirty(const struct wined3d_buffer *buffer) { - return !!This->modified_areas; + return !!buffer->modified_areas; } -static inline BOOL buffer_is_fully_dirty(struct wined3d_buffer *This) +static BOOL buffer_is_fully_dirty(const struct wined3d_buffer *buffer) { unsigned int i; - for(i = 0; i < This->modified_areas; i++) + for (i = 0; i < buffer->modified_areas; ++i) { - if (!This->maps[i].offset && This->maps[i].size == This->resource.size) - { + if (!buffer->maps[i].offset && buffer->maps[i].size == buffer->resource.size) return TRUE; - } } return FALSE; } @@ -119,7 +117,7 @@ static void buffer_create_buffer_object(struct wined3d_buffer *This, const struc { GLenum error, gl_usage; - TRACE("Creating an OpenGL vertex buffer object for IWineD3DVertexBuffer %p Usage(%s)\n", + TRACE("Creating an OpenGL vertex buffer object for wined3d_buffer %p with usage %s.\n", This, debug_d3dusage(This->resource.usage)); ENTER_GL(); @@ -131,12 +129,11 @@ static void buffer_create_buffer_object(struct wined3d_buffer *This, const struc */ while (glGetError() != GL_NO_ERROR); - /* Basically the FVF parameter passed to CreateVertexBuffer is no good - * It is the FVF set with IWineD3DDevice::SetFVF or the Vertex Declaration set with - * IWineD3DDevice::SetVertexDeclaration that decides how the vertices in the buffer - * look like. This means that on each DrawPrimitive call the vertex buffer has to be verified - * to check if the rhw and color values are in the correct format. - */ + /* Basically the FVF parameter passed to CreateVertexBuffer is no good. + * The vertex declaration from the device determines how the data in the + * buffer is interpreted. This means that on each draw call the buffer has + * to be verified to check if the rhw and color values are in the correct + * format. */ GL_EXTCALL(glGenBuffersARB(1, &This->buffer_object)); error = glGetError(); @@ -147,10 +144,8 @@ static void buffer_create_buffer_object(struct wined3d_buffer *This, const struc goto fail; } - if(This->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB) - { - IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_INDEXBUFFER); - } + if (This->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB) + device_invalidate_state(This->resource.device, STATE_INDEXBUFFER); GL_EXTCALL(glBindBufferARB(This->buffer_type_hint, This->buffer_object)); error = glGetError(); if (error != GL_NO_ERROR) @@ -231,7 +226,6 @@ static BOOL buffer_process_converted_attribute(struct wined3d_buffer *This, const enum wined3d_buffer_conversion_type conversion_type, const struct wined3d_stream_info_element *attrib, DWORD *stride_this_run) { - DWORD offset = This->resource.device->stateBlock->state.streams[attrib->stream_idx].offset; DWORD attrib_size; BOOL ret = FALSE; unsigned int i; @@ -268,7 +262,7 @@ static BOOL buffer_process_converted_attribute(struct wined3d_buffer *This, } } - data = (((DWORD_PTR)attrib->data) + offset) % This->stride; + data = ((DWORD_PTR)attrib->data.addr) % This->stride; attrib_size = attrib->format->component_count * attrib->format->component_size; for (i = 0; i < attrib_size; ++i) { @@ -297,7 +291,7 @@ static BOOL buffer_check_attribute(struct wined3d_buffer *This, const struct win * there, on nonexistent attribs the vbo is 0. */ if (!(si->use_map & (1 << attrib_idx)) - || attrib->buffer_object != This->buffer_object) + || attrib->data.buffer_object != This->buffer_object) return FALSE; format = attrib->format->id; @@ -470,10 +464,10 @@ static inline void fixup_transformed_pos(float *p) } /* Context activation is done by the caller. */ -const BYTE *buffer_get_memory(struct wined3d_buffer *buffer, - const struct wined3d_gl_info *gl_info, GLuint *buffer_object) +void buffer_get_memory(struct wined3d_buffer *buffer, const struct wined3d_gl_info *gl_info, + struct wined3d_bo_address *data) { - *buffer_object = buffer->buffer_object; + data->buffer_object = buffer->buffer_object; if (!buffer->buffer_object) { if (buffer->flags & WINED3D_BUFFER_CREATEBO) @@ -482,15 +476,16 @@ const BYTE *buffer_get_memory(struct wined3d_buffer *buffer, buffer->flags &= ~WINED3D_BUFFER_CREATEBO; if (buffer->buffer_object) { - *buffer_object = buffer->buffer_object; - return NULL; + data->buffer_object = buffer->buffer_object; + data->addr = NULL; + return; } } - return buffer->resource.allocatedMemory; + data->addr = buffer->resource.allocatedMemory; } else { - return NULL; + data->addr = NULL; } } @@ -513,9 +508,7 @@ BYTE *buffer_get_sysmem(struct wined3d_buffer *This, const struct wined3d_gl_inf This->resource.allocatedMemory = (BYTE *)(((ULONG_PTR)This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1)); if (This->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB) - { - IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_INDEXBUFFER); - } + device_invalidate_state(This->resource.device, STATE_INDEXBUFFER); ENTER_GL(); GL_EXTCALL(glBindBufferARB(This->buffer_type_hint, This->buffer_object)); @@ -589,23 +582,6 @@ void * CDECL wined3d_buffer_get_parent(const struct wined3d_buffer *buffer) return buffer->resource.parent; } -HRESULT CDECL wined3d_buffer_set_private_data(struct wined3d_buffer *buffer, - REFGUID guid, const void *data, DWORD data_size, DWORD flags) -{ - return resource_set_private_data(&buffer->resource, guid, data, data_size, flags); -} - -HRESULT CDECL wined3d_buffer_get_private_data(const struct wined3d_buffer *buffer, - REFGUID guid, void *data, DWORD *data_size) -{ - return resource_get_private_data(&buffer->resource, guid, data, data_size); -} - -HRESULT CDECL wined3d_buffer_free_private_data(struct wined3d_buffer *buffer, REFGUID guid) -{ - return resource_free_private_data(&buffer->resource, guid); -} - DWORD CDECL wined3d_buffer_set_priority(struct wined3d_buffer *buffer, DWORD priority) { return resource_set_priority(&buffer->resource, priority); @@ -704,13 +680,9 @@ static void buffer_direct_upload(struct wined3d_buffer *This, const struct wined GLbitfield mapflags; mapflags = GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT; if (flags & WINED3D_BUFFER_DISCARD) - { - mapflags |= GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_INVALIDATE_BUFFER_BIT; - } - else if (flags & WINED3D_BUFFER_NOSYNC) - { + mapflags |= GL_MAP_INVALIDATE_BUFFER_BIT; + if (flags & WINED3D_BUFFER_NOSYNC) mapflags |= GL_MAP_UNSYNCHRONIZED_BIT; - } map = GL_EXTCALL(glMapBufferRange(This->buffer_type_hint, 0, This->resource.size, mapflags)); checkGLcall("glMapBufferRange"); @@ -833,7 +805,7 @@ void CDECL wined3d_buffer_preload(struct wined3d_buffer *buffer) * is not valid any longer. Dirtify the stream source to force a * reload. This happens only once per changed vertexbuffer and * should occur rather rarely. */ - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_STREAMSRC); + device_invalidate_state(device, STATE_STREAMSRC); return; } @@ -864,7 +836,8 @@ void CDECL wined3d_buffer_preload(struct wined3d_buffer *buffer) FIXME("Too many full buffer conversions, stopping converting.\n"); buffer_unload(&buffer->resource); buffer->flags &= ~WINED3D_BUFFER_CREATEBO; - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_STREAMSRC); + if (buffer->bind_count) + device_invalidate_state(device, STATE_STREAMSRC); return; } } @@ -879,7 +852,7 @@ void CDECL wined3d_buffer_preload(struct wined3d_buffer *buffer) } if (buffer->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB) - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_INDEXBUFFER); + device_invalidate_state(device, STATE_INDEXBUFFER); if (!buffer->conversion_map) { @@ -961,7 +934,7 @@ void CDECL wined3d_buffer_preload(struct wined3d_buffer *buffer) context_release(context); } -static DWORD buffer_sanitize_flags(struct wined3d_buffer *buffer, DWORD flags) +static DWORD buffer_sanitize_flags(const struct wined3d_buffer *buffer, DWORD flags) { /* Not all flags make sense together, but Windows never returns an error. Catch the * cases that could cause issues */ @@ -996,17 +969,15 @@ static GLbitfield buffer_gl_map_flags(DWORD d3d_flags) { GLbitfield ret = 0; - if (!(d3d_flags & WINED3DLOCK_READONLY)) ret = GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT; - - if (d3d_flags & (WINED3DLOCK_DISCARD | WINED3DLOCK_NOOVERWRITE)) - { - if(d3d_flags & WINED3DLOCK_DISCARD) ret |= GL_MAP_INVALIDATE_BUFFER_BIT; - ret |= GL_MAP_UNSYNCHRONIZED_BIT; - } - else - { + if (!(d3d_flags & WINED3DLOCK_READONLY)) + ret |= GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT; + if (!(d3d_flags & (WINED3DLOCK_DISCARD | WINED3DLOCK_NOOVERWRITE))) ret |= GL_MAP_READ_BIT; - } + + if (d3d_flags & WINED3DLOCK_DISCARD) + ret |= GL_MAP_INVALIDATE_BUFFER_BIT; + if (d3d_flags & WINED3DLOCK_NOOVERWRITE) + ret |= GL_MAP_UNSYNCHRONIZED_BIT; return ret; } @@ -1043,12 +1014,13 @@ HRESULT CDECL wined3d_buffer_map(struct wined3d_buffer *buffer, UINT offset, UIN struct wined3d_context *context; const struct wined3d_gl_info *gl_info; - if (buffer->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB) - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_INDEXBUFFER); - context = context_acquire(device, NULL); gl_info = context->gl_info; + ENTER_GL(); + + if (buffer->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB) + context_invalidate_state(context, STATE_INDEXBUFFER); GL_EXTCALL(glBindBufferARB(buffer->buffer_type_hint, buffer->buffer_object)); if (gl_info->supported[ARB_MAP_BUFFER_RANGE]) @@ -1074,8 +1046,7 @@ HRESULT CDECL wined3d_buffer_map(struct wined3d_buffer *buffer, UINT offset, UIN if (((DWORD_PTR)buffer->resource.allocatedMemory) & (RESOURCE_ALIGNMENT - 1)) { - WARN("Pointer %p is not %u byte aligned, falling back to double buffered operation.\n", - buffer->resource.allocatedMemory, RESOURCE_ALIGNMENT); + WARN("Pointer %p is not %u byte aligned.\n", buffer->resource.allocatedMemory, RESOURCE_ALIGNMENT); ENTER_GL(); GL_EXTCALL(glUnmapBufferARB(buffer->buffer_type_hint)); @@ -1083,7 +1054,23 @@ HRESULT CDECL wined3d_buffer_map(struct wined3d_buffer *buffer, UINT offset, UIN LEAVE_GL(); buffer->resource.allocatedMemory = NULL; - buffer_get_sysmem(buffer, gl_info); + if (buffer->resource.usage & WINED3DUSAGE_DYNAMIC) + { + /* The extra copy is more expensive than not using VBOs at + * all on the Nvidia Linux driver, which is the only driver + * that returns unaligned pointers + */ + TRACE("Dynamic buffer, dropping VBO\n"); + buffer_unload(&buffer->resource); + buffer->flags &= ~WINED3D_BUFFER_CREATEBO; + if (buffer->bind_count) + device_invalidate_state(device, STATE_STREAMSRC); + } + else + { + TRACE("Falling back to doublebuffered operation\n"); + buffer_get_sysmem(buffer, gl_info); + } TRACE("New pointer is %p.\n", buffer->resource.allocatedMemory); } context_release(context); @@ -1147,14 +1134,13 @@ void CDECL wined3d_buffer_unmap(struct wined3d_buffer *buffer) const struct wined3d_gl_info *gl_info; struct wined3d_context *context; - if (buffer->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB) - { - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_INDEXBUFFER); - } - context = context_acquire(device, NULL); gl_info = context->gl_info; + ENTER_GL(); + + if (buffer->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB) + context_invalidate_state(context, STATE_INDEXBUFFER); GL_EXTCALL(glBindBufferARB(buffer->buffer_type_hint, buffer->buffer_object)); if (gl_info->supported[ARB_MAP_BUFFER_RANGE]) @@ -1178,6 +1164,7 @@ void CDECL wined3d_buffer_unmap(struct wined3d_buffer *buffer) GL_EXTCALL(glUnmapBufferARB(buffer->buffer_type_hint)); LEAVE_GL(); + if (wined3d_settings.strict_draw_ordering) wglFlush(); /* Flush to ensure ordering across contexts. */ context_release(context); buffer->resource.allocatedMemory = NULL; @@ -1195,7 +1182,7 @@ static const struct wined3d_resource_ops buffer_resource_ops = }; static HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device *device, - UINT size, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool, GLenum bind_hint, + UINT size, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool, GLenum bind_hint, const char *data, void *parent, const struct wined3d_parent_ops *parent_ops) { const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; @@ -1209,8 +1196,8 @@ static HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device return WINED3DERR_INVALIDCALL; } - hr = resource_init(&buffer->resource, device, WINED3DRTYPE_BUFFER, format, - WINED3DMULTISAMPLE_NONE, 0, usage, pool, size, 1, 1, size, + hr = resource_init(&buffer->resource, device, WINED3D_RTYPE_BUFFER, format, + WINED3D_MULTISAMPLE_NONE, 0, usage, pool, size, 1, 1, size, parent, parent_ops, &buffer_resource_ops); if (FAILED(hr)) { @@ -1222,8 +1209,7 @@ static HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device TRACE("size %#x, usage %#x, format %s, memory @ %p, iface @ %p.\n", buffer->resource.size, buffer->resource.usage, debug_d3dformat(buffer->resource.format->id), buffer->resource.allocatedMemory, buffer); - /* GL_ARB_map_buffer_range is disabled for now due to numerous bugs and no gains */ - dynamic_buffer_ok = gl_info->supported[APPLE_FLUSH_BUFFER_RANGE]; + dynamic_buffer_ok = gl_info->supported[APPLE_FLUSH_BUFFER_RANGE] || gl_info->supported[ARB_MAP_BUFFER_RANGE]; /* Observations show that drawStridedSlow is faster on dynamic VBs than converting + * drawStridedFast (half-life 2 and others). @@ -1236,7 +1222,7 @@ static HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device { TRACE("Not creating a vbo because GL_ARB_vertex_buffer is not supported\n"); } - else if(buffer->resource.pool == WINED3DPOOL_SYSTEMMEM) + else if(buffer->resource.pool == WINED3D_POOL_SYSTEM_MEM) { TRACE("Not creating a vbo because the vertex buffer is in system memory\n"); } @@ -1298,7 +1284,7 @@ HRESULT CDECL wined3d_buffer_create(struct wined3d_device *device, struct wined3 FIXME("Ignoring access flags (pool)\n"); hr = buffer_init(object, device, desc->byte_width, desc->usage, WINED3DFMT_UNKNOWN, - WINED3DPOOL_MANAGED, GL_ARRAY_BUFFER_ARB, data, parent, parent_ops); + WINED3D_POOL_MANAGED, GL_ARRAY_BUFFER_ARB, data, parent, parent_ops); if (FAILED(hr)) { WARN("Failed to initialize buffer, hr %#x.\n", hr); @@ -1314,7 +1300,7 @@ HRESULT CDECL wined3d_buffer_create(struct wined3d_device *device, struct wined3 return WINED3D_OK; } -HRESULT CDECL wined3d_buffer_create_vb(struct wined3d_device *device, UINT size, DWORD usage, WINED3DPOOL pool, +HRESULT CDECL wined3d_buffer_create_vb(struct wined3d_device *device, UINT size, DWORD usage, enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_buffer **buffer) { struct wined3d_buffer *object; @@ -1323,11 +1309,11 @@ HRESULT CDECL wined3d_buffer_create_vb(struct wined3d_device *device, UINT size, TRACE("device %p, size %u, usage %#x, pool %#x, parent %p, parent_ops %p, buffer %p.\n", device, size, usage, pool, parent, parent_ops, buffer); - if (pool == WINED3DPOOL_SCRATCH) + if (pool == WINED3D_POOL_SCRATCH) { /* The d3d9 tests shows that this is not allowed. It doesn't make much * sense anyway, SCRATCH buffers wouldn't be usable anywhere. */ - WARN("Vertex buffer in WINED3DPOOL_SCRATCH requested, returning WINED3DERR_INVALIDCALL.\n"); + WARN("Vertex buffer in WINED3D_POOL_SCRATCH requested, returning WINED3DERR_INVALIDCALL.\n"); *buffer = NULL; return WINED3DERR_INVALIDCALL; } @@ -1355,7 +1341,7 @@ HRESULT CDECL wined3d_buffer_create_vb(struct wined3d_device *device, UINT size, return WINED3D_OK; } -HRESULT CDECL wined3d_buffer_create_ib(struct wined3d_device *device, UINT size, DWORD usage, WINED3DPOOL pool, +HRESULT CDECL wined3d_buffer_create_ib(struct wined3d_device *device, UINT size, DWORD usage, enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_buffer **buffer) { struct wined3d_buffer *object; diff --git a/reactos/dll/directx/wine/wined3d/clipper.c b/reactos/dll/directx/wine/wined3d/clipper.c deleted file mode 100644 index e5131d7f749..00000000000 --- a/reactos/dll/directx/wine/wined3d/clipper.c +++ /dev/null @@ -1,162 +0,0 @@ -/* IWineD3DClipper implementation - * - * Copyright 2000 (c) Marcus Meissner - * Copyright 2000 (c) TransGaming Technologies Inc. - * Copyright 2006 (c) Stefan Dösinger - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include "config.h" -#include -#ifdef HAVE_FLOAT_H -# include -#endif -#include "wined3d_private.h" - -WINE_DEFAULT_DEBUG_CHANNEL(d3d); - -ULONG CDECL wined3d_clipper_incref(struct wined3d_clipper *clipper) -{ - ULONG refcount = InterlockedIncrement(&clipper->ref); - - TRACE("%p increasing refcount to %u.\n", clipper, refcount); - - return refcount; -} - -ULONG CDECL wined3d_clipper_decref(struct wined3d_clipper *clipper) -{ - ULONG refcount = InterlockedDecrement(&clipper->ref); - - TRACE("%p decreasing refcount to %u.\n", clipper, refcount); - - if (!refcount) - HeapFree(GetProcessHeap(), 0, clipper); - - return refcount; -} - -HRESULT CDECL wined3d_clipper_set_window(struct wined3d_clipper *clipper, DWORD flags, HWND window) -{ - TRACE("clipper %p, flags %#x, window %p.\n", clipper, flags, window); - - if (flags) - { - FIXME("flags %#x, not supported.\n", flags); - return WINED3DERR_INVALIDCALL; - } - - clipper->hWnd = window; - - return WINED3D_OK; -} - -HRESULT CDECL wined3d_clipper_get_clip_list(const struct wined3d_clipper *clipper, const RECT *rect, - RGNDATA *clip_list, DWORD *clip_list_size) -{ - TRACE("clipper %p, rect %s, clip_list %p, clip_list_size %p.\n", - clipper, wine_dbgstr_rect(rect), clip_list, clip_list_size); - - if (clipper->hWnd) - { - HDC hDC = GetDCEx(clipper->hWnd, NULL, DCX_WINDOW); - if (hDC) - { - HRGN hRgn = CreateRectRgn(0,0,0,0); - if (GetRandomRgn(hDC, hRgn, SYSRGN)) - { - if (GetVersion() & 0x80000000) - { - /* map region to screen coordinates */ - POINT org; - GetDCOrgEx(hDC, &org); - OffsetRgn(hRgn, org.x, org.y); - } - if (rect) - { - HRGN hRgnClip = CreateRectRgn(rect->left, rect->top, - rect->right, rect->bottom); - CombineRgn(hRgn, hRgn, hRgnClip, RGN_AND); - DeleteObject(hRgnClip); - } - *clip_list_size = GetRegionData(hRgn, *clip_list_size, clip_list); - } - DeleteObject(hRgn); - ReleaseDC(clipper->hWnd, hDC); - } - return WINED3D_OK; - } - else - { - static unsigned int once; - - if (!once++) - FIXME("clipper %p, rect %s, clip_list %p, clip_list_size %p stub!\n", - clipper, wine_dbgstr_rect(rect), clip_list, clip_list_size); - - if (clip_list_size) - *clip_list_size = 0; - - return WINEDDERR_NOCLIPLIST; - } -} - -HRESULT CDECL wined3d_clipper_set_clip_list(struct wined3d_clipper *clipper, const RGNDATA *region, DWORD flags) -{ - static unsigned int once; - - if (!once++ || !region) - FIXME("clipper %p, region %p, flags %#x stub!\n", clipper, region, flags); - - return WINED3D_OK; -} - -HRESULT CDECL wined3d_clipper_get_window(const struct wined3d_clipper *clipper, HWND *window) -{ - TRACE("clipper %p, window %p.\n", clipper, window); - - *window = clipper->hWnd; - - return WINED3D_OK; -} - -HRESULT CDECL wined3d_clipper_is_clip_list_changed(const struct wined3d_clipper *clipper, BOOL *changed) -{ - FIXME("clipper %p, changed %p stub!\n", clipper, changed); - - /* XXX What is safest? */ - *changed = FALSE; - - return WINED3D_OK; -} - -struct wined3d_clipper * CDECL wined3d_clipper_create(void) -{ - struct wined3d_clipper *clipper; - - TRACE("\n"); - - clipper = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*clipper)); - if (!clipper) - { - ERR("Out of memory when trying to allocate a WineD3D Clipper\n"); - return NULL; - } - - wined3d_clipper_incref(clipper); - - return clipper; -} diff --git a/reactos/dll/directx/wine/wined3d/context.c b/reactos/dll/directx/wine/wined3d/context.c index 04942527e07..fe26549179c 100644 --- a/reactos/dll/directx/wine/wined3d/context.c +++ b/reactos/dll/directx/wine/wined3d/context.c @@ -33,7 +33,7 @@ static DWORD wined3d_context_tls_idx; /* FBO helper functions */ /* GL locking is done by the caller */ -void context_bind_fbo(struct wined3d_context *context, GLenum target, GLuint *fbo) +static void context_bind_fbo(struct wined3d_context *context, GLenum target, GLuint *fbo) { const struct wined3d_gl_info *gl_info = context->gl_info; GLuint f; @@ -111,87 +111,25 @@ static void context_destroy_fbo(struct wined3d_context *context, GLuint *fbo) checkGLcall("glDeleteFramebuffers()"); } -/* GL locking is done by the caller */ -static void context_apply_attachment_filter_states(const struct wined3d_context *context, - struct wined3d_surface *surface, DWORD location) +static void context_attach_depth_stencil_rb(const struct wined3d_gl_info *gl_info, + GLenum fbo_target, DWORD format_flags, GLuint rb) { - /* Update base texture states array */ - if (surface->container.type == WINED3D_CONTAINER_TEXTURE) + if (format_flags & WINED3DFMT_FLAG_DEPTH) { - struct wined3d_texture *texture = surface->container.u.texture; - struct wined3d_device *device = surface->resource.device; - BOOL update_minfilter = FALSE; - BOOL update_magfilter = FALSE; - struct gl_texture *gl_tex; + gl_info->fbo_ops.glFramebufferRenderbuffer(fbo_target, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb); + checkGLcall("glFramebufferRenderbuffer()"); + } - switch (location) - { - case SFLAG_INTEXTURE: - case SFLAG_INSRGBTEX: - gl_tex = wined3d_texture_get_gl_texture(texture, - context->gl_info, location == SFLAG_INSRGBTEX); - break; - - default: - ERR("Unsupported location %s (%#x).\n", debug_surflocation(location), location); - return; - } - - if (gl_tex->states[WINED3DTEXSTA_MINFILTER] != WINED3DTEXF_POINT - || gl_tex->states[WINED3DTEXSTA_MIPFILTER] != WINED3DTEXF_NONE) - { - gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT; - gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE; - update_minfilter = TRUE; - } - - if (gl_tex->states[WINED3DTEXSTA_MAGFILTER] != WINED3DTEXF_POINT) - { - gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT; - update_magfilter = TRUE; - } - - if (texture->bind_count) - { - WARN("Render targets should not be bound to a sampler\n"); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(texture->sampler)); - } - - if (update_minfilter || update_magfilter) - { - GLenum target, bind_target; - GLint old_binding; - - target = surface->texture_target; - if (target == GL_TEXTURE_2D) - { - bind_target = GL_TEXTURE_2D; - glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_binding); - } - else if (target == GL_TEXTURE_RECTANGLE_ARB) - { - bind_target = GL_TEXTURE_RECTANGLE_ARB; - glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &old_binding); - } - else - { - bind_target = GL_TEXTURE_CUBE_MAP_ARB; - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARB, &old_binding); - } - - glBindTexture(bind_target, gl_tex->name); - if (update_minfilter) glTexParameteri(bind_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - if (update_magfilter) glTexParameteri(bind_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glBindTexture(bind_target, old_binding); - } - - checkGLcall("apply_attachment_filter_states()"); + if (format_flags & WINED3DFMT_FLAG_STENCIL) + { + gl_info->fbo_ops.glFramebufferRenderbuffer(fbo_target, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb); + checkGLcall("glFramebufferRenderbuffer()"); } } /* GL locking is done by the caller */ -void context_attach_depth_stencil_fbo(struct wined3d_context *context, - GLenum fbo_target, struct wined3d_surface *depth_stencil, BOOL use_render_buffer) +static void context_attach_depth_stencil_fbo(struct wined3d_context *context, + GLenum fbo_target, struct wined3d_surface *depth_stencil, DWORD location) { const struct wined3d_gl_info *gl_info = context->gl_info; @@ -201,41 +139,51 @@ void context_attach_depth_stencil_fbo(struct wined3d_context *context, { DWORD format_flags = depth_stencil->resource.format->flags; - if (use_render_buffer && depth_stencil->current_renderbuffer) + if (depth_stencil->current_renderbuffer) { - if (format_flags & WINED3DFMT_FLAG_DEPTH) - { - gl_info->fbo_ops.glFramebufferRenderbuffer(fbo_target, GL_DEPTH_ATTACHMENT, - GL_RENDERBUFFER, depth_stencil->current_renderbuffer->id); - checkGLcall("glFramebufferRenderbuffer()"); - } - - if (format_flags & WINED3DFMT_FLAG_STENCIL) - { - gl_info->fbo_ops.glFramebufferRenderbuffer(fbo_target, GL_STENCIL_ATTACHMENT, - GL_RENDERBUFFER, depth_stencil->current_renderbuffer->id); - checkGLcall("glFramebufferRenderbuffer()"); - } + context_attach_depth_stencil_rb(gl_info, fbo_target, + format_flags, depth_stencil->current_renderbuffer->id); } else { - surface_prepare_texture(depth_stencil, gl_info, FALSE); - context_apply_attachment_filter_states(context, depth_stencil, SFLAG_INTEXTURE); - - if (format_flags & WINED3DFMT_FLAG_DEPTH) + switch (location) { - gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_DEPTH_ATTACHMENT, - depth_stencil->texture_target, depth_stencil->texture_name, - depth_stencil->texture_level); - checkGLcall("glFramebufferTexture2D()"); - } + case SFLAG_INTEXTURE: + case SFLAG_INSRGBTEX: + surface_prepare_texture(depth_stencil, context, FALSE); - if (format_flags & WINED3DFMT_FLAG_STENCIL) - { - gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_STENCIL_ATTACHMENT, - depth_stencil->texture_target, depth_stencil->texture_name, - depth_stencil->texture_level); - checkGLcall("glFramebufferTexture2D()"); + if (format_flags & WINED3DFMT_FLAG_DEPTH) + { + gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_DEPTH_ATTACHMENT, + depth_stencil->texture_target, depth_stencil->texture_name, + depth_stencil->texture_level); + checkGLcall("glFramebufferTexture2D()"); + } + + if (format_flags & WINED3DFMT_FLAG_STENCIL) + { + gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_STENCIL_ATTACHMENT, + depth_stencil->texture_target, depth_stencil->texture_name, + depth_stencil->texture_level); + checkGLcall("glFramebufferTexture2D()"); + } + break; + + case SFLAG_INRB_MULTISAMPLE: + surface_prepare_rb(depth_stencil, gl_info, TRUE); + context_attach_depth_stencil_rb(gl_info, fbo_target, + format_flags, depth_stencil->rb_multisample); + break; + + case SFLAG_INRB_RESOLVED: + surface_prepare_rb(depth_stencil, gl_info, FALSE); + context_attach_depth_stencil_rb(gl_info, fbo_target, + format_flags, depth_stencil->rb_resolved); + break; + + default: + ERR("Unsupported location %s (%#x).\n", debug_surflocation(location), location); + break; } } @@ -262,7 +210,7 @@ void context_attach_depth_stencil_fbo(struct wined3d_context *context, } /* GL locking is done by the caller */ -static void context_attach_surface_fbo(const struct wined3d_context *context, +static void context_attach_surface_fbo(struct wined3d_context *context, GLenum fbo_target, DWORD idx, struct wined3d_surface *surface, DWORD location) { const struct wined3d_gl_info *gl_info = context->gl_info; @@ -278,18 +226,31 @@ static void context_attach_surface_fbo(const struct wined3d_context *context, case SFLAG_INTEXTURE: case SFLAG_INSRGBTEX: srgb = location == SFLAG_INSRGBTEX; - surface_prepare_texture(surface, gl_info, srgb); - context_apply_attachment_filter_states(context, surface, location); + surface_prepare_texture(surface, context, srgb); gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_COLOR_ATTACHMENT0 + idx, surface->texture_target, surface_get_texture_name(surface, gl_info, srgb), surface->texture_level); + checkGLcall("glFramebufferTexture2D()"); + break; + + case SFLAG_INRB_MULTISAMPLE: + surface_prepare_rb(surface, gl_info, TRUE); + gl_info->fbo_ops.glFramebufferRenderbuffer(fbo_target, GL_COLOR_ATTACHMENT0 + idx, + GL_RENDERBUFFER, surface->rb_multisample); + checkGLcall("glFramebufferRenderbuffer()"); + break; + + case SFLAG_INRB_RESOLVED: + surface_prepare_rb(surface, gl_info, FALSE); + gl_info->fbo_ops.glFramebufferRenderbuffer(fbo_target, GL_COLOR_ATTACHMENT0 + idx, + GL_RENDERBUFFER, surface->rb_resolved); + checkGLcall("glFramebufferRenderbuffer()"); break; default: ERR("Unsupported location %s (%#x).\n", debug_surflocation(location), location); break; } - checkGLcall("glFramebufferTexture2D()"); } else { @@ -299,11 +260,13 @@ static void context_attach_surface_fbo(const struct wined3d_context *context, } /* GL locking is done by the caller */ -void context_check_fbo_status(struct wined3d_context *context, GLenum target) +void context_check_fbo_status(const struct wined3d_context *context, GLenum target) { const struct wined3d_gl_info *gl_info = context->gl_info; GLenum status; + if (!FIXME_ON(d3d)) return; + status = gl_info->fbo_ops.glCheckFramebufferStatus(target); if (status == GL_FRAMEBUFFER_COMPLETE) { @@ -311,7 +274,7 @@ void context_check_fbo_status(struct wined3d_context *context, GLenum target) } else { - struct wined3d_surface *attachment; + const struct wined3d_surface *attachment; unsigned int i; FIXME("FBO status %s (%#x)\n", debug_fbostatus(status), status); @@ -331,22 +294,33 @@ void context_check_fbo_status(struct wined3d_context *context, GLenum target) attachment = context->current_fbo->render_targets[i]; if (attachment) { - FIXME("\tColor attachment %d: (%p) %s %ux%u\n", + FIXME("\tColor attachment %d: (%p) %s %ux%u %u samples.\n", i, attachment, debug_d3dformat(attachment->resource.format->id), - attachment->pow2Width, attachment->pow2Height); + attachment->pow2Width, attachment->pow2Height, attachment->resource.multisample_type); } } attachment = context->current_fbo->depth_stencil; if (attachment) { - FIXME("\tDepth attachment: (%p) %s %ux%u\n", + FIXME("\tDepth attachment: (%p) %s %ux%u %u samples.\n", attachment, debug_d3dformat(attachment->resource.format->id), - attachment->pow2Width, attachment->pow2Height); + attachment->pow2Width, attachment->pow2Height, attachment->resource.multisample_type); } } } -static struct fbo_entry *context_create_fbo_entry(struct wined3d_context *context, +static inline DWORD context_generate_rt_mask(GLenum buffer) +{ + /* Should take care of all the GL_FRONT/GL_BACK/GL_AUXi/GL_NONE... cases */ + return buffer ? (1 << 31) | buffer : 0; +} + +static inline DWORD context_generate_rt_mask_from_surface(const struct wined3d_surface *target) +{ + return (1 << 31) | surface_get_gl_buffer(target); +} + +static struct fbo_entry *context_create_fbo_entry(const struct wined3d_context *context, struct wined3d_surface **render_targets, struct wined3d_surface *depth_stencil, DWORD location) { const struct wined3d_gl_info *gl_info = context->gl_info; @@ -357,6 +331,7 @@ static struct fbo_entry *context_create_fbo_entry(struct wined3d_context *contex memcpy(entry->render_targets, render_targets, gl_info->limits.buffers * sizeof(*entry->render_targets)); entry->depth_stencil = depth_stencil; entry->location = location; + entry->rt_mask = context_generate_rt_mask(GL_COLOR_ATTACHMENT0); entry->attached = FALSE; entry->id = 0; @@ -448,31 +423,20 @@ static void context_apply_fbo_entry(struct wined3d_context *context, GLenum targ context_bind_fbo(context, target, &entry->id); - if (!entry->attached) - { - /* Apply render targets */ - for (i = 0; i < gl_info->limits.buffers; ++i) - { - context_attach_surface_fbo(context, target, i, entry->render_targets[i], entry->location); - } + if (entry->attached) return; - /* Apply depth targets */ - if (entry->depth_stencil) - surface_set_compatible_renderbuffer(entry->depth_stencil, entry->render_targets[0]); - context_attach_depth_stencil_fbo(context, target, entry->depth_stencil, TRUE); - - entry->attached = TRUE; - } - else + /* Apply render targets */ + for (i = 0; i < gl_info->limits.buffers; ++i) { - for (i = 0; i < gl_info->limits.buffers; ++i) - { - if (entry->render_targets[i]) - context_apply_attachment_filter_states(context, entry->render_targets[i], entry->location); - } - if (entry->depth_stencil) - context_apply_attachment_filter_states(context, entry->depth_stencil, SFLAG_INTEXTURE); + context_attach_surface_fbo(context, target, i, entry->render_targets[i], entry->location); } + + /* Apply depth targets */ + if (entry->depth_stencil) + surface_set_compatible_renderbuffer(entry->depth_stencil, entry->render_targets[0]); + context_attach_depth_stencil_fbo(context, target, entry->depth_stencil, entry->location); + + entry->attached = TRUE; } /* GL locking is done by the caller */ @@ -492,33 +456,28 @@ static void context_apply_fbo_state(struct wined3d_context *context, GLenum targ context->rebind_fbo = FALSE; } - if (render_targets) - { - context->current_fbo = context_find_fbo_entry(context, target, render_targets, depth_stencil, location); - context_apply_fbo_entry(context, target, context->current_fbo); - } - else + if (location == SFLAG_INDRAWABLE) { context->current_fbo = NULL; context_bind_fbo(context, target, NULL); } + else + { + context->current_fbo = context_find_fbo_entry(context, target, render_targets, depth_stencil, location); + context_apply_fbo_entry(context, target, context->current_fbo); + } } /* GL locking is done by the caller */ void context_apply_fbo_state_blit(struct wined3d_context *context, GLenum target, struct wined3d_surface *render_target, struct wined3d_surface *depth_stencil, DWORD location) { - if (location != SFLAG_INDRAWABLE || surface_is_offscreen(render_target)) - { - UINT clear_size = (context->gl_info->limits.buffers - 1) * sizeof(*context->blit_targets); - context->blit_targets[0] = render_target; - if (clear_size) memset(&context->blit_targets[1], 0, clear_size); - context_apply_fbo_state(context, target, context->blit_targets, depth_stencil, location); - } - else - { - context_apply_fbo_state(context, target, NULL, NULL, location); - } + UINT clear_size = (context->gl_info->limits.buffers - 1) * sizeof(*context->blit_targets); + + context->blit_targets[0] = render_target; + if (clear_size) + memset(&context->blit_targets[1], 0, clear_size); + context_apply_fbo_state(context, target, context->blit_targets, depth_stencil, location); } /* Context activation is done by the caller. */ @@ -652,8 +611,8 @@ void context_free_event_query(struct wined3d_event_query *query) typedef void (context_fbo_entry_func_t)(struct wined3d_context *context, struct fbo_entry *entry); -static void context_enum_surface_fbo_entries(struct wined3d_device *device, - struct wined3d_surface *surface, context_fbo_entry_func_t *callback) +static void context_enum_surface_fbo_entries(const struct wined3d_device *device, + const struct wined3d_surface *surface, context_fbo_entry_func_t *callback) { UINT i; @@ -693,14 +652,14 @@ static void context_queue_fbo_entry_destruction(struct wined3d_context *context, list_add_head(&context->fbo_destroy_list, &entry->entry); } -void context_resource_released(struct wined3d_device *device, - struct wined3d_resource *resource, WINED3DRESOURCETYPE type) +void context_resource_released(const struct wined3d_device *device, + struct wined3d_resource *resource, enum wined3d_resource_type type) { if (!device->d3d_initialized) return; switch (type) { - case WINED3DRTYPE_SURFACE: + case WINED3D_RTYPE_SURFACE: context_enum_surface_fbo_entries(device, surface_from_resource(resource), context_queue_fbo_entry_destruction); break; @@ -715,12 +674,12 @@ static void context_detach_fbo_entry(struct wined3d_context *context, struct fbo entry->attached = FALSE; } -void context_resource_unloaded(struct wined3d_device *device, - struct wined3d_resource *resource, WINED3DRESOURCETYPE type) +void context_resource_unloaded(const struct wined3d_device *device, + struct wined3d_resource *resource, enum wined3d_resource_type type) { switch (type) { - case WINED3DRTYPE_SURFACE: + case WINED3D_RTYPE_SURFACE: context_enum_surface_fbo_entries(device, surface_from_resource(resource), context_detach_fbo_entry); break; @@ -730,7 +689,7 @@ void context_resource_unloaded(struct wined3d_device *device, } } -void context_surface_update(struct wined3d_context *context, struct wined3d_surface *surface) +void context_surface_update(struct wined3d_context *context, const struct wined3d_surface *surface) { const struct wined3d_gl_info *gl_info = context->gl_info; struct fbo_entry *entry = context->current_fbo; @@ -765,7 +724,8 @@ static BOOL context_set_pixel_format(const struct wined3d_gl_info *gl_info, HDC { if (!SetPixelFormat(dc, format, NULL)) { - ERR("Failed to set pixel format %d on device context %p, last error %#x.\n", + /* This may also happen if the dc belongs to a destroyed window. */ + WARN("Failed to set pixel format %d on device context %p, last error %#x.\n", format, dc, GetLastError()); return FALSE; } @@ -799,65 +759,69 @@ static BOOL context_set_pixel_format(const struct wined3d_gl_info *gl_info, HDC static BOOL context_set_gl_context(struct wined3d_context *ctx) { struct wined3d_swapchain *swapchain = ctx->swapchain; + BOOL backup = FALSE; - if (!pwglMakeCurrent(ctx->hdc, ctx->glCtx)) + if (!context_set_pixel_format(ctx->gl_info, ctx->hdc, ctx->pixel_format)) { + WARN("Failed to set pixel format %d on device context %p.\n", + ctx->pixel_format, ctx->hdc); + backup = TRUE; + } + + if (backup || !pwglMakeCurrent(ctx->hdc, ctx->glCtx)) + { + HDC dc; + WARN("Failed to make GL context %p current on device context %p, last error %#x.\n", ctx->glCtx, ctx->hdc, GetLastError()); ctx->valid = 0; WARN("Trying fallback to the backup window.\n"); - if (!swapchain->backup_dc) + /* FIXME: If the context is destroyed it's no longer associated with + * a swapchain, so we can't use the swapchain to get a backup dc. To + * make this work windowless contexts would need to be handled by the + * device. */ + if (ctx->destroyed) { - TRACE("Creating the backup window for swapchain %p.\n", swapchain); - swapchain->backup_wnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window", - WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL); - if (!swapchain->backup_wnd) - { - ERR("Failed to create a window.\n"); - goto fail; - } - swapchain->backup_dc = GetDC(swapchain->backup_wnd); - if (!swapchain->backup_dc) - { - ERR("Failed to get a DC.\n"); - goto fail; - } - if (!context_set_pixel_format(ctx->gl_info, swapchain->backup_dc, ctx->pixel_format)) - { - ERR("Failed to set pixel format %d on device context %p.\n", - ctx->pixel_format, swapchain->backup_dc); - goto fail; - } + FIXME("Unable to get backup dc for destroyed context %p.\n", ctx); + context_set_current(NULL); + return FALSE; } - if (!pwglMakeCurrent(swapchain->backup_dc, ctx->glCtx)) + if (!(dc = swapchain_get_backup_dc(swapchain))) + { + context_set_current(NULL); + return FALSE; + } + + if (!context_set_pixel_format(ctx->gl_info, dc, ctx->pixel_format)) + { + ERR("Failed to set pixel format %d on device context %p.\n", + ctx->pixel_format, dc); + context_set_current(NULL); + return FALSE; + } + + if (!pwglMakeCurrent(dc, ctx->glCtx)) { ERR("Fallback to backup window (dc %p) failed too, last error %#x.\n", - swapchain->backup_dc, GetLastError()); + dc, GetLastError()); context_set_current(NULL); return FALSE; } } return TRUE; - -fail: - if (swapchain->backup_dc) - { - ReleaseDC(swapchain->backup_wnd, swapchain->backup_dc); - swapchain->backup_dc = NULL; - } - if (swapchain->backup_wnd) - { - DestroyWindow(swapchain->backup_wnd); - swapchain->backup_wnd = NULL; - } - context_set_current(NULL); - return FALSE; } -static void context_restore_gl_context(HDC dc, HGLRC gl_ctx) +static void context_restore_gl_context(const struct wined3d_gl_info *gl_info, HDC dc, HGLRC gl_ctx, int pf) { + if (!context_set_pixel_format(gl_info, dc, pf)) + { + ERR("Failed to restore pixel format %d on device context %p.\n", pf, dc); + context_set_current(NULL); + return; + } + if (!pwglMakeCurrent(dc, gl_ctx)) { ERR("Failed to restore GL context %p on device context %p, last error %#x.\n", @@ -928,11 +892,12 @@ static void context_destroy_gl_resources(struct wined3d_context *context) HGLRC restore_ctx; HDC restore_dc; unsigned int i; + int restore_pf; restore_ctx = pwglGetCurrentContext(); restore_dc = pwglGetCurrentDC(); + restore_pf = GetPixelFormat(restore_dc); - context_update_window(context); if (context->valid && restore_ctx != context->glCtx) context_set_gl_context(context); else restore_ctx = NULL; @@ -974,11 +939,6 @@ static void context_destroy_gl_resources(struct wined3d_context *context) if (context->valid) { - if (context->dst_fbo) - { - TRACE("Destroy dst FBO %d\n", context->dst_fbo); - context_destroy_fbo(context, &context->dst_fbo); - } if (context->dummy_arbfp_prog) { GL_EXTCALL(glDeleteProgramsARB(1, &context->dummy_arbfp_prog)); @@ -1019,7 +979,7 @@ static void context_destroy_gl_resources(struct wined3d_context *context) if (restore_ctx) { - context_restore_gl_context(restore_dc, restore_ctx); + context_restore_gl_context(gl_info, restore_dc, restore_ctx, restore_pf); } else if (pwglGetCurrentContext() && !pwglMakeCurrent(NULL, NULL)) { @@ -1067,6 +1027,7 @@ BOOL context_set_current(struct wined3d_context *ctx) { TRACE("Switching away from destroyed context %p.\n", old); context_destroy_gl_resources(old); + HeapFree(GetProcessHeap(), 0, (void *)old->gl_info); HeapFree(GetProcessHeap(), 0, old); } else @@ -1118,7 +1079,7 @@ void context_release(struct wined3d_context *context) if (!--context->level && context->restore_ctx) { TRACE("Restoring GL context %p on device context %p.\n", context->restore_ctx, context->restore_dc); - context_restore_gl_context(context->restore_dc, context->restore_ctx); + context_restore_gl_context(context->gl_info, context->restore_dc, context->restore_ctx, context->restore_pf); context->restore_ctx = NULL; context->restore_dc = NULL; } @@ -1139,26 +1100,14 @@ static void context_enter(struct wined3d_context *context) current_gl, pwglGetCurrentDC()); context->restore_ctx = current_gl; context->restore_dc = pwglGetCurrentDC(); + context->restore_pf = GetPixelFormat(context->restore_dc); } } } -/***************************************************************************** - * Context_MarkStateDirty - * - * Marks a state in a context dirty. Only one context, opposed to - * IWineD3DDeviceImpl_MarkStateDirty, which marks the state dirty in all - * contexts - * - * Params: - * context: Context to mark the state dirty in - * state: State to mark dirty - * StateTable: Pointer to the state table in use(for state grouping) - * - *****************************************************************************/ -static void Context_MarkStateDirty(struct wined3d_context *context, DWORD state, const struct StateEntry *StateTable) +void context_invalidate_state(struct wined3d_context *context, DWORD state) { - DWORD rep = StateTable[state].representative; + DWORD rep = context->state_table[state].representative; DWORD idx; BYTE shift; @@ -1170,45 +1119,21 @@ static void Context_MarkStateDirty(struct wined3d_context *context, DWORD state, context->isStateDirty[idx] |= (1 << shift); } -/* This function takes care of WineD3D pixel format selection. */ -static int WineD3D_ChoosePixelFormat(struct wined3d_device *device, HDC hdc, +/* This function takes care of wined3d pixel format selection. */ +static int context_choose_pixel_format(const struct wined3d_device *device, HDC hdc, const struct wined3d_format *color_format, const struct wined3d_format *ds_format, - BOOL auxBuffers, int numSamples, BOOL findCompatible) + BOOL auxBuffers, BOOL findCompatible) { int iPixelFormat=0; - unsigned int matchtry; BYTE redBits, greenBits, blueBits, alphaBits, colorBits; BYTE depthBits=0, stencilBits=0; + unsigned int current_value; + unsigned int cfg_count = device->adapter->cfg_count; + unsigned int i; - static const struct - { - BOOL require_aux; - BOOL exact_alpha; - BOOL exact_color; - } - matches[] = - { - /* First, try without alpha match buffers. MacOS supports aux buffers only - * on A8R8G8B8, and we prefer better offscreen rendering over an alpha match. - * Then try without aux buffers - this is the most common cause for not - * finding a pixel format. Also some drivers(the open source ones) - * only offer 32 bit ARB pixel formats. First try without an exact alpha - * match, then try without an exact alpha and color match. - */ - { TRUE, TRUE, TRUE }, - { TRUE, FALSE, TRUE }, - { FALSE, TRUE, TRUE }, - { FALSE, FALSE, TRUE }, - { TRUE, FALSE, FALSE }, - { FALSE, FALSE, FALSE }, - }; - - int i = 0; - int nCfgs = device->adapter->nCfgs; - - TRACE("ColorFormat=%s, DepthStencilFormat=%s, auxBuffers=%d, numSamples=%d, findCompatible=%d\n", - debug_d3dformat(color_format->id), debug_d3dformat(ds_format->id), - auxBuffers, numSamples, findCompatible); + TRACE("device %p, dc %p, color_format %s, ds_format %s, aux_buffers %#x, find_compatible %#x.\n", + device, hdc, debug_d3dformat(color_format->id), debug_d3dformat(ds_format->id), + auxBuffers, findCompatible); if (!getColorBits(color_format, &redBits, &greenBits, &blueBits, &alphaBits, &colorBits)) { @@ -1219,84 +1144,56 @@ static int WineD3D_ChoosePixelFormat(struct wined3d_device *device, HDC hdc, getDepthStencilBits(ds_format, &depthBits, &stencilBits); - for (matchtry = 0; matchtry < (sizeof(matches) / sizeof(*matches)) && !iPixelFormat; ++matchtry) + current_value = 0; + for (i = 0; i < cfg_count; ++i) { - for (i = 0; i < nCfgs; ++i) + const struct wined3d_pixel_format *cfg = &device->adapter->cfgs[i]; + unsigned int value; + + /* For now only accept RGBA formats. Perhaps some day we will + * allow floating point formats for pbuffers. */ + if (cfg->iPixelType != WGL_TYPE_RGBA_ARB) + continue; + /* In window mode we need a window drawable format and double buffering. */ + if (!(cfg->windowDrawable && cfg->doubleBuffer)) + continue; + if (cfg->redSize < redBits) + continue; + if (cfg->greenSize < greenBits) + continue; + if (cfg->blueSize < blueBits) + continue; + if (cfg->alphaSize < alphaBits) + continue; + if (cfg->depthSize < depthBits) + continue; + if (stencilBits && cfg->stencilSize != stencilBits) + continue; + /* Check multisampling support. */ + if (cfg->numSamples) + continue; + + value = 1; + /* We try to locate a format which matches our requirements exactly. In case of + * depth it is no problem to emulate 16-bit using e.g. 24-bit, so accept that. */ + if (cfg->depthSize == depthBits) + value += 1; + if (cfg->stencilSize == stencilBits) + value += 2; + if (cfg->alphaSize == alphaBits) + value += 4; + /* We like to have aux buffers in backbuffer mode */ + if (auxBuffers && cfg->auxBuffers) + value += 8; + if (cfg->redSize == redBits + && cfg->greenSize == greenBits + && cfg->blueSize == blueBits) + value += 16; + + if (value > current_value) { - const struct wined3d_pixel_format *cfg = &device->adapter->cfgs[i]; - BOOL exactDepthMatch = TRUE; - - /* For now only accept RGBA formats. Perhaps some day we will - * allow floating point formats for pbuffers. */ - if(cfg->iPixelType != WGL_TYPE_RGBA_ARB) - continue; - - /* In window mode we need a window drawable format and double buffering. */ - if(!(cfg->windowDrawable && cfg->doubleBuffer)) - continue; - - /* We like to have aux buffers in backbuffer mode */ - if(auxBuffers && !cfg->auxBuffers && matches[matchtry].require_aux) - continue; - - if(matches[matchtry].exact_color) { - if(cfg->redSize != redBits) - continue; - if(cfg->greenSize != greenBits) - continue; - if(cfg->blueSize != blueBits) - continue; - } else { - if(cfg->redSize < redBits) - continue; - if(cfg->greenSize < greenBits) - continue; - if(cfg->blueSize < blueBits) - continue; - } - if(matches[matchtry].exact_alpha) { - if(cfg->alphaSize != alphaBits) - continue; - } else { - if(cfg->alphaSize < alphaBits) - continue; - } - - /* We try to locate a format which matches our requirements exactly. In case of - * depth it is no problem to emulate 16-bit using e.g. 24-bit, so accept that. */ - if(cfg->depthSize < depthBits) - continue; - else if(cfg->depthSize > depthBits) - exactDepthMatch = FALSE; - - /* In all cases make sure the number of stencil bits matches our requirements - * even when we don't need stencil because it could affect performance EXCEPT - * on cards which don't offer depth formats without stencil like the i915 drivers - * on Linux. */ - if (stencilBits != cfg->stencilSize - && !(device->adapter->brokenStencil && stencilBits <= cfg->stencilSize)) - continue; - - /* Check multisampling support */ - if(cfg->numSamples != numSamples) - continue; - - /* When we have passed all the checks then we have found a format which matches our - * requirements. Note that we only check for a limit number of capabilities right now, - * so there can easily be a dozen of pixel formats which appear to be the 'same' but - * can still differ in things like multisampling, stereo, SRGB and other flags. - */ - - /* Exit the loop as we have found a format :) */ - if(exactDepthMatch) { - iPixelFormat = cfg->iPixelFormat; - break; - } else if(!iPixelFormat) { - /* In the end we might end up with a format which doesn't exactly match our depth - * requirements. Accept the first format we found because formats with higher iPixelFormat - * values tend to have more extended capabilities (e.g. multisampling) which we don't need. */ - iPixelFormat = cfg->iPixelFormat; - } + iPixelFormat = cfg->iPixelFormat; + current_value = value; } } @@ -1333,6 +1230,40 @@ static int WineD3D_ChoosePixelFormat(struct wined3d_device *device, HDC hdc, return iPixelFormat; } +/* GL locking is done by the caller */ +static void bind_dummy_textures(const struct wined3d_device *device, const struct wined3d_context *context) +{ + const struct wined3d_gl_info *gl_info = context->gl_info; + unsigned int i, count = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers); + + for (i = 0; i < count; ++i) + { + GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i)); + checkGLcall("glActiveTextureARB"); + + glBindTexture(GL_TEXTURE_2D, device->dummy_texture_2d[i]); + checkGLcall("glBindTexture"); + + if (gl_info->supported[ARB_TEXTURE_RECTANGLE]) + { + glBindTexture(GL_TEXTURE_RECTANGLE_ARB, device->dummy_texture_rect[i]); + checkGLcall("glBindTexture"); + } + + if (gl_info->supported[EXT_TEXTURE3D]) + { + glBindTexture(GL_TEXTURE_3D, device->dummy_texture_3d[i]); + checkGLcall("glBindTexture"); + } + + if (gl_info->supported[ARB_TEXTURE_CUBE_MAP]) + { + glBindTexture(GL_TEXTURE_CUBE_MAP, device->dummy_texture_cube[i]); + checkGLcall("glBindTexture"); + } + } +} + /* Do not call while under the GL lock. */ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, struct wined3d_surface *target, const struct wined3d_format *ds_format) @@ -1341,9 +1272,7 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; const struct wined3d_format *color_format; struct wined3d_context *ret; - PIXELFORMATDESCRIPTOR pfd; BOOL auxBuffers = FALSE; - int numSamples = 0; int pixel_format; unsigned int s; int swap_interval; @@ -1360,10 +1289,43 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, return NULL; } + ret->blit_targets = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, + gl_info->limits.buffers * sizeof(*ret->blit_targets)); + if (!ret->blit_targets) + goto out; + + ret->draw_buffers = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, + gl_info->limits.buffers * sizeof(*ret->draw_buffers)); + if (!ret->draw_buffers) + goto out; + + ret->free_occlusion_query_size = 4; + ret->free_occlusion_queries = HeapAlloc(GetProcessHeap(), 0, + ret->free_occlusion_query_size * sizeof(*ret->free_occlusion_queries)); + if (!ret->free_occlusion_queries) + goto out; + + list_init(&ret->occlusion_queries); + + ret->free_event_query_size = 4; + ret->free_event_queries = HeapAlloc(GetProcessHeap(), 0, + ret->free_event_query_size * sizeof(*ret->free_event_queries)); + if (!ret->free_event_queries) + goto out; + + list_init(&ret->event_queries); + list_init(&ret->fbo_list); + list_init(&ret->fbo_destroy_list); + if (!(hdc = GetDC(swapchain->win_handle))) { - ERR("Failed to retrieve a device context.\n"); - goto out; + WARN("Failed to retireve device context, trying swapchain backup.\n"); + + if (!(hdc = swapchain_get_backup_dc(swapchain))) + { + ERR("Failed to retrieve a device context.\n"); + goto out; + } } color_format = target->resource.format; @@ -1389,28 +1351,14 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, if (color_format->id == WINED3DFMT_P8_UINT) color_format = wined3d_get_format(gl_info, WINED3DFMT_B8G8R8A8_UNORM); - /* D3D only allows multisampling when SwapEffect is set to WINED3DSWAPEFFECT_DISCARD. */ - if (swapchain->presentParms.MultiSampleType && (swapchain->presentParms.SwapEffect == WINED3DSWAPEFFECT_DISCARD)) - { - if (!gl_info->supported[ARB_MULTISAMPLE]) - WARN("The application is requesting multisampling without support.\n"); - else - { - TRACE("Requesting multisample type %#x.\n", swapchain->presentParms.MultiSampleType); - numSamples = swapchain->presentParms.MultiSampleType; - } - } - /* Try to find a pixel format which matches our requirements. */ - pixel_format = WineD3D_ChoosePixelFormat(device, hdc, color_format, ds_format, - auxBuffers, numSamples, FALSE /* findCompatible */); + pixel_format = context_choose_pixel_format(device, hdc, color_format, ds_format, auxBuffers, FALSE); /* Try to locate a compatible format if we weren't able to find anything. */ if (!pixel_format) { TRACE("Trying to locate a compatible pixel format because an exact match failed.\n"); - pixel_format = WineD3D_ChoosePixelFormat(device, hdc, color_format, ds_format, - auxBuffers, 0 /* numSamples */, TRUE /* findCompatible */); + pixel_format = context_choose_pixel_format(device, hdc, color_format, ds_format, auxBuffers, TRUE); } /* If we still don't have a pixel format, something is very wrong as ChoosePixelFormat barely fails */ @@ -1420,48 +1368,53 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, goto out; } - DescribePixelFormat(hdc, pixel_format, sizeof(pfd), &pfd); + context_enter(ret); + if (!context_set_pixel_format(gl_info, hdc, pixel_format)) { ERR("Failed to set pixel format %d on device context %p.\n", pixel_format, hdc); + context_release(ret); + goto out; + } + + if (!(ctx = pwglCreateContext(hdc))) + { + ERR("Failed to create a WGL context.\n"); + context_release(ret); goto out; } - ctx = pwglCreateContext(hdc); if (device->context_count) { if (!pwglShareLists(device->contexts[0]->glCtx, ctx)) { - DWORD err = GetLastError(); ERR("wglShareLists(%p, %p) failed, last error %#x.\n", - device->contexts[0]->glCtx, ctx, err); + device->contexts[0]->glCtx, ctx, GetLastError()); + context_release(ret); + if (!pwglDeleteContext(ctx)) + ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx, GetLastError()); + goto out; } } - if(!ctx) { - ERR("Failed to create a WGL context\n"); - goto out; - } - if (!device_context_add(device, ret)) { ERR("Failed to add the newly created context to the context list\n"); + context_release(ret); if (!pwglDeleteContext(ctx)) - { - DWORD err = GetLastError(); - ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx, err); - } + ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx, GetLastError()); goto out; } ret->gl_info = gl_info; + ret->state_table = device->StateTable; /* Mark all states dirty to force a proper initialization of the states * on the first use of the context. */ for (state = 0; state <= STATE_HIGHEST; ++state) { - if (device->StateTable[state].representative) - Context_MarkStateDirty(ret, state, device->StateTable); + if (ret->state_table[state].representative) + context_invalidate_state(ret, state); } ret->swapchain = swapchain; @@ -1469,7 +1422,7 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, ret->tid = GetCurrentThreadId(); ret->render_offscreen = surface_is_offscreen(target); - ret->draw_buffer_dirty = TRUE; + ret->draw_buffers_mask = context_generate_rt_mask(GL_BACK); ret->valid = 1; ret->glCtx = ctx; @@ -1477,57 +1430,18 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, ret->hdc = hdc; ret->pixel_format = pixel_format; - if (device->shader_backend->shader_dirtifyable_constants()) - { - /* Create the dirty constants array and initialize them to dirty */ - ret->vshader_const_dirty = HeapAlloc(GetProcessHeap(), 0, - sizeof(*ret->vshader_const_dirty) * device->d3d_vshader_constantF); - ret->pshader_const_dirty = HeapAlloc(GetProcessHeap(), 0, - sizeof(*ret->pshader_const_dirty) * device->d3d_pshader_constantF); - memset(ret->vshader_const_dirty, 1, - sizeof(*ret->vshader_const_dirty) * device->d3d_vshader_constantF); - memset(ret->pshader_const_dirty, 1, - sizeof(*ret->pshader_const_dirty) * device->d3d_pshader_constantF); - } - - ret->blit_targets = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, - gl_info->limits.buffers * sizeof(*ret->blit_targets)); - if (!ret->blit_targets) goto out; - - ret->draw_buffers = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, - gl_info->limits.buffers * sizeof(*ret->draw_buffers)); - if (!ret->draw_buffers) goto out; - - ret->free_occlusion_query_size = 4; - ret->free_occlusion_queries = HeapAlloc(GetProcessHeap(), 0, - ret->free_occlusion_query_size * sizeof(*ret->free_occlusion_queries)); - if (!ret->free_occlusion_queries) goto out; - - list_init(&ret->occlusion_queries); - - ret->free_event_query_size = 4; - ret->free_event_queries = HeapAlloc(GetProcessHeap(), 0, - ret->free_event_query_size * sizeof(*ret->free_event_queries)); - if (!ret->free_event_queries) goto out; - - list_init(&ret->event_queries); - - TRACE("Successfully created new context %p\n", ret); - - list_init(&ret->fbo_list); - list_init(&ret->fbo_destroy_list); - - context_enter(ret); - /* Set up the context defaults */ if (!context_set_current(ret)) { - ERR("Cannot activate context to set up defaults\n"); + ERR("Cannot activate context to set up defaults.\n"); + device_context_remove(device, ret); context_release(ret); + if (!pwglDeleteContext(ctx)) + ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx, GetLastError()); goto out; } - switch (swapchain->presentParms.PresentationInterval) + switch (swapchain->desc.swap_interval) { case WINED3DPRESENT_INTERVAL_IMMEDIATE: swap_interval = 0; @@ -1546,7 +1460,7 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, swap_interval = 4; break; default: - FIXME("Unknown presentation interval %08x\n", swapchain->presentParms.PresentationInterval); + FIXME("Unknown swap interval %#x.\n", swapchain->desc.swap_interval); swap_interval = 1; } @@ -1609,7 +1523,7 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, */ for (s = 1; s < gl_info->limits.textures; ++s) { - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + s)); + context_active_texture(ret, gl_info, s); glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + s - 1); checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, ..."); } @@ -1634,11 +1548,14 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(dummy_program), dummy_program)); } - for (s = 0; s < gl_info->limits.point_sprite_units; ++s) + if (gl_info->supported[ARB_POINT_SPRITE]) { - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + s)); - glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE); - checkGLcall("glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE)"); + for (s = 0; s < gl_info->limits.textures; ++s) + { + context_active_texture(ret, gl_info, s); + glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE); + checkGLcall("glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE)"); + } } if (gl_info->supported[ARB_PROVOKING_VERTEX]) @@ -1651,6 +1568,12 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, } device->frag_pipe->enable_extension(TRUE); + /* If this happens to be the first context for the device, dummy textures + * are not created yet. In that case, they will be created (and bound) by + * create_dummy_textures right after this context is initialized. */ + if (device->dummy_texture_2d[0]) + bind_dummy_textures(device, ret); + LEAVE_GL(); TRACE("Created context %p.\n", ret); @@ -1662,8 +1585,6 @@ out: HeapFree(GetProcessHeap(), 0, ret->free_occlusion_queries); HeapFree(GetProcessHeap(), 0, ret->draw_buffers); HeapFree(GetProcessHeap(), 0, ret->blit_targets); - HeapFree(GetProcessHeap(), 0, ret->pshader_const_dirty); - HeapFree(GetProcessHeap(), 0, ret->vshader_const_dirty); HeapFree(GetProcessHeap(), 0, ret); return NULL; } @@ -1683,26 +1604,36 @@ void context_destroy(struct wined3d_device *device, struct wined3d_context *cont } else { + /* Make a copy of gl_info for context_destroy_gl_resources use, the one + in wined3d_adapter may go away in the meantime */ + struct wined3d_gl_info *gl_info = HeapAlloc(GetProcessHeap(), 0, sizeof(*gl_info)); + *gl_info = *context->gl_info; + context->gl_info = gl_info; context->destroyed = 1; destroy = FALSE; } HeapFree(GetProcessHeap(), 0, context->draw_buffers); HeapFree(GetProcessHeap(), 0, context->blit_targets); - HeapFree(GetProcessHeap(), 0, context->vshader_const_dirty); - HeapFree(GetProcessHeap(), 0, context->pshader_const_dirty); device_context_remove(device, context); if (destroy) HeapFree(GetProcessHeap(), 0, context); } /* GL locking is done by the caller */ -static inline void set_blit_dimension(UINT width, UINT height) { +static void set_blit_dimension(UINT width, UINT height) +{ + const GLdouble projection[] = + { + 2.0 / width, 0.0, 0.0, 0.0, + 0.0, 2.0 / height, 0.0, 0.0, + 0.0, 0.0, 2.0, 0.0, + -1.0, -1.0, -1.0, 1.0, + }; + glMatrixMode(GL_PROJECTION); checkGLcall("glMatrixMode(GL_PROJECTION)"); - glLoadIdentity(); - checkGLcall("glLoadIdentity()"); - glOrtho(0, width, 0, height, 0.0, -1.0); - checkGLcall("glOrtho"); + glLoadMatrixd(projection); + checkGLcall("glLoadMatrixd"); glViewport(0, 0, width, height); checkGLcall("glViewport"); } @@ -1724,10 +1655,9 @@ static inline void set_blit_dimension(UINT width, UINT height) { * *****************************************************************************/ /* Context activation is done by the caller. */ -static void SetupForBlit(struct wined3d_device *device, struct wined3d_context *context) +static void SetupForBlit(const struct wined3d_device *device, struct wined3d_context *context) { int i; - const struct StateEntry *StateTable = device->StateTable; const struct wined3d_gl_info *gl_info = context->gl_info; UINT width = context->current_rt->resource.width; UINT height = context->current_rt->resource.height; @@ -1757,11 +1687,11 @@ static void SetupForBlit(struct wined3d_device *device, struct wined3d_context * device->shader_backend->shader_select(context, FALSE, FALSE); LEAVE_GL(); - Context_MarkStateDirty(context, STATE_VSHADER, StateTable); - Context_MarkStateDirty(context, STATE_PIXELSHADER, StateTable); + context_invalidate_state(context, STATE_VSHADER); + context_invalidate_state(context, STATE_PIXELSHADER); /* Call ENTER_GL() once for all gl calls below. In theory we should not call - * helper functions in between gl calls. This function is full of Context_MarkStateDirty + * helper functions in between gl calls. This function is full of context_invalidate_state * which can safely be called from here, we only lock once instead locking/unlocking * after each GL call. */ @@ -1776,8 +1706,7 @@ static void SetupForBlit(struct wined3d_device *device, struct wined3d_context * for (i = gl_info->limits.textures - 1; i > 0 ; --i) { sampler = device->rev_tex_unit_map[i]; - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i)); - checkGLcall("glActiveTextureARB"); + context_active_texture(context, gl_info, i); if (gl_info->supported[ARB_TEXTURE_CUBE_MAP]) { @@ -1799,14 +1728,12 @@ static void SetupForBlit(struct wined3d_device *device, struct wined3d_context * if (sampler != WINED3D_UNMAPPED_STAGE) { - if (sampler < MAX_TEXTURES) { - Context_MarkStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP), StateTable); - } - Context_MarkStateDirty(context, STATE_SAMPLER(sampler), StateTable); + if (sampler < MAX_TEXTURES) + context_invalidate_state(context, STATE_TEXTURESTAGE(sampler, WINED3D_TSS_COLOR_OP)); + context_invalidate_state(context, STATE_SAMPLER(sampler)); } } - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB)); - checkGLcall("glActiveTextureARB"); + context_active_texture(context, gl_info, 0); sampler = device->rev_tex_unit_map[0]; @@ -1842,54 +1769,55 @@ static void SetupForBlit(struct wined3d_device *device, struct wined3d_context * if (sampler != WINED3D_UNMAPPED_STAGE) { - if (sampler < MAX_TEXTURES) { - Context_MarkStateDirty(context, STATE_TRANSFORM(WINED3DTS_TEXTURE0 + sampler), StateTable); - Context_MarkStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP), StateTable); + if (sampler < MAX_TEXTURES) + { + context_invalidate_state(context, STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + sampler)); + context_invalidate_state(context, STATE_TEXTURESTAGE(sampler, WINED3D_TSS_COLOR_OP)); } - Context_MarkStateDirty(context, STATE_SAMPLER(sampler), StateTable); + context_invalidate_state(context, STATE_SAMPLER(sampler)); } /* Other misc states */ glDisable(GL_ALPHA_TEST); checkGLcall("glDisable(GL_ALPHA_TEST)"); - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHATESTENABLE), StateTable); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ALPHATESTENABLE)); glDisable(GL_LIGHTING); checkGLcall("glDisable GL_LIGHTING"); - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_LIGHTING), StateTable); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_LIGHTING)); glDisable(GL_DEPTH_TEST); checkGLcall("glDisable GL_DEPTH_TEST"); - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ZENABLE), StateTable); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ZENABLE)); glDisableWINE(GL_FOG); checkGLcall("glDisable GL_FOG"); - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_FOGENABLE), StateTable); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_FOGENABLE)); glDisable(GL_BLEND); checkGLcall("glDisable GL_BLEND"); - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), StateTable); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE)); glDisable(GL_CULL_FACE); checkGLcall("glDisable GL_CULL_FACE"); - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_CULLMODE), StateTable); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_CULLMODE)); glDisable(GL_STENCIL_TEST); checkGLcall("glDisable GL_STENCIL_TEST"); - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_STENCILENABLE), StateTable); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_STENCILENABLE)); glDisable(GL_SCISSOR_TEST); checkGLcall("glDisable GL_SCISSOR_TEST"); - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE), StateTable); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE)); if (gl_info->supported[ARB_POINT_SPRITE]) { glDisable(GL_POINT_SPRITE_ARB); checkGLcall("glDisable GL_POINT_SPRITE_ARB"); - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_POINTSPRITEENABLE), StateTable); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE)); } glColorMask(GL_TRUE, GL_TRUE,GL_TRUE,GL_TRUE); checkGLcall("glColorMask"); - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_COLORWRITEENABLE), StateTable); - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_COLORWRITEENABLE1), StateTable); - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_COLORWRITEENABLE2), StateTable); - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_COLORWRITEENABLE3), StateTable); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3)); if (gl_info->supported[EXT_SECONDARY_COLOR]) { glDisable(GL_COLOR_SUM_EXT); - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SPECULARENABLE), StateTable); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SPECULARENABLE)); checkGLcall("glDisable(GL_COLOR_SUM_EXT)"); } @@ -1898,10 +1826,10 @@ static void SetupForBlit(struct wined3d_device *device, struct wined3d_context * checkGLcall("glMatrixMode(GL_MODELVIEW)"); glLoadIdentity(); checkGLcall("glLoadIdentity()"); - Context_MarkStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), StateTable); + context_invalidate_state(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0))); context->last_was_rhw = TRUE; - Context_MarkStateDirty(context, STATE_VDECL, StateTable); /* because of last_was_rhw = TRUE */ + context_invalidate_state(context, STATE_VDECL); /* because of last_was_rhw = TRUE */ glDisable(GL_CLIP_PLANE0); checkGLcall("glDisable(clip plane 0)"); glDisable(GL_CLIP_PLANE1); checkGLcall("glDisable(clip plane 1)"); @@ -1909,7 +1837,7 @@ static void SetupForBlit(struct wined3d_device *device, struct wined3d_context * glDisable(GL_CLIP_PLANE3); checkGLcall("glDisable(clip plane 3)"); glDisable(GL_CLIP_PLANE4); checkGLcall("glDisable(clip plane 4)"); glDisable(GL_CLIP_PLANE5); checkGLcall("glDisable(clip plane 5)"); - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_CLIPPING), StateTable); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_CLIPPING)); set_blit_dimension(width, height); device->frag_pipe->enable_extension(FALSE); @@ -1917,74 +1845,31 @@ static void SetupForBlit(struct wined3d_device *device, struct wined3d_context * LEAVE_GL(); context->blit_w = width; context->blit_h = height; - Context_MarkStateDirty(context, STATE_VIEWPORT, StateTable); - Context_MarkStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION), StateTable); + context_invalidate_state(context, STATE_VIEWPORT); + context_invalidate_state(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)); } -/* Do not call while under the GL lock. */ -static struct wined3d_context *FindContext(struct wined3d_device *device, struct wined3d_surface *target) +static inline BOOL is_rt_mask_onscreen(DWORD rt_mask) { - struct wined3d_context *current_context = context_get_current(); - struct wined3d_context *context; + return rt_mask & (1 << 31); +} - if (current_context && current_context->destroyed) current_context = NULL; - - if (!target) - { - if (current_context - && current_context->current_rt - && current_context->swapchain->device == device) - { - target = current_context->current_rt; - } - else - { - struct wined3d_swapchain *swapchain = device->swapchains[0]; - if (swapchain->back_buffers) target = swapchain->back_buffers[0]; - else target = swapchain->front_buffer; - } - } - - if (current_context && current_context->current_rt == target) - { - context_update_window(current_context); - return current_context; - } - - if (target->container.type == WINED3D_CONTAINER_SWAPCHAIN) - { - TRACE("Rendering onscreen\n"); - - context = swapchain_get_context(target->container.u.swapchain); - } - else - { - TRACE("Rendering offscreen\n"); - - /* Stay with the current context if possible. Otherwise use the - * context for the primary swapchain. */ - if (current_context && current_context->swapchain->device == device) - context = current_context; - else - context = swapchain_get_context(device->swapchains[0]); - } - - context_update_window(context); - - return context; +static inline GLenum draw_buffer_from_rt_mask(DWORD rt_mask) +{ + return rt_mask & ~(1 << 31); } /* Context activation and GL locking are done by the caller. */ -static void context_apply_draw_buffers(struct wined3d_context *context, DWORD rt_mask, struct wined3d_surface **rts) +static void context_apply_draw_buffers(struct wined3d_context *context, DWORD rt_mask) { if (!rt_mask) { glDrawBuffer(GL_NONE); checkGLcall("glDrawBuffer()"); } - else if (!surface_is_offscreen(rts[0])) + else if (is_rt_mask_onscreen(rt_mask)) { - glDrawBuffer(surface_get_gl_buffer(rts[0])); + glDrawBuffer(draw_buffer_from_rt_mask(rt_mask)); checkGLcall("glDrawBuffer()"); } else @@ -1996,7 +1881,7 @@ static void context_apply_draw_buffers(struct wined3d_context *context, DWORD rt while (rt_mask) { - if ((rt_mask & 1) && rts[i] && rts[i]->resource.format->id != WINED3DFMT_NULL) + if (rt_mask & 1) context->draw_buffers[i] = GL_COLOR_ATTACHMENT0 + i; else context->draw_buffers[i] = GL_NONE; @@ -2018,8 +1903,7 @@ static void context_apply_draw_buffers(struct wined3d_context *context, DWORD rt } else { - glDrawBuffer(rts[0]->resource.device->offscreenBuffer); - checkGLcall("glDrawBuffer()"); + ERR("Unexpected draw buffers mask with backbuffer ORM.\n"); } } } @@ -2029,19 +1913,77 @@ void context_set_draw_buffer(struct wined3d_context *context, GLenum buffer) { glDrawBuffer(buffer); checkGLcall("glDrawBuffer()"); - context->draw_buffer_dirty = TRUE; + if (context->current_fbo) + context->current_fbo->rt_mask = context_generate_rt_mask(buffer); + else + context->draw_buffers_mask = context_generate_rt_mask(buffer); } -static inline void context_set_render_offscreen(struct wined3d_context *context, const struct StateEntry *StateTable, - BOOL offscreen) +/* GL locking is done by the caller. */ +void context_active_texture(struct wined3d_context *context, const struct wined3d_gl_info *gl_info, unsigned int unit) +{ + GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0 + unit)); + checkGLcall("glActiveTextureARB"); + context->active_texture = unit; +} + +void context_bind_texture(struct wined3d_context *context, GLenum target, GLuint name) +{ + DWORD unit = context->active_texture; + DWORD old_texture_type = context->texture_type[unit]; + + if (name) + { + glBindTexture(target, name); + checkGLcall("glBindTexture"); + } + else + { + target = GL_NONE; + } + + if (old_texture_type != target) + { + const struct wined3d_device *device = context->swapchain->device; + + switch (old_texture_type) + { + case GL_NONE: + /* nothing to do */ + break; + case GL_TEXTURE_2D: + glBindTexture(GL_TEXTURE_2D, device->dummy_texture_2d[unit]); + checkGLcall("glBindTexture"); + break; + case GL_TEXTURE_RECTANGLE_ARB: + glBindTexture(GL_TEXTURE_RECTANGLE_ARB, device->dummy_texture_rect[unit]); + checkGLcall("glBindTexture"); + break; + case GL_TEXTURE_CUBE_MAP: + glBindTexture(GL_TEXTURE_CUBE_MAP, device->dummy_texture_cube[unit]); + checkGLcall("glBindTexture"); + break; + case GL_TEXTURE_3D: + glBindTexture(GL_TEXTURE_3D, device->dummy_texture_3d[unit]); + checkGLcall("glBindTexture"); + break; + default: + ERR("Unexpected texture target %#x\n", old_texture_type); + } + + context->texture_type[unit] = target; + } +} + +static void context_set_render_offscreen(struct wined3d_context *context, BOOL offscreen) { if (context->render_offscreen == offscreen) return; - Context_MarkStateDirty(context, STATE_POINTSPRITECOORDORIGIN, StateTable); - Context_MarkStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION), StateTable); - Context_MarkStateDirty(context, STATE_VIEWPORT, StateTable); - Context_MarkStateDirty(context, STATE_SCISSORRECT, StateTable); - Context_MarkStateDirty(context, STATE_FRONTFACE, StateTable); + context_invalidate_state(context, STATE_POINTSPRITECOORDORIGIN); + context_invalidate_state(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)); + context_invalidate_state(context, STATE_VIEWPORT); + context_invalidate_state(context, STATE_SCISSORRECT); + context_invalidate_state(context, STATE_FRONTFACE); context->render_offscreen = offscreen; } @@ -2064,8 +2006,8 @@ static BOOL match_depth_stencil_format(const struct wined3d_format *existing, } /* The caller provides a context */ -static void context_validate_onscreen_formats(struct wined3d_device *device, - struct wined3d_context *context, struct wined3d_surface *depth_stencil) +static void context_validate_onscreen_formats(struct wined3d_context *context, + const struct wined3d_surface *depth_stencil) { /* Onscreen surfaces are always in a swapchain */ struct wined3d_swapchain *swapchain = context->current_rt->container.u.swapchain; @@ -2081,40 +2023,62 @@ static void context_validate_onscreen_formats(struct wined3d_device *device, /* The currently active context is the necessary context to access the swapchain's onscreen buffers */ surface_load_location(context->current_rt, SFLAG_INTEXTURE, NULL); swapchain->render_to_fbo = TRUE; - context_set_render_offscreen(context, device->StateTable, TRUE); + swapchain_update_draw_bindings(swapchain); + context_set_render_offscreen(context, TRUE); +} + +static DWORD context_generate_rt_mask_no_fbo(const struct wined3d_device *device, const struct wined3d_surface *rt) +{ + if (!rt || rt->resource.format->id == WINED3DFMT_NULL) + return 0; + else if (rt->container.type == WINED3D_CONTAINER_SWAPCHAIN) + return context_generate_rt_mask_from_surface(rt); + else + return context_generate_rt_mask(device->offscreenBuffer); } /* Context activation is done by the caller. */ -void context_apply_blit_state(struct wined3d_context *context, struct wined3d_device *device) +void context_apply_blit_state(struct wined3d_context *context, const struct wined3d_device *device) { + struct wined3d_surface *rt = context->current_rt; + DWORD rt_mask, old_mask; + if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) { - context_validate_onscreen_formats(device, context, NULL); + context_validate_onscreen_formats(context, NULL); if (context->render_offscreen) { - surface_internal_preload(context->current_rt, SRGB_RGB); + surface_internal_preload(rt, SRGB_RGB); ENTER_GL(); - context_apply_fbo_state_blit(context, GL_FRAMEBUFFER, context->current_rt, NULL, SFLAG_INTEXTURE); + context_apply_fbo_state_blit(context, GL_FRAMEBUFFER, rt, NULL, rt->draw_binding); LEAVE_GL(); + if (rt->resource.format->id != WINED3DFMT_NULL) + rt_mask = 1; + else + rt_mask = 0; } else { ENTER_GL(); context_bind_fbo(context, GL_FRAMEBUFFER, NULL); LEAVE_GL(); + rt_mask = context_generate_rt_mask_from_surface(rt); } - - context->draw_buffer_dirty = TRUE; + } + else + { + rt_mask = context_generate_rt_mask_no_fbo(device, rt); } + old_mask = context->current_fbo ? context->current_fbo->rt_mask : context->draw_buffers_mask; + ENTER_GL(); - if (context->draw_buffer_dirty) + if (rt_mask != old_mask) { - context_apply_draw_buffers(context, 1, &context->current_rt); - if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) - context->draw_buffer_dirty = FALSE; + context_apply_draw_buffers(context, rt_mask); + context->draw_buffers_mask = rt_mask; } if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) @@ -2124,10 +2088,11 @@ void context_apply_blit_state(struct wined3d_context *context, struct wined3d_de LEAVE_GL(); SetupForBlit(device, context); + context_invalidate_state(context, STATE_FRAMEBUFFER); } static BOOL context_validate_rt_config(UINT rt_count, - struct wined3d_surface **rts, struct wined3d_surface *ds) + struct wined3d_surface * const *rts, const struct wined3d_surface *ds) { unsigned int i; @@ -2144,55 +2109,83 @@ static BOOL context_validate_rt_config(UINT rt_count, } /* Context activation is done by the caller. */ -BOOL context_apply_clear_state(struct wined3d_context *context, struct wined3d_device *device, - UINT rt_count, struct wined3d_surface **rts, struct wined3d_surface *depth_stencil) +BOOL context_apply_clear_state(struct wined3d_context *context, const struct wined3d_device *device, + UINT rt_count, const struct wined3d_fb_state *fb) { - const struct StateEntry *state_table = device->StateTable; - DWORD rt_mask = 0; + DWORD rt_mask = 0, old_mask; UINT i; + struct wined3d_surface **rts = fb->render_targets; - if (!context_validate_rt_config(rt_count, rts, depth_stencil)) - return FALSE; - - - if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) + if (isStateDirty(context, STATE_FRAMEBUFFER) || fb != &device->fb + || rt_count != context->gl_info->limits.buffers) { - context_validate_onscreen_formats(device, context, depth_stencil); + if (!context_validate_rt_config(rt_count, rts, fb->depth_stencil)) + return FALSE; - ENTER_GL(); - - if (!rt_count || surface_is_offscreen(rts[0])) + if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) { - for (i = 0; i < rt_count; ++i) + context_validate_onscreen_formats(context, fb->depth_stencil); + + ENTER_GL(); + + if (!rt_count || surface_is_offscreen(rts[0])) { - context->blit_targets[i] = rts[i]; - rt_mask |= (1 << i); + for (i = 0; i < rt_count; ++i) + { + context->blit_targets[i] = rts[i]; + if (rts[i] && rts[i]->resource.format->id != WINED3DFMT_NULL) + rt_mask |= (1 << i); + } + while (i < context->gl_info->limits.buffers) + { + context->blit_targets[i] = NULL; + ++i; + } + context_apply_fbo_state(context, GL_FRAMEBUFFER, context->blit_targets, fb->depth_stencil, + rt_count ? rts[0]->draw_binding : SFLAG_INTEXTURE); + glReadBuffer(GL_NONE); + checkGLcall("glReadBuffer"); } - while (i < context->gl_info->limits.buffers) + else { - context->blit_targets[i] = NULL; - ++i; + context_apply_fbo_state(context, GL_FRAMEBUFFER, NULL, NULL, SFLAG_INDRAWABLE); + rt_mask = context_generate_rt_mask_from_surface(rts[0]); } - context_apply_fbo_state(context, GL_FRAMEBUFFER, context->blit_targets, depth_stencil, SFLAG_INTEXTURE); - glReadBuffer(GL_NONE); - checkGLcall("glReadBuffer"); + + LEAVE_GL(); + + /* If the framebuffer is not the device's fb the device's fb has to be reapplied + * next draw. Otherwise we could mark the framebuffer state clean here, once the + * state management allows this */ + context_invalidate_state(context, STATE_FRAMEBUFFER); } else { - context_apply_fbo_state(context, GL_FRAMEBUFFER, NULL, NULL, SFLAG_INDRAWABLE); - rt_mask = 1; + rt_mask = context_generate_rt_mask_no_fbo(device, rt_count ? rts[0] : NULL); + } + } + else if (wined3d_settings.offscreen_rendering_mode == ORM_FBO + && (!rt_count || surface_is_offscreen(rts[0]))) + { + for (i = 0; i < rt_count; ++i) + { + if (rts[i] && rts[i]->resource.format->id != WINED3DFMT_NULL) rt_mask |= (1 << i); } - - LEAVE_GL(); } else { - rt_mask = 1; + rt_mask = context_generate_rt_mask_no_fbo(device, rt_count ? rts[0] : NULL); } + old_mask = context->current_fbo ? context->current_fbo->rt_mask : context->draw_buffers_mask; + ENTER_GL(); - context_apply_draw_buffers(context, rt_mask, rts); - context->draw_buffer_dirty = TRUE; + if (rt_mask != old_mask) + { + context_apply_draw_buffers(context, rt_mask); + context->draw_buffers_mask = rt_mask; + context_invalidate_state(context, STATE_FRAMEBUFFER); + } if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) { @@ -2202,6 +2195,7 @@ BOOL context_apply_clear_state(struct wined3d_context *context, struct wined3d_d if (context->last_was_blit) { device->frag_pipe->enable_extension(TRUE); + context->last_was_blit = FALSE; } /* Blending and clearing should be orthogonal, but tests on the nvidia @@ -2212,69 +2206,114 @@ BOOL context_apply_clear_state(struct wined3d_context *context, struct wined3d_d checkGLcall("glEnable GL_SCISSOR_TEST"); LEAVE_GL(); - context->last_was_blit = FALSE; - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), state_table); - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE), state_table); - Context_MarkStateDirty(context, STATE_SCISSORRECT, state_table); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE)); + context_invalidate_state(context, STATE_SCISSORRECT); return TRUE; } +static DWORD find_draw_buffers_mask(const struct wined3d_context *context, const struct wined3d_device *device) +{ + const struct wined3d_state *state = &device->stateBlock->state; + struct wined3d_surface **rts = state->fb->render_targets; + struct wined3d_shader *ps = state->pixel_shader; + DWORD rt_mask, rt_mask_bits; + unsigned int i; + + if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) return context_generate_rt_mask_no_fbo(device, rts[0]); + else if (!context->render_offscreen) return context_generate_rt_mask_from_surface(rts[0]); + + rt_mask = ps ? ps->reg_maps.rt_mask : 1; + rt_mask &= device->valid_rt_mask; + rt_mask_bits = rt_mask; + i = 0; + while (rt_mask_bits) + { + rt_mask_bits &= ~(1 << i); + if (!rts[i] || rts[i]->resource.format->id == WINED3DFMT_NULL) + rt_mask &= ~(1 << i); + + i++; + } + + return rt_mask; +} + +/* GL locking and context activation are done by the caller */ +void context_state_fb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) +{ + const struct wined3d_device *device = context->swapchain->device; + const struct wined3d_fb_state *fb = state->fb; + DWORD rt_mask = find_draw_buffers_mask(context, device); + DWORD old_mask; + + if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) + { + if (!context->render_offscreen) + { + context_apply_fbo_state(context, GL_FRAMEBUFFER, NULL, NULL, SFLAG_INDRAWABLE); + } + else + { + context_apply_fbo_state(context, GL_FRAMEBUFFER, fb->render_targets, fb->depth_stencil, + fb->render_targets[0]->draw_binding); + glReadBuffer(GL_NONE); + checkGLcall("glReadBuffer"); + } + } + + old_mask = context->current_fbo ? context->current_fbo->rt_mask : context->draw_buffers_mask; + if (rt_mask != old_mask) + { + context_apply_draw_buffers(context, rt_mask); + context->draw_buffers_mask = rt_mask; + } +} + +/* GL locking and context activation are done by the caller */ +void context_state_drawbuf(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) +{ + const struct wined3d_device *device = context->swapchain->device; + DWORD rt_mask, old_mask; + + if (isStateDirty(context, STATE_FRAMEBUFFER)) return; + + old_mask = context->current_fbo ? context->current_fbo->rt_mask : context->draw_buffers_mask; + rt_mask = find_draw_buffers_mask(context, device); + if (rt_mask != old_mask) + { + context_apply_draw_buffers(context, rt_mask); + context->draw_buffers_mask = rt_mask; + } +} + /* Context activation is done by the caller. */ BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_device *device) { - const struct StateEntry *state_table = device->StateTable; - const struct wined3d_fb_state *fb = &device->fb; + const struct wined3d_state *state = &device->stateBlock->state; + const struct StateEntry *state_table = context->state_table; + const struct wined3d_fb_state *fb = state->fb; unsigned int i; if (!context_validate_rt_config(context->gl_info->limits.buffers, fb->render_targets, fb->depth_stencil)) return FALSE; + if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && isStateDirty(context, STATE_FRAMEBUFFER)) + { + context_validate_onscreen_formats(context, fb->depth_stencil); + } + /* Preload resources before FBO setup. Texture preload in particular may * result in changes to the current FBO, due to using e.g. FBO blits for * updating a resource location. */ device_update_tex_unit_map(device); device_preload_textures(device); - if (isStateDirty(context, STATE_VDECL)) + if (isStateDirty(context, STATE_VDECL) || isStateDirty(context, STATE_STREAMSRC)) device_update_stream_info(device, context->gl_info); - if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) - { - context_validate_onscreen_formats(device, context, fb->depth_stencil); - - if (!context->render_offscreen) - { - ENTER_GL(); - context_apply_fbo_state(context, GL_FRAMEBUFFER, NULL, NULL, SFLAG_INDRAWABLE); - LEAVE_GL(); - } - else - { - ENTER_GL(); - context_apply_fbo_state(context, GL_FRAMEBUFFER, fb->render_targets, fb->depth_stencil, SFLAG_INTEXTURE); - glReadBuffer(GL_NONE); - checkGLcall("glReadBuffer"); - LEAVE_GL(); - } - } - ENTER_GL(); - if (context->draw_buffer_dirty) - { - const struct wined3d_shader *ps = device->stateBlock->state.pixel_shader; - DWORD rt_mask = ps ? ps->reg_maps.rt_mask : 1; - - rt_mask &= device->valid_rt_mask; - context_apply_draw_buffers(context, rt_mask, fb->render_targets); - context->draw_buffer_dirty = FALSE; - } - - if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) - { - context_check_fbo_status(context, GL_FRAMEBUFFER); - } - if (context->last_was_blit) { device->frag_pipe->enable_extension(TRUE); @@ -2286,8 +2325,14 @@ BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_de DWORD idx = rep / (sizeof(*context->isStateDirty) * CHAR_BIT); BYTE shift = rep & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1); context->isStateDirty[idx] &= ~(1 << shift); - state_table[rep].apply(rep, device->stateBlock, context); + state_table[rep].apply(context, state, rep); } + + if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) + { + context_check_fbo_status(context, GL_FRAMEBUFFER); + } + LEAVE_GL(); context->numDirtyEntries = 0; /* This makes the whole list clean */ context->last_was_blit = FALSE; @@ -2295,13 +2340,10 @@ BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_de return TRUE; } -static void context_setup_target(struct wined3d_device *device, - struct wined3d_context *context, struct wined3d_surface *target) +static void context_setup_target(struct wined3d_context *context, struct wined3d_surface *target) { BOOL old_render_offscreen = context->render_offscreen, render_offscreen; - const struct StateEntry *StateTable = device->StateTable; - if (!target) return; render_offscreen = surface_is_offscreen(target); if (context->current_rt == target && render_offscreen == old_render_offscreen) return; @@ -2309,7 +2351,7 @@ static void context_setup_target(struct wined3d_device *device, * the alpha blend state changes with different render target formats. */ if (!context->current_rt) { - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), StateTable); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE)); } else { @@ -2321,14 +2363,11 @@ static void context_setup_target(struct wined3d_device *device, /* Disable blending when the alpha mask has changed and when a format doesn't support blending. */ if ((old->alpha_mask && !new->alpha_mask) || (!old->alpha_mask && new->alpha_mask) || !(new->flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING)) - { - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), StateTable); - } + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE)); + /* Update sRGB writing when switching between formats that do/do not support sRGB writing */ if ((old->flags & WINED3DFMT_FLAG_SRGB_WRITE) != (new->flags & WINED3DFMT_FLAG_SRGB_WRITE)) - { - Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SRGBWRITEENABLE), StateTable); - } + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE)); } /* When switching away from an offscreen render target, and we're not @@ -2349,21 +2388,63 @@ static void context_setup_target(struct wined3d_device *device, } } - context->draw_buffer_dirty = TRUE; context->current_rt = target; - context_set_render_offscreen(context, StateTable, render_offscreen); + context_set_render_offscreen(context, render_offscreen); } /* Do not call while under the GL lock. */ -struct wined3d_context *context_acquire(struct wined3d_device *device, struct wined3d_surface *target) +struct wined3d_context *context_acquire(const struct wined3d_device *device, struct wined3d_surface *target) { struct wined3d_context *current_context = context_get_current(); struct wined3d_context *context; TRACE("device %p, target %p.\n", device, target); - context = FindContext(device, target); - context_setup_target(device, context, target); + if (current_context && current_context->destroyed) + current_context = NULL; + + if (!target) + { + if (current_context + && current_context->current_rt + && current_context->swapchain->device == device) + { + target = current_context->current_rt; + } + else + { + struct wined3d_swapchain *swapchain = device->swapchains[0]; + if (swapchain->back_buffers) + target = swapchain->back_buffers[0]; + else + target = swapchain->front_buffer; + } + } + + if (current_context && current_context->current_rt == target) + { + context = current_context; + } + else if (target->container.type == WINED3D_CONTAINER_SWAPCHAIN) + { + TRACE("Rendering onscreen.\n"); + + context = swapchain_get_context(target->container.u.swapchain); + } + else + { + TRACE("Rendering offscreen.\n"); + + /* Stay with the current context if possible. Otherwise use the + * context for the primary swapchain. */ + if (current_context && current_context->swapchain->device == device) + context = current_context; + else + context = swapchain_get_context(device->swapchains[0]); + } + + context_update_window(context); + context_setup_target(context, target); context_enter(context); if (!context->valid) return context; @@ -2379,19 +2460,6 @@ struct wined3d_context *context_acquire(struct wined3d_device *device, struct wi device->frag_pipe->enable_extension(!context->last_was_blit); LEAVE_GL(); } - - if (context->vshader_const_dirty) - { - memset(context->vshader_const_dirty, 1, - sizeof(*context->vshader_const_dirty) * device->d3d_vshader_constantF); - device->highest_dirty_vs_const = device->d3d_vshader_constantF; - } - if (context->pshader_const_dirty) - { - memset(context->pshader_const_dirty, 1, - sizeof(*context->pshader_const_dirty) * device->d3d_pshader_constantF); - device->highest_dirty_ps_const = device->d3d_pshader_constantF; - } } else if (context->restore_ctx) { diff --git a/reactos/dll/directx/wine/wined3d/device.c b/reactos/dll/directx/wine/wined3d/device.c index 8724cdfb3e8..65954226c2e 100644 --- a/reactos/dll/directx/wine/wined3d/device.c +++ b/reactos/dll/directx/wine/wined3d/device.c @@ -1,6 +1,4 @@ /* - * IWineD3DDevice implementation - * * Copyright 2002 Lionel Ulmer * Copyright 2002-2005 Jason Edmeades * Copyright 2003-2004 Raphael Junqueira @@ -35,10 +33,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d); -/* Define the default light parameters as specified by MSDN */ -const WINED3DLIGHT WINED3D_default_light = { - - WINED3DLIGHT_DIRECTIONAL, /* Type */ +/* Define the default light parameters as specified by MSDN. */ +const struct wined3d_light WINED3D_default_light = +{ + WINED3D_LIGHT_DIRECTIONAL, /* Type */ { 1.0f, 1.0f, 1.0f, 0.0f }, /* Diffuse r,g,b,a */ { 0.0f, 0.0f, 0.0f, 0.0f }, /* Specular r,g,b,a */ { 0.0f, 0.0f, 0.0f, 0.0f }, /* Ambient r,g,b,a, */ @@ -64,38 +62,38 @@ const float identity[] = /* Note that except for WINED3DPT_POINTLIST and WINED3DPT_LINELIST these * actually have the same values in GL and D3D. */ -static GLenum gl_primitive_type_from_d3d(WINED3DPRIMITIVETYPE primitive_type) +static GLenum gl_primitive_type_from_d3d(enum wined3d_primitive_type primitive_type) { switch(primitive_type) { - case WINED3DPT_POINTLIST: + case WINED3D_PT_POINTLIST: return GL_POINTS; - case WINED3DPT_LINELIST: + case WINED3D_PT_LINELIST: return GL_LINES; - case WINED3DPT_LINESTRIP: + case WINED3D_PT_LINESTRIP: return GL_LINE_STRIP; - case WINED3DPT_TRIANGLELIST: + case WINED3D_PT_TRIANGLELIST: return GL_TRIANGLES; - case WINED3DPT_TRIANGLESTRIP: + case WINED3D_PT_TRIANGLESTRIP: return GL_TRIANGLE_STRIP; - case WINED3DPT_TRIANGLEFAN: + case WINED3D_PT_TRIANGLEFAN: return GL_TRIANGLE_FAN; - case WINED3DPT_LINELIST_ADJ: + case WINED3D_PT_LINELIST_ADJ: return GL_LINES_ADJACENCY_ARB; - case WINED3DPT_LINESTRIP_ADJ: + case WINED3D_PT_LINESTRIP_ADJ: return GL_LINE_STRIP_ADJACENCY_ARB; - case WINED3DPT_TRIANGLELIST_ADJ: + case WINED3D_PT_TRIANGLELIST_ADJ: return GL_TRIANGLES_ADJACENCY_ARB; - case WINED3DPT_TRIANGLESTRIP_ADJ: + case WINED3D_PT_TRIANGLESTRIP_ADJ: return GL_TRIANGLE_STRIP_ADJACENCY_ARB; default: @@ -104,43 +102,43 @@ static GLenum gl_primitive_type_from_d3d(WINED3DPRIMITIVETYPE primitive_type) } } -static WINED3DPRIMITIVETYPE d3d_primitive_type_from_gl(GLenum primitive_type) +static enum wined3d_primitive_type d3d_primitive_type_from_gl(GLenum primitive_type) { switch(primitive_type) { case GL_POINTS: - return WINED3DPT_POINTLIST; + return WINED3D_PT_POINTLIST; case GL_LINES: - return WINED3DPT_LINELIST; + return WINED3D_PT_LINELIST; case GL_LINE_STRIP: - return WINED3DPT_LINESTRIP; + return WINED3D_PT_LINESTRIP; case GL_TRIANGLES: - return WINED3DPT_TRIANGLELIST; + return WINED3D_PT_TRIANGLELIST; case GL_TRIANGLE_STRIP: - return WINED3DPT_TRIANGLESTRIP; + return WINED3D_PT_TRIANGLESTRIP; case GL_TRIANGLE_FAN: - return WINED3DPT_TRIANGLEFAN; + return WINED3D_PT_TRIANGLEFAN; case GL_LINES_ADJACENCY_ARB: - return WINED3DPT_LINELIST_ADJ; + return WINED3D_PT_LINELIST_ADJ; case GL_LINE_STRIP_ADJACENCY_ARB: - return WINED3DPT_LINESTRIP_ADJ; + return WINED3D_PT_LINESTRIP_ADJ; case GL_TRIANGLES_ADJACENCY_ARB: - return WINED3DPT_TRIANGLELIST_ADJ; + return WINED3D_PT_TRIANGLELIST_ADJ; case GL_TRIANGLE_STRIP_ADJACENCY_ARB: - return WINED3DPT_TRIANGLESTRIP_ADJ; + return WINED3D_PT_TRIANGLESTRIP_ADJ; default: FIXME("Unhandled primitive type %s\n", debug_d3dprimitivetype(primitive_type)); - return WINED3DPT_UNDEFINED; + return WINED3D_PT_UNDEFINED; } } @@ -174,10 +172,12 @@ static BOOL fixed_get_input(BYTE usage, BYTE usage_idx, unsigned int *regnum) /* Context activation is done by the caller. */ void device_stream_info_from_declaration(struct wined3d_device *device, - BOOL use_vshader, struct wined3d_stream_info *stream_info, BOOL *fixup) + struct wined3d_stream_info *stream_info, BOOL *fixup) { + const struct wined3d_state *state = &device->stateBlock->state; /* We need to deal with frequency data! */ - struct wined3d_vertex_declaration *declaration = device->stateBlock->state.vertex_declaration; + struct wined3d_vertex_declaration *declaration = state->vertex_declaration; + BOOL use_vshader; unsigned int i; stream_info->use_map = 0; @@ -185,15 +185,15 @@ void device_stream_info_from_declaration(struct wined3d_device *device, /* Check for transformed vertices, disable vertex shader if present. */ stream_info->position_transformed = declaration->position_transformed; - if (declaration->position_transformed) use_vshader = FALSE; + use_vshader = state->vertex_shader && !declaration->position_transformed; /* Translate the declaration into strided data. */ for (i = 0; i < declaration->element_count; ++i) { const struct wined3d_vertex_declaration_element *element = &declaration->elements[i]; - struct wined3d_buffer *buffer = device->stateBlock->state.streams[element->input_slot].buffer; - GLuint buffer_object = 0; - const BYTE *data = NULL; + const struct wined3d_stream_state *stream = &state->streams[element->input_slot]; + struct wined3d_buffer *buffer = stream->buffer; + struct wined3d_bo_address data; BOOL stride_used; unsigned int idx; DWORD stride; @@ -203,30 +203,33 @@ void device_stream_info_from_declaration(struct wined3d_device *device, if (!buffer) continue; - stride = device->stateBlock->state.streams[element->input_slot].stride; - if (device->stateBlock->state.user_stream) + data.buffer_object = 0; + data.addr = NULL; + + stride = stream->stride; + if (state->user_stream) { TRACE("Stream %u is UP, %p\n", element->input_slot, buffer); - buffer_object = 0; - data = (BYTE *)buffer; + data.buffer_object = 0; + data.addr = (BYTE *)buffer; } else { TRACE("Stream %u isn't UP, %p\n", element->input_slot, buffer); - data = buffer_get_memory(buffer, &device->adapter->gl_info, &buffer_object); + buffer_get_memory(buffer, &device->adapter->gl_info, &data); /* Can't use vbo's if the base vertex index is negative. OpenGL doesn't accept negative offsets * (or rather offsets bigger than the vbo, because the pointer is unsigned), so use system memory * sources. In most sane cases the pointer - offset will still be > 0, otherwise it will wrap * around to some big value. Hope that with the indices, the driver wraps it back internally. If * not, drawStridedSlow is needed, including a vertex buffer path. */ - if (device->stateBlock->state.load_base_vertex_index < 0) + if (state->load_base_vertex_index < 0) { WARN("load_base_vertex_index is < 0 (%d), not using VBOs.\n", - device->stateBlock->state.load_base_vertex_index); - buffer_object = 0; - data = buffer_get_sysmem(buffer, &device->adapter->gl_info); - if ((UINT_PTR)data < -device->stateBlock->state.load_base_vertex_index * stride) + state->load_base_vertex_index); + data.buffer_object = 0; + data.addr = buffer_get_sysmem(buffer, &device->adapter->gl_info); + if ((UINT_PTR)data.addr < -state->load_base_vertex_index * stride) { FIXME("System memory vertex data load offset is negative!\n"); } @@ -234,7 +237,8 @@ void device_stream_info_from_declaration(struct wined3d_device *device, if (fixup) { - if (buffer_object) *fixup = TRUE; + if (data.buffer_object) + *fixup = TRUE; else if (*fixup && !use_vshader && (element->usage == WINED3DDECLUSAGE_COLOR || element->usage == WINED3DDECLUSAGE_POSITIONT)) @@ -249,7 +253,7 @@ void device_stream_info_from_declaration(struct wined3d_device *device, } } } - data += element->offset; + data.addr += element->offset; TRACE("offset %u input_slot %u usage_idx %d\n", element->offset, element->input_slot, element->usage_idx); @@ -260,7 +264,7 @@ void device_stream_info_from_declaration(struct wined3d_device *device, /* TODO: Assuming vertexdeclarations are usually used with the * same or a similar shader, it might be worth it to store the * last used output slot and try that one first. */ - stride_used = vshader_get_input(device->stateBlock->state.vertex_shader, + stride_used = vshader_get_input(state->vertex_shader, element->usage, element->usage_idx, &idx); } else @@ -289,13 +293,14 @@ void device_stream_info_from_declaration(struct wined3d_device *device, "input_slot %u, offset %u, stride %u, format %s, buffer_object %u]\n", use_vshader ? "shader": "fixed function", idx, debug_d3ddeclusage(element->usage), element->usage_idx, element->input_slot, - element->offset, stride, debug_d3dformat(element->format->id), buffer_object); + element->offset, stride, debug_d3dformat(element->format->id), data.buffer_object); + + data.addr += stream->offset; stream_info->elements[idx].format = element->format; - stream_info->elements[idx].stride = stride; stream_info->elements[idx].data = data; + stream_info->elements[idx].stride = stride; stream_info->elements[idx].stream_idx = element->input_slot; - stream_info->elements[idx].buffer_object = buffer_object; if (!device->adapter->gl_info.supported[ARB_VERTEX_ARRAY_BGRA] && element->format->id == WINED3DFMT_B8G8R8A8_UNORM) @@ -307,7 +312,7 @@ void device_stream_info_from_declaration(struct wined3d_device *device, } device->num_buffer_queries = 0; - if (!device->stateBlock->state.user_stream) + if (!state->user_stream) { WORD map = stream_info->use_map; @@ -320,14 +325,15 @@ void device_stream_info_from_declaration(struct wined3d_device *device, if (!(map & 1)) continue; element = &stream_info->elements[i]; - buffer = device->stateBlock->state.streams[element->stream_idx].buffer; + buffer = state->streams[element->stream_idx].buffer; wined3d_buffer_preload(buffer); - /* If PreLoad dropped the buffer object, update the stream info. */ - if (buffer->buffer_object != element->buffer_object) + /* If the preload dropped the buffer object, update the stream info. */ + if (buffer->buffer_object != element->data.buffer_object) { - element->buffer_object = 0; - element->data = buffer_get_sysmem(buffer, &device->adapter->gl_info) + (ptrdiff_t)element->data; + element->data.buffer_object = 0; + element->data.addr = buffer_get_sysmem(buffer, &device->adapter->gl_info) + + (ptrdiff_t)element->data.addr; } if (buffer->query) @@ -337,35 +343,35 @@ void device_stream_info_from_declaration(struct wined3d_device *device, } static void stream_info_element_from_strided(const struct wined3d_gl_info *gl_info, - const struct WineDirect3DStridedData *strided, struct wined3d_stream_info_element *e) + const struct wined3d_strided_element *strided, struct wined3d_stream_info_element *e) { + e->data.addr = strided->data; + e->data.buffer_object = 0; e->format = wined3d_get_format(gl_info, strided->format); - e->stride = strided->dwStride; - e->data = strided->lpData; + e->stride = strided->stride; e->stream_idx = 0; - e->buffer_object = 0; } static void device_stream_info_from_strided(const struct wined3d_gl_info *gl_info, - const struct WineDirect3DVertexStridedData *strided, struct wined3d_stream_info *stream_info) + const struct wined3d_strided_data *strided, struct wined3d_stream_info *stream_info) { unsigned int i; memset(stream_info, 0, sizeof(*stream_info)); - if (strided->position.lpData) + if (strided->position.data) stream_info_element_from_strided(gl_info, &strided->position, &stream_info->elements[WINED3D_FFP_POSITION]); - if (strided->normal.lpData) + if (strided->normal.data) stream_info_element_from_strided(gl_info, &strided->normal, &stream_info->elements[WINED3D_FFP_NORMAL]); - if (strided->diffuse.lpData) + if (strided->diffuse.data) stream_info_element_from_strided(gl_info, &strided->diffuse, &stream_info->elements[WINED3D_FFP_DIFFUSE]); - if (strided->specular.lpData) + if (strided->specular.data) stream_info_element_from_strided(gl_info, &strided->specular, &stream_info->elements[WINED3D_FFP_SPECULAR]); for (i = 0; i < WINED3DDP_MAXTEXCOORD; ++i) { - if (strided->texCoords[i].lpData) - stream_info_element_from_strided(gl_info, &strided->texCoords[i], + if (strided->tex_coords[i].data) + stream_info_element_from_strided(gl_info, &strided->tex_coords[i], &stream_info->elements[WINED3D_FFP_TEXCOORD0 + i]); } @@ -421,7 +427,7 @@ void device_update_stream_info(struct wined3d_device *device, const struct wined else { TRACE("============================= Vertex Declaration =============================\n"); - device_stream_info_from_declaration(device, !!state->vertex_shader, stream_info, &fixup); + device_stream_info_from_declaration(device, stream_info, &fixup); } if (state->vertex_shader && !stream_info->position_transformed) @@ -459,11 +465,11 @@ static void device_preload_texture(const struct wined3d_state *state, unsigned i enum WINED3DSRGB srgb; if (!(texture = state->textures[idx])) return; - srgb = state->sampler_states[idx][WINED3DSAMP_SRGBTEXTURE] ? SRGB_SRGB : SRGB_RGB; + srgb = state->sampler_states[idx][WINED3D_SAMP_SRGB_TEXTURE] ? SRGB_SRGB : SRGB_RGB; texture->texture_ops->texture_preload(texture, srgb); } -void device_preload_textures(struct wined3d_device *device) +void device_preload_textures(const struct wined3d_device *device) { const struct wined3d_state *state = &device->stateBlock->state; unsigned int i; @@ -559,27 +565,15 @@ void device_context_remove(struct wined3d_device *device, struct wined3d_context device->contexts = new_array; } -void device_get_draw_rect(struct wined3d_device *device, RECT *rect) -{ - struct wined3d_stateblock *stateblock = device->stateBlock; - WINED3DVIEWPORT *vp = &stateblock->state.viewport; - - SetRect(rect, vp->X, vp->Y, vp->X + vp->Width, vp->Y + vp->Height); - - if (stateblock->state.render_states[WINED3DRS_SCISSORTESTENABLE]) - { - IntersectRect(rect, rect, &stateblock->state.scissor_rect); - } -} - /* Do not call while under the GL lock. */ void device_switch_onscreen_ds(struct wined3d_device *device, struct wined3d_context *context, struct wined3d_surface *depth_stencil) { if (device->onscreen_depth_stencil) { - surface_load_ds_location(device->onscreen_depth_stencil, context, SFLAG_DS_OFFSCREEN); - surface_modify_ds_location(device->onscreen_depth_stencil, SFLAG_DS_OFFSCREEN, + surface_load_ds_location(device->onscreen_depth_stencil, context, SFLAG_INTEXTURE); + + surface_modify_ds_location(device->onscreen_depth_stencil, SFLAG_INTEXTURE, device->onscreen_depth_stencil->ds_current_size.cx, device->onscreen_depth_stencil->ds_current_size.cy); wined3d_surface_decref(device->onscreen_depth_stencil); @@ -588,7 +582,7 @@ void device_switch_onscreen_ds(struct wined3d_device *device, wined3d_surface_incref(device->onscreen_depth_stencil); } -static BOOL is_full_clear(struct wined3d_surface *target, const RECT *draw_rect, const RECT *clear_rect) +static BOOL is_full_clear(const struct wined3d_surface *target, const RECT *draw_rect, const RECT *clear_rect) { /* partial draw rect */ if (draw_rect->left || draw_rect->top @@ -606,7 +600,7 @@ static BOOL is_full_clear(struct wined3d_surface *target, const RECT *draw_rect, } static void prepare_ds_clear(struct wined3d_surface *ds, struct wined3d_context *context, - DWORD location, const RECT *draw_rect, UINT rect_count, const RECT *clear_rect) + DWORD location, const RECT *draw_rect, UINT rect_count, const RECT *clear_rect, RECT *out_rect) { RECT current_rect, r; @@ -621,7 +615,7 @@ static void prepare_ds_clear(struct wined3d_surface *ds, struct wined3d_context if (EqualRect(&r, draw_rect)) { /* current_rect ⊇ draw_rect, modify only. */ - surface_modify_ds_location(ds, location, ds->ds_current_size.cx, ds->ds_current_size.cy); + SetRect(out_rect, 0, 0, ds->ds_current_size.cx, ds->ds_current_size.cy); return; } @@ -632,7 +626,7 @@ static void prepare_ds_clear(struct wined3d_surface *ds, struct wined3d_context if (!clear_rect) { /* Full clear, modify only. */ - surface_modify_ds_location(ds, location, draw_rect->right, draw_rect->bottom); + *out_rect = *draw_rect; return; } @@ -640,28 +634,29 @@ static void prepare_ds_clear(struct wined3d_surface *ds, struct wined3d_context if (EqualRect(&r, draw_rect)) { /* clear_rect ⊇ draw_rect, modify only. */ - surface_modify_ds_location(ds, location, draw_rect->right, draw_rect->bottom); + *out_rect = *draw_rect; return; } } /* Full load. */ surface_load_ds_location(ds, context, location); - surface_modify_ds_location(ds, location, ds->ds_current_size.cx, ds->ds_current_size.cy); + SetRect(out_rect, 0, 0, ds->ds_current_size.cx, ds->ds_current_size.cy); } /* Do not call while under the GL lock. */ -HRESULT device_clear_render_targets(struct wined3d_device *device, UINT rt_count, struct wined3d_surface **rts, - struct wined3d_surface *depth_stencil, UINT rect_count, const RECT *rects, const RECT *draw_rect, - DWORD flags, const WINED3DCOLORVALUE *color, float depth, DWORD stencil) +HRESULT device_clear_render_targets(struct wined3d_device *device, UINT rt_count, const struct wined3d_fb_state *fb, + UINT rect_count, const RECT *rects, const RECT *draw_rect, DWORD flags, const struct wined3d_color *color, + float depth, DWORD stencil) { const RECT *clear_rect = (rect_count > 0 && rects) ? (const RECT *)rects : NULL; - struct wined3d_surface *target = rt_count ? rts[0] : NULL; + struct wined3d_surface *target = rt_count ? fb->render_targets[0] : NULL; UINT drawable_width, drawable_height; struct wined3d_context *context; GLbitfield clear_mask = 0; BOOL render_offscreen; unsigned int i; + RECT ds_rect; /* When we're clearing parts of the drawable, make sure that the target surface is well up to date in the * drawable. After the clear we'll mark the drawable up to date, so we have to make sure that this is true @@ -675,7 +670,9 @@ HRESULT device_clear_render_targets(struct wined3d_device *device, UINT rt_count { for (i = 0; i < rt_count; ++i) { - if (rts[i]) surface_load_location(rts[i], SFLAG_INDRAWABLE, NULL); + struct wined3d_surface *rt = fb->render_targets[i]; + if (rt) + surface_load_location(rt, rt->draw_binding, NULL); } } @@ -687,13 +684,6 @@ HRESULT device_clear_render_targets(struct wined3d_device *device, UINT rt_count return WINED3D_OK; } - if (!context_apply_clear_state(context, device, rt_count, rts, depth_stencil)) - { - context_release(context); - WARN("Failed to apply clear state, skipping clear.\n"); - return WINED3D_OK; - } - if (target) { render_offscreen = context->render_offscreen; @@ -702,8 +692,25 @@ HRESULT device_clear_render_targets(struct wined3d_device *device, UINT rt_count else { render_offscreen = TRUE; - drawable_width = depth_stencil->pow2Width; - drawable_height = depth_stencil->pow2Height; + drawable_width = fb->depth_stencil->pow2Width; + drawable_height = fb->depth_stencil->pow2Height; + } + + if (flags & WINED3DCLEAR_ZBUFFER) + { + DWORD location = render_offscreen ? fb->depth_stencil->draw_binding : SFLAG_INDRAWABLE; + + if (!render_offscreen && fb->depth_stencil != device->onscreen_depth_stencil) + device_switch_onscreen_ds(device, context, fb->depth_stencil); + prepare_ds_clear(fb->depth_stencil, context, location, + draw_rect, rect_count, clear_rect, &ds_rect); + } + + if (!context_apply_clear_state(context, device, rt_count, fb)) + { + context_release(context); + WARN("Failed to apply clear state, skipping clear.\n"); + return WINED3D_OK; } ENTER_GL(); @@ -714,10 +721,10 @@ HRESULT device_clear_render_targets(struct wined3d_device *device, UINT rt_count if (context->gl_info->supported[EXT_STENCIL_TWO_SIDE]) { glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_TWOSIDEDSTENCILMODE)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_TWOSIDEDSTENCILMODE)); } glStencilMask(~0U); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_STENCILWRITEMASK)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK)); glClearStencil(stencil); checkGLcall("glClearStencil"); clear_mask = clear_mask | GL_STENCIL_BUFFER_BIT; @@ -725,19 +732,12 @@ HRESULT device_clear_render_targets(struct wined3d_device *device, UINT rt_count if (flags & WINED3DCLEAR_ZBUFFER) { - DWORD location = render_offscreen ? SFLAG_DS_OFFSCREEN : SFLAG_DS_ONSCREEN; + DWORD location = render_offscreen ? fb->depth_stencil->draw_binding : SFLAG_INDRAWABLE; - if (location == SFLAG_DS_ONSCREEN && depth_stencil != device->onscreen_depth_stencil) - { - LEAVE_GL(); - device_switch_onscreen_ds(device, context, depth_stencil); - ENTER_GL(); - } - prepare_ds_clear(depth_stencil, context, location, draw_rect, rect_count, clear_rect); - surface_modify_location(depth_stencil, SFLAG_INDRAWABLE, TRUE); + surface_modify_ds_location(fb->depth_stencil, location, ds_rect.right, ds_rect.bottom); glDepthMask(GL_TRUE); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_ZWRITEENABLE)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ZWRITEENABLE)); glClearDepth(depth); checkGLcall("glClearDepth"); clear_mask = clear_mask | GL_DEPTH_BUFFER_BIT; @@ -747,14 +747,17 @@ HRESULT device_clear_render_targets(struct wined3d_device *device, UINT rt_count { for (i = 0; i < rt_count; ++i) { - if (rts[i]) surface_modify_location(rts[i], SFLAG_INDRAWABLE, TRUE); + struct wined3d_surface *rt = fb->render_targets[i]; + + if (rt) + surface_modify_location(rt, rt->draw_binding, TRUE); } glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE)); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE1)); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE2)); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE3)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3)); glClearColor(color->r, color->g, color->b, color->a); checkGLcall("glClearColor"); clear_mask = clear_mask | GL_COLOR_BUFFER_BIT; @@ -791,7 +794,7 @@ HRESULT device_clear_render_targets(struct wined3d_device *device, UINT rt_count wine_dbgstr_rect(¤t_rect)); /* Tests show that rectangles where x1 > x2 or y1 > y2 are ignored silently. - * The rectangle is not cleared, no error is returned, but further rectanlges are + * The rectangle is not cleared, no error is returned, but further rectangles are * still cleared if they are valid. */ if (current_rect.left > current_rect.right || current_rect.top > current_rect.bottom) { @@ -845,8 +848,19 @@ ULONG CDECL wined3d_device_decref(struct wined3d_device *device) if (!refcount) { + struct wined3d_stateblock *stateblock; UINT i; + if (wined3d_stateblock_decref(device->updateStateBlock) + && device->updateStateBlock != device->stateBlock) + FIXME("Something's still holding the update stateblock.\n"); + device->updateStateBlock = NULL; + + stateblock = device->stateBlock; + device->stateBlock = NULL; + if (wined3d_stateblock_decref(stateblock)) + FIXME("Something's still holding the stateblock.\n"); + for (i = 0; i < sizeof(device->multistate_funcs) / sizeof(device->multistate_funcs[0]); ++i) { HeapFree(GetProcessHeap(), 0, device->multistate_funcs[i]); @@ -862,7 +876,7 @@ ULONG CDECL wined3d_device_decref(struct wined3d_device *device) LIST_FOR_EACH_ENTRY(resource, &device->resources, struct wined3d_resource, resource_list_entry) { FIXME("Leftover resource %p with type %s (%#x).\n", - resource, debug_d3dresourcetype(resource->resourceType), resource->resourceType); + resource, debug_d3dresourcetype(resource->type), resource->type); } } @@ -881,14 +895,14 @@ ULONG CDECL wined3d_device_decref(struct wined3d_device *device) return refcount; } -UINT CDECL wined3d_device_get_swapchain_count(struct wined3d_device *device) +UINT CDECL wined3d_device_get_swapchain_count(const struct wined3d_device *device) { TRACE("device %p.\n", device); return device->swapchain_count; } -HRESULT CDECL wined3d_device_get_swapchain(struct wined3d_device *device, +HRESULT CDECL wined3d_device_get_swapchain(const struct wined3d_device *device, UINT swapchain_idx, struct wined3d_swapchain **swapchain) { TRACE("device %p, swapchain_idx %u, swapchain %p.\n", @@ -910,13 +924,13 @@ HRESULT CDECL wined3d_device_get_swapchain(struct wined3d_device *device, return WINED3D_OK; } -static void IWineD3DDeviceImpl_LoadLogo(struct wined3d_device *device, const char *filename) +static void device_load_logo(struct wined3d_device *device, const char *filename) { + struct wined3d_color_key color_key; HBITMAP hbm; BITMAP bm; HRESULT hr; HDC dcb = NULL, dcs = NULL; - WINEDDCOLORKEY colorkey; hbm = LoadImageA(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); if(hbm) @@ -936,9 +950,9 @@ static void IWineD3DDeviceImpl_LoadLogo(struct wined3d_device *device, const cha bm.bmHeight = 32; } - hr = wined3d_surface_create(device, bm.bmWidth, bm.bmHeight, WINED3DFMT_B5G6R5_UNORM, TRUE, - FALSE, 0, 0, WINED3DPOOL_DEFAULT, WINED3DMULTISAMPLE_NONE, 0, SURFACE_OPENGL, NULL, - &wined3d_null_parent_ops, &device->logo_surface); + hr = wined3d_surface_create(device, bm.bmWidth, bm.bmHeight, WINED3DFMT_B5G6R5_UNORM, 0, 0, + WINED3D_POOL_DEFAULT, WINED3D_MULTISAMPLE_NONE, 0, SURFACE_OPENGL, WINED3D_SURFACE_MAPPABLE, + NULL, &wined3d_null_parent_ops, &device->logo_surface); if (FAILED(hr)) { ERR("Wine logo requested, but failed to create surface, hr %#x.\n", hr); @@ -952,13 +966,13 @@ static void IWineD3DDeviceImpl_LoadLogo(struct wined3d_device *device, const cha BitBlt(dcs, 0, 0, bm.bmWidth, bm.bmHeight, dcb, 0, 0, SRCCOPY); wined3d_surface_releasedc(device->logo_surface, dcs); - colorkey.dwColorSpaceLowValue = 0; - colorkey.dwColorSpaceHighValue = 0; - wined3d_surface_set_color_key(device->logo_surface, WINEDDCKEY_SRCBLT, &colorkey); + color_key.color_space_low_value = 0; + color_key.color_space_high_value = 0; + wined3d_surface_set_color_key(device->logo_surface, WINEDDCKEY_SRCBLT, &color_key); } else { - const WINED3DCOLORVALUE c = {1.0f, 1.0f, 1.0f, 1.0f}; + const struct wined3d_color c = {1.0f, 1.0f, 1.0f, 1.0f}; /* Fill the surface with a white color to show that wined3d is there */ wined3d_device_color_fill(device, device->logo_surface, NULL, &c); } @@ -969,15 +983,14 @@ out: } /* Context activation is done by the caller. */ -static void create_dummy_textures(struct wined3d_device *device) +static void create_dummy_textures(struct wined3d_device *device, struct wined3d_context *context) { const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; - unsigned int i; - /* Under DirectX you can have texture stage operations even if no texture is - bound, whereas opengl will only do texture operations when a valid texture is - bound. We emulate this by creating dummy textures and binding them to each - texture stage, but disable all stages by default. Hence if a stage is enabled - then the default texture will kick in until replaced by a SetTexture call */ + unsigned int i, j, count; + /* Under DirectX you can sample even if no texture is bound, whereas + * OpenGL will only allow that when a valid texture is bound. + * We emulate this by creating dummy textures and binding them + * to each texture stage when the currently set D3D texture is NULL. */ ENTER_GL(); if (gl_info->supported[APPLE_CLIENT_STORAGE]) @@ -987,26 +1000,65 @@ static void create_dummy_textures(struct wined3d_device *device) checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)"); } - for (i = 0; i < gl_info->limits.textures; ++i) + count = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers); + for (i = 0; i < count; ++i) { - GLubyte white = 255; + DWORD color = 0x000000ff; /* Make appropriate texture active */ - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i)); - checkGLcall("glActiveTextureARB"); + context_active_texture(context, gl_info, i); - /* Generate an opengl texture name */ - glGenTextures(1, &device->dummyTextureName[i]); + glGenTextures(1, &device->dummy_texture_2d[i]); checkGLcall("glGenTextures"); - TRACE("Dummy Texture %d given name %d.\n", i, device->dummyTextureName[i]); + TRACE("Dummy 2D texture %u given name %u.\n", i, device->dummy_texture_2d[i]); - /* Generate a dummy 2d texture (not using 1d because they cause many - * DRI drivers fall back to sw) */ - glBindTexture(GL_TEXTURE_2D, device->dummyTextureName[i]); + glBindTexture(GL_TEXTURE_2D, device->dummy_texture_2d[i]); checkGLcall("glBindTexture"); - glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &white); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color); checkGLcall("glTexImage2D"); + + if (gl_info->supported[ARB_TEXTURE_RECTANGLE]) + { + glGenTextures(1, &device->dummy_texture_rect[i]); + checkGLcall("glGenTextures"); + TRACE("Dummy rectangle texture %u given name %u.\n", i, device->dummy_texture_rect[i]); + + glBindTexture(GL_TEXTURE_RECTANGLE_ARB, device->dummy_texture_rect[i]); + checkGLcall("glBindTexture"); + + glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color); + checkGLcall("glTexImage2D"); + } + + if (gl_info->supported[EXT_TEXTURE3D]) + { + glGenTextures(1, &device->dummy_texture_3d[i]); + checkGLcall("glGenTextures"); + TRACE("Dummy 3D texture %u given name %u.\n", i, device->dummy_texture_3d[i]); + + glBindTexture(GL_TEXTURE_3D, device->dummy_texture_3d[i]); + checkGLcall("glBindTexture"); + + GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color)); + checkGLcall("glTexImage3D"); + } + + if (gl_info->supported[ARB_TEXTURE_CUBE_MAP]) + { + glGenTextures(1, &device->dummy_texture_cube[i]); + checkGLcall("glGenTextures"); + TRACE("Dummy cube texture %u given name %u.\n", i, device->dummy_texture_cube[i]); + + glBindTexture(GL_TEXTURE_CUBE_MAP, device->dummy_texture_cube[i]); + checkGLcall("glBindTexture"); + + for (j = GL_TEXTURE_CUBE_MAP_POSITIVE_X; j <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; ++j) + { + glTexImage2D(j, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color); + checkGLcall("glTexImage2D"); + } + } } if (gl_info->supported[APPLE_CLIENT_STORAGE]) @@ -1022,12 +1074,35 @@ static void create_dummy_textures(struct wined3d_device *device) /* Context activation is done by the caller. */ static void destroy_dummy_textures(struct wined3d_device *device, const struct wined3d_gl_info *gl_info) { + unsigned int count = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers); + ENTER_GL(); - glDeleteTextures(gl_info->limits.textures, device->dummyTextureName); - checkGLcall("glDeleteTextures(gl_info->limits.textures, device->dummyTextureName)"); + if (gl_info->supported[ARB_TEXTURE_CUBE_MAP]) + { + glDeleteTextures(count, device->dummy_texture_cube); + checkGLcall("glDeleteTextures(count, device->dummy_texture_cube)"); + } + + if (gl_info->supported[EXT_TEXTURE3D]) + { + glDeleteTextures(count, device->dummy_texture_3d); + checkGLcall("glDeleteTextures(count, device->dummy_texture_3d)"); + } + + if (gl_info->supported[ARB_TEXTURE_RECTANGLE]) + { + glDeleteTextures(count, device->dummy_texture_rect); + checkGLcall("glDeleteTextures(count, device->dummy_texture_rect)"); + } + + glDeleteTextures(count, device->dummy_texture_2d); + checkGLcall("glDeleteTextures(count, device->dummy_texture_2d)"); LEAVE_GL(); - memset(device->dummyTextureName, 0, gl_info->limits.textures * sizeof(*device->dummyTextureName)); + memset(device->dummy_texture_cube, 0, gl_info->limits.textures * sizeof(*device->dummy_texture_cube)); + memset(device->dummy_texture_3d, 0, gl_info->limits.textures * sizeof(*device->dummy_texture_3d)); + memset(device->dummy_texture_rect, 0, gl_info->limits.textures * sizeof(*device->dummy_texture_rect)); + memset(device->dummy_texture_2d, 0, gl_info->limits.textures * sizeof(*device->dummy_texture_2d)); } static LONG fullscreen_style(LONG style) @@ -1138,8 +1213,9 @@ void CDECL wined3d_device_release_focus_window(struct wined3d_device *device) } HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device, - WINED3DPRESENT_PARAMETERS *present_parameters) + struct wined3d_swapchain_desc *swapchain_desc) { + static const struct wined3d_color black = {0.0f, 0.0f, 0.0f, 0.0f}; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; struct wined3d_swapchain *swapchain = NULL; struct wined3d_context *context; @@ -1147,57 +1223,19 @@ HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device, DWORD state; unsigned int i; - TRACE("device %p, present_parameters %p.\n", device, present_parameters); + TRACE("device %p, swapchain_desc %p.\n", device, swapchain_desc); if (device->d3d_initialized) return WINED3DERR_INVALIDCALL; if (!device->adapter->opengl) return WINED3DERR_INVALIDCALL; - TRACE("Creating stateblock.\n"); - hr = wined3d_stateblock_create(device, WINED3DSBT_INIT, &device->stateBlock); - if (FAILED(hr)) - { - WARN("Failed to create stateblock\n"); - goto err_out; - } - - TRACE("Created stateblock %p.\n", device->stateBlock); - device->updateStateBlock = device->stateBlock; - wined3d_stateblock_incref(device->updateStateBlock); - device->valid_rt_mask = 0; for (i = 0; i < gl_info->limits.buffers; ++i) device->valid_rt_mask |= (1 << i); device->fb.render_targets = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*device->fb.render_targets) * gl_info->limits.buffers); - device->palette_count = 1; - device->palettes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PALETTEENTRY*)); - if (!device->palettes || !device->fb.render_targets) - { - ERR("Out of memory!\n"); - hr = E_OUTOFMEMORY; - goto err_out; - } - - device->palettes[0] = HeapAlloc(GetProcessHeap(), 0, sizeof(PALETTEENTRY) * 256); - if (!device->palettes[0]) - { - ERR("Out of memory!\n"); - hr = E_OUTOFMEMORY; - goto err_out; - } - - for (i = 0; i < 256; ++i) - { - device->palettes[0][i].peRed = 0xff; - device->palettes[0][i].peGreen = 0xff; - device->palettes[0][i].peBlue = 0xff; - device->palettes[0][i].peFlags = 0xff; - } - device->currentPalette = 0; - /* Initialize the texture unit mapping to a 1:1 mapping */ for (state = 0; state < MAX_COMBINED_SAMPLERS; ++state) { @@ -1216,7 +1254,7 @@ HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device, /* Setup the implicit swapchain. This also initializes a context. */ TRACE("Creating implicit swapchain\n"); hr = device->device_parent->ops->create_swapchain(device->device_parent, - present_parameters, &swapchain); + swapchain_desc, &swapchain); if (FAILED(hr)) { WARN("Failed to create implicit swapchain\n"); @@ -1275,7 +1313,7 @@ HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device, context = context_acquire(device, swapchain->front_buffer); - create_dummy_textures(device); + create_dummy_textures(device, context); ENTER_GL(); @@ -1293,7 +1331,7 @@ HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device, { if (context_get_current()->aux_buffers > 0) { - TRACE("Using auxilliary buffer for offscreen rendering\n"); + TRACE("Using auxiliary buffer for offscreen rendering\n"); device->offscreenBuffer = GL_AUX0; } else @@ -1311,34 +1349,21 @@ HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device, /* Clear the screen */ wined3d_device_clear(device, 0, NULL, WINED3DCLEAR_TARGET - | (present_parameters->EnableAutoDepthStencil ? WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL : 0), - 0x00, 1.0f, 0); + | (swapchain_desc->enable_auto_depth_stencil ? WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL : 0), + &black, 1.0f, 0); device->d3d_initialized = TRUE; if (wined3d_settings.logo) - IWineD3DDeviceImpl_LoadLogo(device, wined3d_settings.logo); - device->highest_dirty_ps_const = 0; - device->highest_dirty_vs_const = 0; + device_load_logo(device, wined3d_settings.logo); return WINED3D_OK; err_out: HeapFree(GetProcessHeap(), 0, device->fb.render_targets); HeapFree(GetProcessHeap(), 0, device->swapchains); device->swapchain_count = 0; - if (device->palettes) - { - HeapFree(GetProcessHeap(), 0, device->palettes[0]); - HeapFree(GetProcessHeap(), 0, device->palettes); - } - device->palette_count = 0; if (swapchain) wined3d_swapchain_decref(swapchain); - if (device->stateBlock) - { - wined3d_stateblock_decref(device->stateBlock); - device->stateBlock = NULL; - } if (device->blit_priv) device->blitter->free_private(device); if (device->fragment_priv) @@ -1350,17 +1375,17 @@ err_out: } HRESULT CDECL wined3d_device_init_gdi(struct wined3d_device *device, - WINED3DPRESENT_PARAMETERS *present_parameters) + struct wined3d_swapchain_desc *swapchain_desc) { struct wined3d_swapchain *swapchain = NULL; HRESULT hr; - TRACE("device %p, present_parameters %p.\n", device, present_parameters); + TRACE("device %p, swapchain_desc %p.\n", device, swapchain_desc); /* Setup the implicit swapchain */ TRACE("Creating implicit swapchain\n"); hr = device->device_parent->ops->create_swapchain(device->device_parent, - present_parameters, &swapchain); + swapchain_desc, &swapchain); if (FAILED(hr)) { WARN("Failed to create implicit swapchain\n"); @@ -1382,17 +1407,9 @@ err_out: return hr; } -static HRESULT WINAPI device_unload_resource(struct wined3d_resource *resource, void *data) -{ - TRACE("Unloading resource %p.\n", resource); - - resource->resource_ops->resource_unload(resource); - - return S_OK; -} - HRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device) { + struct wined3d_resource *resource, *cursor; const struct wined3d_gl_info *gl_info; struct wined3d_context *context; struct wined3d_surface *surface; @@ -1415,8 +1432,15 @@ HRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device) if (device->logo_surface) wined3d_surface_decref(device->logo_surface); + stateblock_unbind_resources(device->stateBlock); + /* Unload resources */ - wined3d_device_enum_resources(device, device_unload_resource, NULL); + LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry) + { + TRACE("Unloading resource %p.\n", resource); + + resource->resource_ops->resource_unload(resource); + } TRACE("Deleting high order patches\n"); for(i = 0; i < PATCHMAP_SIZE; i++) { @@ -1448,32 +1472,6 @@ HRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device) LEAVE_GL(); device->depth_blt_texture = 0; } - if (device->depth_blt_rb) - { - ENTER_GL(); - gl_info->fbo_ops.glDeleteRenderbuffers(1, &device->depth_blt_rb); - LEAVE_GL(); - device->depth_blt_rb = 0; - device->depth_blt_rb_w = 0; - device->depth_blt_rb_h = 0; - } - - /* Release the update stateblock */ - if (wined3d_stateblock_decref(device->updateStateBlock)) - { - if (device->updateStateBlock != device->stateBlock) - FIXME("Something's still holding the update stateblock.\n"); - } - device->updateStateBlock = NULL; - - { - struct wined3d_stateblock *stateblock = device->stateBlock; - device->stateBlock = NULL; - - /* Release the stateblock */ - if (wined3d_stateblock_decref(stateblock)) - FIXME("Something's still holding the stateblock.\n"); - } /* Destroy the shader backend. Note that this has to happen after all shaders are destroyed. */ device->blitter->free_private(device); @@ -1495,9 +1493,7 @@ HRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device) TRACE("Releasing depth/stencil buffer %p.\n", surface); device->fb.depth_stencil = NULL; - if (wined3d_surface_decref(surface) - && surface != device->auto_depth_stencil) - ERR("Something is still holding a reference to depth/stencil buffer %p.\n", surface); + wined3d_surface_decref(surface); } if (device->auto_depth_stencil) @@ -1532,12 +1528,6 @@ HRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device) device->swapchains = NULL; device->swapchain_count = 0; - for (i = 0; i < device->palette_count; ++i) - HeapFree(GetProcessHeap(), 0, device->palettes[i]); - HeapFree(GetProcessHeap(), 0, device->palettes); - device->palettes = NULL; - device->palette_count = 0; - HeapFree(GetProcessHeap(), 0, device->fb.render_targets); device->fb.render_targets = NULL; @@ -1574,19 +1564,20 @@ void CDECL wined3d_device_set_multithreaded(struct wined3d_device *device) TRACE("device %p.\n", device); /* For now just store the flag (needed in case of ddraw). */ - device->createParms.BehaviorFlags |= WINED3DCREATE_MULTITHREADED; + device->create_parms.flags |= WINED3DCREATE_MULTITHREADED; } HRESULT CDECL wined3d_device_set_display_mode(struct wined3d_device *device, - UINT swapchain_idx, const WINED3DDISPLAYMODE *mode) + UINT swapchain_idx, const struct wined3d_display_mode *mode) { - const struct wined3d_format *format = wined3d_get_format(&device->adapter->gl_info, mode->Format); + struct wined3d_adapter *adapter = device->adapter; + const struct wined3d_format *format = wined3d_get_format(&adapter->gl_info, mode->format_id); DEVMODEW devmode; LONG ret; RECT clip_rc; TRACE("device %p, swapchain_idx %u, mode %p (%ux%u@%u %s).\n", device, swapchain_idx, mode, - mode->Width, mode->Height, mode->RefreshRate, debug_d3dformat(mode->Format)); + mode->width, mode->height, mode->refresh_rate, debug_d3dformat(mode->format_id)); /* Resize the screen even without a window: * The app could have unset it with SetCooperativeLevel, but not called @@ -1598,16 +1589,16 @@ HRESULT CDECL wined3d_device_set_display_mode(struct wined3d_device *device, devmode.dmSize = sizeof(devmode); devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; devmode.dmBitsPerPel = format->byte_count * CHAR_BIT; - devmode.dmPelsWidth = mode->Width; - devmode.dmPelsHeight = mode->Height; + devmode.dmPelsWidth = mode->width; + devmode.dmPelsHeight = mode->height; - devmode.dmDisplayFrequency = mode->RefreshRate; - if (mode->RefreshRate) + devmode.dmDisplayFrequency = mode->refresh_rate; + if (mode->refresh_rate) devmode.dmFields |= DM_DISPLAYFREQUENCY; /* Only change the mode if necessary */ - if (device->ddraw_width == mode->Width && device->ddraw_height == mode->Height - && device->ddraw_format == mode->Format && !mode->RefreshRate) + if (adapter->screen_size.cx == mode->width && adapter->screen_size.cy == mode->height + && adapter->screen_format == mode->format_id && !mode->refresh_rate) return WINED3D_OK; ret = ChangeDisplaySettingsExW(NULL, &devmode, NULL, CDS_FULLSCREEN, NULL); @@ -1626,18 +1617,18 @@ HRESULT CDECL wined3d_device_set_display_mode(struct wined3d_device *device, } /* Store the new values */ - device->ddraw_width = mode->Width; - device->ddraw_height = mode->Height; - device->ddraw_format = mode->Format; + adapter->screen_size.cx = mode->width; + adapter->screen_size.cy = mode->height; + adapter->screen_format = mode->format_id; /* And finally clip mouse to our screen */ - SetRect(&clip_rc, 0, 0, mode->Width, mode->Height); + SetRect(&clip_rc, 0, 0, mode->width, mode->height); ClipCursor(&clip_rc); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_wined3d(struct wined3d_device *device, struct wined3d **wined3d) +HRESULT CDECL wined3d_device_get_wined3d(const struct wined3d_device *device, struct wined3d **wined3d) { TRACE("device %p, wined3d %p.\n", device, wined3d); @@ -1649,7 +1640,7 @@ HRESULT CDECL wined3d_device_get_wined3d(struct wined3d_device *device, struct w return WINED3D_OK; } -UINT CDECL wined3d_device_get_available_texture_mem(struct wined3d_device *device) +UINT CDECL wined3d_device_get_available_texture_mem(const struct wined3d_device *device) { TRACE("device %p.\n", device); @@ -1722,12 +1713,12 @@ HRESULT CDECL wined3d_device_set_stream_source(struct wined3d_device *device, UI wined3d_buffer_decref(prev_buffer); } - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_STREAMSRC); + device_invalidate_state(device, STATE_STREAMSRC); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_stream_source(struct wined3d_device *device, +HRESULT CDECL wined3d_device_get_stream_source(const struct wined3d_device *device, UINT stream_idx, struct wined3d_buffer **buffer, UINT *offset, UINT *stride) { struct wined3d_stream_state *stream; @@ -1786,12 +1777,13 @@ HRESULT CDECL wined3d_device_set_stream_source_freq(struct wined3d_device *devic device->updateStateBlock->changed.streamFreq |= 1 << stream_idx; if (stream->frequency != old_freq || stream->flags != old_flags) - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_STREAMSRC); + device_invalidate_state(device, STATE_STREAMSRC); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_stream_source_freq(struct wined3d_device *device, UINT stream_idx, UINT *divider) +HRESULT CDECL wined3d_device_get_stream_source_freq(const struct wined3d_device *device, + UINT stream_idx, UINT *divider) { struct wined3d_stream_state *stream; @@ -1806,7 +1798,7 @@ HRESULT CDECL wined3d_device_get_stream_source_freq(struct wined3d_device *devic } HRESULT CDECL wined3d_device_set_transform(struct wined3d_device *device, - WINED3DTRANSFORMSTATETYPE d3dts, const WINED3DMATRIX *matrix) + enum wined3d_transform_state d3dts, const struct wined3d_matrix *matrix) { TRACE("device %p, state %s, matrix %p.\n", device, debug_d3dtstype(d3dts), matrix); @@ -1840,18 +1832,18 @@ HRESULT CDECL wined3d_device_set_transform(struct wined3d_device *device, * In OpenGL, camera and world space is combined into GL_MODELVIEW * matrix. The Projection matrix stay projection matrix. */ - if (d3dts == WINED3DTS_VIEW) + if (d3dts == WINED3D_TS_VIEW) device->view_ident = !memcmp(matrix, identity, 16 * sizeof(float)); - if (d3dts < WINED3DTS_WORLDMATRIX(device->adapter->gl_info.limits.blends)) - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_TRANSFORM(d3dts)); + if (d3dts < WINED3D_TS_WORLD_MATRIX(device->adapter->gl_info.limits.blends)) + device_invalidate_state(device, STATE_TRANSFORM(d3dts)); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_transform(struct wined3d_device *device, - WINED3DTRANSFORMSTATETYPE state, WINED3DMATRIX *matrix) +HRESULT CDECL wined3d_device_get_transform(const struct wined3d_device *device, + enum wined3d_transform_state state, struct wined3d_matrix *matrix) { TRACE("device %p, state %s, matrix %p.\n", device, debug_d3dtstype(state), matrix); @@ -1861,10 +1853,10 @@ HRESULT CDECL wined3d_device_get_transform(struct wined3d_device *device, } HRESULT CDECL wined3d_device_multiply_transform(struct wined3d_device *device, - WINED3DTRANSFORMSTATETYPE state, const WINED3DMATRIX *matrix) + enum wined3d_transform_state state, const struct wined3d_matrix *matrix) { - const WINED3DMATRIX *mat = NULL; - WINED3DMATRIX temp; + const struct wined3d_matrix *mat = NULL; + struct wined3d_matrix temp; TRACE("device %p, state %s, matrix %p.\n", device, debug_d3dtstype(state), matrix); @@ -1872,12 +1864,13 @@ HRESULT CDECL wined3d_device_multiply_transform(struct wined3d_device *device, * below means it will be recorded in a state block change, but it * works regardless where it is recorded. * If this is found to be wrong, change to StateBlock. */ + if (state > HIGHEST_TRANSFORMSTATE) + { + WARN("Unhandled transform state %#x.\n", state); + return WINED3D_OK; + } - if (state <= HIGHEST_TRANSFORMSTATE) - mat = &device->updateStateBlock->state.transforms[state]; - else - FIXME("Unhandled transform state %#x.\n", state); - + mat = &device->updateStateBlock->state.transforms[state]; multiply_matrix(&temp, mat, matrix); /* Apply change via set transform - will reapply to eg. lights this way. */ @@ -1891,7 +1884,8 @@ HRESULT CDECL wined3d_device_multiply_transform(struct wined3d_device *device, * stateblock problems. When capturing the state block, I duplicate the * hashmap, but when recording, just build a chain pretty much of commands to * be replayed. */ -HRESULT CDECL wined3d_device_set_light(struct wined3d_device *device, UINT light_idx, const WINED3DLIGHT *light) +HRESULT CDECL wined3d_device_set_light(struct wined3d_device *device, + UINT light_idx, const struct wined3d_light *light) { UINT hash_idx = LIGHTMAP_HASHFUNC(light_idx); struct wined3d_light_info *object = NULL; @@ -1905,22 +1899,22 @@ HRESULT CDECL wined3d_device_set_light(struct wined3d_device *device, UINT light if (!light) return WINED3DERR_INVALIDCALL; - switch (light->Type) + switch (light->type) { - case WINED3DLIGHT_POINT: - case WINED3DLIGHT_SPOT: - case WINED3DLIGHT_PARALLELPOINT: - case WINED3DLIGHT_GLSPOT: + case WINED3D_LIGHT_POINT: + case WINED3D_LIGHT_SPOT: + case WINED3D_LIGHT_PARALLELPOINT: + case WINED3D_LIGHT_GLSPOT: /* Incorrect attenuation values can cause the gl driver to crash. * Happens with Need for speed most wanted. */ - if (light->Attenuation0 < 0.0f || light->Attenuation1 < 0.0f || light->Attenuation2 < 0.0f) + if (light->attenuation0 < 0.0f || light->attenuation1 < 0.0f || light->attenuation2 < 0.0f) { WARN("Attenuation is negative, returning WINED3DERR_INVALIDCALL.\n"); return WINED3DERR_INVALIDCALL; } break; - case WINED3DLIGHT_DIRECTIONAL: + case WINED3D_LIGHT_DIRECTIONAL: /* Ignores attenuation */ break; @@ -1953,51 +1947,51 @@ HRESULT CDECL wined3d_device_set_light(struct wined3d_device *device, UINT light /* Initialize the object. */ TRACE("Light %d setting to type %d, Diffuse(%f,%f,%f,%f), Specular(%f,%f,%f,%f), Ambient(%f,%f,%f,%f)\n", - light_idx, light->Type, - light->Diffuse.r, light->Diffuse.g, light->Diffuse.b, light->Diffuse.a, - light->Specular.r, light->Specular.g, light->Specular.b, light->Specular.a, - light->Ambient.r, light->Ambient.g, light->Ambient.b, light->Ambient.a); - TRACE("... Pos(%f,%f,%f), Dir(%f,%f,%f)\n", light->Position.x, light->Position.y, light->Position.z, - light->Direction.x, light->Direction.y, light->Direction.z); + light_idx, light->type, + light->diffuse.r, light->diffuse.g, light->diffuse.b, light->diffuse.a, + light->specular.r, light->specular.g, light->specular.b, light->specular.a, + light->ambient.r, light->ambient.g, light->ambient.b, light->ambient.a); + TRACE("... Pos(%f,%f,%f), Dir(%f,%f,%f)\n", light->position.x, light->position.y, light->position.z, + light->direction.x, light->direction.y, light->direction.z); TRACE("... Range(%f), Falloff(%f), Theta(%f), Phi(%f)\n", - light->Range, light->Falloff, light->Theta, light->Phi); + light->range, light->falloff, light->theta, light->phi); /* Save away the information. */ object->OriginalParms = *light; - switch (light->Type) + switch (light->type) { - case WINED3DLIGHT_POINT: + case WINED3D_LIGHT_POINT: /* Position */ - object->lightPosn[0] = light->Position.x; - object->lightPosn[1] = light->Position.y; - object->lightPosn[2] = light->Position.z; + object->lightPosn[0] = light->position.x; + object->lightPosn[1] = light->position.y; + object->lightPosn[2] = light->position.z; object->lightPosn[3] = 1.0f; object->cutoff = 180.0f; /* FIXME: Range */ break; - case WINED3DLIGHT_DIRECTIONAL: + case WINED3D_LIGHT_DIRECTIONAL: /* Direction */ - object->lightPosn[0] = -light->Direction.x; - object->lightPosn[1] = -light->Direction.y; - object->lightPosn[2] = -light->Direction.z; + object->lightPosn[0] = -light->direction.x; + object->lightPosn[1] = -light->direction.y; + object->lightPosn[2] = -light->direction.z; object->lightPosn[3] = 0.0f; object->exponent = 0.0f; object->cutoff = 180.0f; break; - case WINED3DLIGHT_SPOT: + case WINED3D_LIGHT_SPOT: /* Position */ - object->lightPosn[0] = light->Position.x; - object->lightPosn[1] = light->Position.y; - object->lightPosn[2] = light->Position.z; + object->lightPosn[0] = light->position.x; + object->lightPosn[1] = light->position.y; + object->lightPosn[2] = light->position.z; object->lightPosn[3] = 1.0f; /* Direction */ - object->lightDirn[0] = light->Direction.x; - object->lightDirn[1] = light->Direction.y; - object->lightDirn[2] = light->Direction.z; + object->lightDirn[0] = light->direction.x; + object->lightDirn[1] = light->direction.y; + object->lightDirn[2] = light->direction.z; object->lightDirn[3] = 1.0f; /* opengl-ish and d3d-ish spot lights use too different models @@ -2006,7 +2000,7 @@ HRESULT CDECL wined3d_device_set_light(struct wined3d_device *device, UINT light * roughly. However, spot lights are rather rarely used in games * (if ever used at all). Furthermore if still used, probably * nobody pays attention to such details. */ - if (!light->Falloff) + if (!light->falloff) { /* Falloff = 0 is easy, because d3d's and opengl's spot light * equations have the falloff resp. exponent parameter as an @@ -2017,7 +2011,7 @@ HRESULT CDECL wined3d_device_set_light(struct wined3d_device *device, UINT light } else { - rho = light->Theta + (light->Phi - light->Theta) / (2 * light->Falloff); + rho = light->theta + (light->phi - light->theta) / (2 * light->falloff); if (rho < 0.0001f) rho = 0.0001f; object->exponent = -0.3f / logf(cosf(rho / 2)); @@ -2026,22 +2020,23 @@ HRESULT CDECL wined3d_device_set_light(struct wined3d_device *device, UINT light if (object->exponent > 128.0f) object->exponent = 128.0f; - object->cutoff = (float)(light->Phi * 90 / M_PI); + object->cutoff = (float)(light->phi * 90 / M_PI); /* FIXME: Range */ break; default: - FIXME("Unrecognized light type %#x.\n", light->Type); + FIXME("Unrecognized light type %#x.\n", light->type); } /* Update the live definitions if the light is currently assigned a glIndex. */ if (object->glIndex != -1 && !device->isRecordingState) - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_ACTIVELIGHT(object->glIndex)); + device_invalidate_state(device, STATE_ACTIVELIGHT(object->glIndex)); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_light(struct wined3d_device *device, UINT light_idx, WINED3DLIGHT *light) +HRESULT CDECL wined3d_device_get_light(const struct wined3d_device *device, + UINT light_idx, struct wined3d_light *light) { UINT hash_idx = LIGHTMAP_HASHFUNC(light_idx); struct wined3d_light_info *light_info = NULL; @@ -2110,7 +2105,7 @@ HRESULT CDECL wined3d_device_set_light_enable(struct wined3d_device *device, UIN if (light_info->glIndex != -1) { if (!device->isRecordingState) - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_ACTIVELIGHT(light_info->glIndex)); + device_invalidate_state(device, STATE_ACTIVELIGHT(light_info->glIndex)); device->updateStateBlock->state.lights[light_info->glIndex] = NULL; light_info->glIndex = -1; @@ -2156,14 +2151,14 @@ HRESULT CDECL wined3d_device_set_light_enable(struct wined3d_device *device, UIN /* i == light_info->glIndex */ if (!device->isRecordingState) - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_ACTIVELIGHT(i)); + device_invalidate_state(device, STATE_ACTIVELIGHT(i)); } } return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_light_enable(struct wined3d_device *device, UINT light_idx, BOOL *enable) +HRESULT CDECL wined3d_device_get_light_enable(const struct wined3d_device *device, UINT light_idx, BOOL *enable) { UINT hash_idx = LIGHTMAP_HASHFUNC(light_idx); struct wined3d_light_info *light_info = NULL; @@ -2223,12 +2218,12 @@ HRESULT CDECL wined3d_device_set_clip_plane(struct wined3d_device *device, UINT return WINED3D_OK; } - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_CLIPPLANE(plane_idx)); + device_invalidate_state(device, STATE_CLIPPLANE(plane_idx)); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_clip_plane(struct wined3d_device *device, UINT plane_idx, float *plane) +HRESULT CDECL wined3d_device_get_clip_plane(const struct wined3d_device *device, UINT plane_idx, float *plane) { TRACE("device %p, plane_idx %u, plane %p.\n", device, plane_idx, plane); @@ -2247,33 +2242,29 @@ HRESULT CDECL wined3d_device_get_clip_plane(struct wined3d_device *device, UINT return WINED3D_OK; } -HRESULT CDECL wined3d_device_set_clip_status(struct wined3d_device *device, const WINED3DCLIPSTATUS *clip_status) +HRESULT CDECL wined3d_device_set_clip_status(struct wined3d_device *device, + const struct wined3d_clip_status *clip_status) { FIXME("device %p, clip_status %p stub!\n", device, clip_status); if (!clip_status) return WINED3DERR_INVALIDCALL; - device->updateStateBlock->state.clip_status.ClipUnion = clip_status->ClipUnion; - device->updateStateBlock->state.clip_status.ClipIntersection = clip_status->ClipIntersection; - return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_clip_status(struct wined3d_device *device, WINED3DCLIPSTATUS *clip_status) +HRESULT CDECL wined3d_device_get_clip_status(const struct wined3d_device *device, + struct wined3d_clip_status *clip_status) { FIXME("device %p, clip_status %p stub!\n", device, clip_status); if (!clip_status) return WINED3DERR_INVALIDCALL; - clip_status->ClipUnion = device->updateStateBlock->state.clip_status.ClipUnion; - clip_status->ClipIntersection = device->updateStateBlock->state.clip_status.ClipIntersection; - return WINED3D_OK; } -HRESULT CDECL wined3d_device_set_material(struct wined3d_device *device, const WINED3DMATERIAL *material) +HRESULT CDECL wined3d_device_set_material(struct wined3d_device *device, const struct wined3d_material *material) { TRACE("device %p, material %p.\n", device, material); @@ -2287,30 +2278,30 @@ HRESULT CDECL wined3d_device_set_material(struct wined3d_device *device, const W return WINED3D_OK; } - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_MATERIAL); + device_invalidate_state(device, STATE_MATERIAL); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_material(struct wined3d_device *device, WINED3DMATERIAL *material) +HRESULT CDECL wined3d_device_get_material(const struct wined3d_device *device, struct wined3d_material *material) { TRACE("device %p, material %p.\n", device, material); *material = device->updateStateBlock->state.material; - TRACE("Diffuse {%.8e, %.8e, %.8e, %.8e}\n", - material->Diffuse.r, material->Diffuse.g, - material->Diffuse.b, material->Diffuse.a); - TRACE("Ambient {%.8e, %.8e, %.8e, %.8e}\n", - material->Ambient.r, material->Ambient.g, - material->Ambient.b, material->Ambient.a); - TRACE("Specular {%.8e, %.8e, %.8e, %.8e}\n", - material->Specular.r, material->Specular.g, - material->Specular.b, material->Specular.a); - TRACE("Emissive {%.8e, %.8e, %.8e, %.8e}\n", - material->Emissive.r, material->Emissive.g, - material->Emissive.b, material->Emissive.a); - TRACE("Power %.8e.\n", material->Power); + TRACE("diffuse {%.8e, %.8e, %.8e, %.8e}\n", + material->diffuse.r, material->diffuse.g, + material->diffuse.b, material->diffuse.a); + TRACE("ambient {%.8e, %.8e, %.8e, %.8e}\n", + material->ambient.r, material->ambient.g, + material->ambient.b, material->ambient.a); + TRACE("specular {%.8e, %.8e, %.8e, %.8e}\n", + material->specular.r, material->specular.g, + material->specular.b, material->specular.a); + TRACE("emissive {%.8e, %.8e, %.8e, %.8e}\n", + material->emissive.r, material->emissive.g, + material->emissive.b, material->emissive.a); + TRACE("power %.8e.\n", material->power); return WINED3D_OK; } @@ -2342,7 +2333,7 @@ HRESULT CDECL wined3d_device_set_index_buffer(struct wined3d_device *device, if (prev_buffer != buffer) { - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_INDEXBUFFER); + device_invalidate_state(device, STATE_INDEXBUFFER); if (buffer) { InterlockedIncrement(&buffer->bind_count); @@ -2358,7 +2349,7 @@ HRESULT CDECL wined3d_device_set_index_buffer(struct wined3d_device *device, return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_index_buffer(struct wined3d_device *device, struct wined3d_buffer **buffer) +HRESULT CDECL wined3d_device_get_index_buffer(const struct wined3d_device *device, struct wined3d_buffer **buffer) { TRACE("device %p, buffer %p.\n", device, buffer); @@ -2390,25 +2381,21 @@ HRESULT CDECL wined3d_device_set_base_vertex_index(struct wined3d_device *device TRACE("Recording... not performing anything\n"); return WINED3D_OK; } - - /* The base vertex index affects the stream sources */ - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_STREAMSRC); - return WINED3D_OK; } -INT CDECL wined3d_device_get_base_vertex_index(struct wined3d_device *device) +INT CDECL wined3d_device_get_base_vertex_index(const struct wined3d_device *device) { TRACE("device %p.\n", device); return device->stateBlock->state.base_vertex_index; } -HRESULT CDECL wined3d_device_set_viewport(struct wined3d_device *device, const WINED3DVIEWPORT *viewport) +HRESULT CDECL wined3d_device_set_viewport(struct wined3d_device *device, const struct wined3d_viewport *viewport) { TRACE("device %p, viewport %p.\n", device, viewport); - TRACE("x %u, y %u, w %u, h %u, minz %.8e, maxz %.8e.\n", - viewport->X, viewport->Y, viewport->Width, viewport->Height, viewport->MinZ, viewport->MaxZ); + TRACE("x %u, y %u, w %u, h %u, min_z %.8e, max_z %.8e.\n", + viewport->x, viewport->y, viewport->width, viewport->height, viewport->min_z, viewport->max_z); device->updateStateBlock->changed.viewport = TRUE; device->updateStateBlock->state.viewport = *viewport; @@ -2420,12 +2407,12 @@ HRESULT CDECL wined3d_device_set_viewport(struct wined3d_device *device, const W return WINED3D_OK; } - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_VIEWPORT); + device_invalidate_state(device, STATE_VIEWPORT); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_viewport(struct wined3d_device *device, WINED3DVIEWPORT *viewport) +HRESULT CDECL wined3d_device_get_viewport(const struct wined3d_device *device, struct wined3d_viewport *viewport) { TRACE("device %p, viewport %p.\n", device, viewport); @@ -2435,7 +2422,7 @@ HRESULT CDECL wined3d_device_get_viewport(struct wined3d_device *device, WINED3D } HRESULT CDECL wined3d_device_set_render_state(struct wined3d_device *device, - WINED3DRENDERSTATETYPE state, DWORD value) + enum wined3d_render_state state, DWORD value) { DWORD old_value = device->stateBlock->state.render_states[state]; @@ -2455,13 +2442,13 @@ HRESULT CDECL wined3d_device_set_render_state(struct wined3d_device *device, if (value == old_value) TRACE("Application is setting the old value over, nothing to do.\n"); else - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(state)); + device_invalidate_state(device, STATE_RENDER(state)); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_render_state(struct wined3d_device *device, - WINED3DRENDERSTATETYPE state, DWORD *value) +HRESULT CDECL wined3d_device_get_render_state(const struct wined3d_device *device, + enum wined3d_render_state state, DWORD *value) { TRACE("device %p, state %s (%#x), value %p.\n", device, debug_d3drenderstate(state), state, value); @@ -2471,7 +2458,7 @@ HRESULT CDECL wined3d_device_get_render_state(struct wined3d_device *device, } HRESULT CDECL wined3d_device_set_sampler_state(struct wined3d_device *device, - UINT sampler_idx, WINED3DSAMPLERSTATETYPE state, DWORD value) + UINT sampler_idx, enum wined3d_sampler_state state, DWORD value) { DWORD old_value; @@ -2505,13 +2492,13 @@ HRESULT CDECL wined3d_device_set_sampler_state(struct wined3d_device *device, return WINED3D_OK; } - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(sampler_idx)); + device_invalidate_state(device, STATE_SAMPLER(sampler_idx)); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_sampler_state(struct wined3d_device *device, - UINT sampler_idx, WINED3DSAMPLERSTATETYPE state, DWORD *value) +HRESULT CDECL wined3d_device_get_sampler_state(const struct wined3d_device *device, + UINT sampler_idx, enum wined3d_sampler_state state, DWORD *value) { TRACE("device %p, sampler_idx %u, state %s, value %p.\n", device, sampler_idx, debug_d3dsamplerstate(state), value); @@ -2550,12 +2537,12 @@ HRESULT CDECL wined3d_device_set_scissor_rect(struct wined3d_device *device, con return WINED3D_OK; } - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SCISSORRECT); + device_invalidate_state(device, STATE_SCISSORRECT); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_scissor_rect(struct wined3d_device *device, RECT *rect) +HRESULT CDECL wined3d_device_get_scissor_rect(const struct wined3d_device *device, RECT *rect) { TRACE("device %p, rect %p.\n", device, rect); @@ -2592,11 +2579,11 @@ HRESULT CDECL wined3d_device_set_vertex_declaration(struct wined3d_device *devic return WINED3D_OK; } - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_VDECL); + device_invalidate_state(device, STATE_VDECL); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_vertex_declaration(struct wined3d_device *device, +HRESULT CDECL wined3d_device_get_vertex_declaration(const struct wined3d_device *device, struct wined3d_vertex_declaration **declaration) { TRACE("device %p, declaration %p.\n", device, declaration); @@ -2638,12 +2625,12 @@ HRESULT CDECL wined3d_device_set_vertex_shader(struct wined3d_device *device, st if (prev) wined3d_shader_decref(prev); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_VSHADER); + device_invalidate_state(device, STATE_VSHADER); return WINED3D_OK; } -struct wined3d_shader * CDECL wined3d_device_get_vertex_shader(struct wined3d_device *device) +struct wined3d_shader * CDECL wined3d_device_get_vertex_shader(const struct wined3d_device *device) { struct wined3d_shader *shader; @@ -2677,12 +2664,12 @@ HRESULT CDECL wined3d_device_set_vs_consts_b(struct wined3d_device *device, device->updateStateBlock->changed.vertexShaderConstantsB |= (1 << i); if (!device->isRecordingState) - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_VERTEXSHADERCONSTANT); + device_invalidate_state(device, STATE_VERTEXSHADERCONSTANT); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_vs_consts_b(struct wined3d_device *device, +HRESULT CDECL wined3d_device_get_vs_consts_b(const struct wined3d_device *device, UINT start_register, BOOL *constants, UINT bool_count) { UINT count = min(bool_count, MAX_CONST_B - start_register); @@ -2720,12 +2707,12 @@ HRESULT CDECL wined3d_device_set_vs_consts_i(struct wined3d_device *device, device->updateStateBlock->changed.vertexShaderConstantsI |= (1 << i); if (!device->isRecordingState) - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_VERTEXSHADERCONSTANT); + device_invalidate_state(device, STATE_VERTEXSHADERCONSTANT); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_vs_consts_i(struct wined3d_device *device, +HRESULT CDECL wined3d_device_get_vs_consts_i(const struct wined3d_device *device, UINT start_register, int *constants, UINT vector4i_count) { UINT count = min(vector4i_count, MAX_CONST_I - start_register); @@ -2768,7 +2755,7 @@ HRESULT CDECL wined3d_device_set_vs_consts_f(struct wined3d_device *device, if (!device->isRecordingState) { device->shader_backend->shader_update_float_vertex_constants(device, start_register, vector4f_count); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_VERTEXSHADERCONSTANT); + device_invalidate_state(device, STATE_VERTEXSHADERCONSTANT); } memset(device->updateStateBlock->changed.vertexShaderConstantsF + start_register, 1, @@ -2777,7 +2764,7 @@ HRESULT CDECL wined3d_device_set_vs_consts_f(struct wined3d_device *device, return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_vs_consts_f(struct wined3d_device *device, +HRESULT CDECL wined3d_device_get_vs_consts_f(const struct wined3d_device *device, UINT start_register, float *constants, UINT vector4f_count) { int count = min(vector4f_count, device->d3d_vshader_constantF - start_register); @@ -2793,13 +2780,13 @@ HRESULT CDECL wined3d_device_get_vs_consts_f(struct wined3d_device *device, return WINED3D_OK; } -static inline void markTextureStagesDirty(struct wined3d_device *device, DWORD stage) +static void device_invalidate_texture_stage(const struct wined3d_device *device, DWORD stage) { DWORD i; for (i = 0; i <= WINED3D_HIGHEST_TEXTURE_STATE; ++i) { - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_TEXTURESTAGE(stage, i)); + device_invalidate_state(device, STATE_TEXTURESTAGE(stage, i)); } } @@ -2825,31 +2812,31 @@ static void device_update_fixed_function_usage_map(struct wined3d_device *device for (i = 0; i < MAX_TEXTURES; ++i) { const struct wined3d_state *state = &device->stateBlock->state; - WINED3DTEXTUREOP color_op = state->texture_states[i][WINED3DTSS_COLOROP]; - WINED3DTEXTUREOP alpha_op = state->texture_states[i][WINED3DTSS_ALPHAOP]; - DWORD color_arg1 = state->texture_states[i][WINED3DTSS_COLORARG1] & WINED3DTA_SELECTMASK; - DWORD color_arg2 = state->texture_states[i][WINED3DTSS_COLORARG2] & WINED3DTA_SELECTMASK; - DWORD color_arg3 = state->texture_states[i][WINED3DTSS_COLORARG0] & WINED3DTA_SELECTMASK; - DWORD alpha_arg1 = state->texture_states[i][WINED3DTSS_ALPHAARG1] & WINED3DTA_SELECTMASK; - DWORD alpha_arg2 = state->texture_states[i][WINED3DTSS_ALPHAARG2] & WINED3DTA_SELECTMASK; - DWORD alpha_arg3 = state->texture_states[i][WINED3DTSS_ALPHAARG0] & WINED3DTA_SELECTMASK; + enum wined3d_texture_op color_op = state->texture_states[i][WINED3D_TSS_COLOR_OP]; + enum wined3d_texture_op alpha_op = state->texture_states[i][WINED3D_TSS_ALPHA_OP]; + DWORD color_arg1 = state->texture_states[i][WINED3D_TSS_COLOR_ARG1] & WINED3DTA_SELECTMASK; + DWORD color_arg2 = state->texture_states[i][WINED3D_TSS_COLOR_ARG2] & WINED3DTA_SELECTMASK; + DWORD color_arg3 = state->texture_states[i][WINED3D_TSS_COLOR_ARG0] & WINED3DTA_SELECTMASK; + DWORD alpha_arg1 = state->texture_states[i][WINED3D_TSS_ALPHA_ARG1] & WINED3DTA_SELECTMASK; + DWORD alpha_arg2 = state->texture_states[i][WINED3D_TSS_ALPHA_ARG2] & WINED3DTA_SELECTMASK; + DWORD alpha_arg3 = state->texture_states[i][WINED3D_TSS_ALPHA_ARG0] & WINED3DTA_SELECTMASK; - if (color_op == WINED3DTOP_DISABLE) { - /* Not used, and disable higher stages */ + /* Not used, and disable higher stages. */ + if (color_op == WINED3D_TOP_DISABLE) break; - } - if (((color_arg1 == WINED3DTA_TEXTURE) && color_op != WINED3DTOP_SELECTARG2) - || ((color_arg2 == WINED3DTA_TEXTURE) && color_op != WINED3DTOP_SELECTARG1) + if (((color_arg1 == WINED3DTA_TEXTURE) && color_op != WINED3D_TOP_SELECT_ARG2) + || ((color_arg2 == WINED3DTA_TEXTURE) && color_op != WINED3D_TOP_SELECT_ARG1) || ((color_arg3 == WINED3DTA_TEXTURE) - && (color_op == WINED3DTOP_MULTIPLYADD || color_op == WINED3DTOP_LERP)) - || ((alpha_arg1 == WINED3DTA_TEXTURE) && alpha_op != WINED3DTOP_SELECTARG2) - || ((alpha_arg2 == WINED3DTA_TEXTURE) && alpha_op != WINED3DTOP_SELECTARG1) + && (color_op == WINED3D_TOP_MULTIPLY_ADD || color_op == WINED3D_TOP_LERP)) + || ((alpha_arg1 == WINED3DTA_TEXTURE) && alpha_op != WINED3D_TOP_SELECT_ARG2) + || ((alpha_arg2 == WINED3DTA_TEXTURE) && alpha_op != WINED3D_TOP_SELECT_ARG1) || ((alpha_arg3 == WINED3DTA_TEXTURE) - && (alpha_op == WINED3DTOP_MULTIPLYADD || alpha_op == WINED3DTOP_LERP))) + && (alpha_op == WINED3D_TOP_MULTIPLY_ADD || alpha_op == WINED3D_TOP_LERP))) device->fixed_function_usage_map |= (1 << i); - if ((color_op == WINED3DTOP_BUMPENVMAP || color_op == WINED3DTOP_BUMPENVMAPLUMINANCE) && i < MAX_TEXTURES - 1) + if ((color_op == WINED3D_TOP_BUMPENVMAP || color_op == WINED3D_TOP_BUMPENVMAP_LUMINANCE) + && i < MAX_TEXTURES - 1) device->fixed_function_usage_map |= (1 << (i + 1)); } } @@ -2872,8 +2859,8 @@ static void device_map_fixed_function_samplers(struct wined3d_device *device, co if (device->texUnitMap[i] != i) { device_map_stage(device, i, i); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(i)); - markTextureStagesDirty(device, i); + device_invalidate_state(device, STATE_SAMPLER(i)); + device_invalidate_texture_stage(device, i); } } return; @@ -2888,8 +2875,8 @@ static void device_map_fixed_function_samplers(struct wined3d_device *device, co if (device->texUnitMap[i] != tex) { device_map_stage(device, i, tex); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(i)); - markTextureStagesDirty(device, i); + device_invalidate_state(device, STATE_SAMPLER(i)); + device_invalidate_texture_stage(device, i); } ++tex; @@ -2898,7 +2885,7 @@ static void device_map_fixed_function_samplers(struct wined3d_device *device, co static void device_map_psamplers(struct wined3d_device *device, const struct wined3d_gl_info *gl_info) { - const WINED3DSAMPLER_TEXTURE_TYPE *sampler_type = + const enum wined3d_sampler_texture_type *sampler_type = device->stateBlock->state.pixel_shader->reg_maps.sampler_type; unsigned int i; @@ -2907,18 +2894,16 @@ static void device_map_psamplers(struct wined3d_device *device, const struct win if (sampler_type[i] && device->texUnitMap[i] != i) { device_map_stage(device, i, i); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(i)); + device_invalidate_state(device, STATE_SAMPLER(i)); if (i < gl_info->limits.texture_stages) - { - markTextureStagesDirty(device, i); - } + device_invalidate_texture_stage(device, i); } } } -static BOOL device_unit_free_for_vs(struct wined3d_device *device, - const WINED3DSAMPLER_TEXTURE_TYPE *pshader_sampler_tokens, - const WINED3DSAMPLER_TEXTURE_TYPE *vshader_sampler_tokens, DWORD unit) +static BOOL device_unit_free_for_vs(const struct wined3d_device *device, + const enum wined3d_sampler_texture_type *pshader_sampler_tokens, + const enum wined3d_sampler_texture_type *vshader_sampler_tokens, DWORD unit) { DWORD current_mapping = device->rev_tex_unit_map[unit]; @@ -2943,9 +2928,9 @@ static BOOL device_unit_free_for_vs(struct wined3d_device *device, static void device_map_vsamplers(struct wined3d_device *device, BOOL ps, const struct wined3d_gl_info *gl_info) { - const WINED3DSAMPLER_TEXTURE_TYPE *vshader_sampler_type = + const enum wined3d_sampler_texture_type *vshader_sampler_type = device->stateBlock->state.vertex_shader->reg_maps.sampler_type; - const WINED3DSAMPLER_TEXTURE_TYPE *pshader_sampler_type = NULL; + const enum wined3d_sampler_texture_type *pshader_sampler_type = NULL; int start = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers) - 1; int i; @@ -2971,7 +2956,7 @@ static void device_map_vsamplers(struct wined3d_device *device, BOOL ps, const s if (device_unit_free_for_vs(device, pshader_sampler_type, vshader_sampler_type, start)) { device_map_stage(device, vsampler_idx, start); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(vsampler_idx)); + device_invalidate_state(device, STATE_SAMPLER(vsampler_idx)); --start; break; @@ -3035,12 +3020,12 @@ HRESULT CDECL wined3d_device_set_pixel_shader(struct wined3d_device *device, str if (prev) wined3d_shader_decref(prev); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_PIXELSHADER); + device_invalidate_state(device, STATE_PIXELSHADER); return WINED3D_OK; } -struct wined3d_shader * CDECL wined3d_device_get_pixel_shader(struct wined3d_device *device) +struct wined3d_shader * CDECL wined3d_device_get_pixel_shader(const struct wined3d_device *device) { struct wined3d_shader *shader; @@ -3074,12 +3059,12 @@ HRESULT CDECL wined3d_device_set_ps_consts_b(struct wined3d_device *device, device->updateStateBlock->changed.pixelShaderConstantsB |= (1 << i); if (!device->isRecordingState) - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_PIXELSHADERCONSTANT); + device_invalidate_state(device, STATE_PIXELSHADERCONSTANT); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_ps_consts_b(struct wined3d_device *device, +HRESULT CDECL wined3d_device_get_ps_consts_b(const struct wined3d_device *device, UINT start_register, BOOL *constants, UINT bool_count) { UINT count = min(bool_count, MAX_CONST_B - start_register); @@ -3117,12 +3102,12 @@ HRESULT CDECL wined3d_device_set_ps_consts_i(struct wined3d_device *device, device->updateStateBlock->changed.pixelShaderConstantsI |= (1 << i); if (!device->isRecordingState) - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_PIXELSHADERCONSTANT); + device_invalidate_state(device, STATE_PIXELSHADERCONSTANT); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_ps_consts_i(struct wined3d_device *device, +HRESULT CDECL wined3d_device_get_ps_consts_i(const struct wined3d_device *device, UINT start_register, int *constants, UINT vector4i_count) { UINT count = min(vector4i_count, MAX_CONST_I - start_register); @@ -3166,7 +3151,7 @@ HRESULT CDECL wined3d_device_set_ps_consts_f(struct wined3d_device *device, if (!device->isRecordingState) { device->shader_backend->shader_update_float_pixel_constants(device, start_register, vector4f_count); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_PIXELSHADERCONSTANT); + device_invalidate_state(device, STATE_PIXELSHADERCONSTANT); } memset(device->updateStateBlock->changed.pixelShaderConstantsF + start_register, 1, @@ -3175,7 +3160,7 @@ HRESULT CDECL wined3d_device_set_ps_consts_f(struct wined3d_device *device, return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_ps_consts_f(struct wined3d_device *device, +HRESULT CDECL wined3d_device_get_ps_consts_f(const struct wined3d_device *device, UINT start_register, float *constants, UINT vector4f_count) { int count = min(vector4f_count, device->d3d_pshader_constantF - start_register); @@ -3194,15 +3179,15 @@ HRESULT CDECL wined3d_device_get_ps_consts_f(struct wined3d_device *device, /* Context activation is done by the caller. */ /* Do not call while under the GL lock. */ #define copy_and_next(dest, src, size) memcpy(dest, src, size); dest += (size) -static HRESULT process_vertices_strided(struct wined3d_device *device, DWORD dwDestIndex, DWORD dwCount, +static HRESULT process_vertices_strided(const struct wined3d_device *device, DWORD dwDestIndex, DWORD dwCount, const struct wined3d_stream_info *stream_info, struct wined3d_buffer *dest, DWORD flags, DWORD DestFVF) { const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; char *dest_ptr, *dest_conv = NULL, *dest_conv_addr = NULL; + struct wined3d_matrix mat, proj_mat, view_mat, world_mat; + struct wined3d_viewport vp; unsigned int i; - WINED3DVIEWPORT vp; - WINED3DMATRIX mat, proj_mat, view_mat, world_mat; BOOL doClip; DWORD numTextures; @@ -3245,7 +3230,7 @@ static HRESULT process_vertices_strided(struct wined3d_device *device, DWORD dwD dest_conv = dest_conv_addr; } - if (device->stateBlock->state.render_states[WINED3DRS_CLIPPING]) + if (device->stateBlock->state.render_states[WINED3D_RS_CLIPPING]) { static BOOL warned = FALSE; /* @@ -3264,9 +3249,9 @@ static HRESULT process_vertices_strided(struct wined3d_device *device, DWORD dwD } else doClip = FALSE; dest_ptr = ((char *)buffer_get_sysmem(dest, gl_info)) + dwDestIndex * get_flexible_vertex_size(DestFVF); - wined3d_device_get_transform(device, WINED3DTS_VIEW, &view_mat); - wined3d_device_get_transform(device, WINED3DTS_PROJECTION, &proj_mat); - wined3d_device_get_transform(device, WINED3DTS_WORLDMATRIX(0), &world_mat); + wined3d_device_get_transform(device, WINED3D_TS_VIEW, &view_mat); + wined3d_device_get_transform(device, WINED3D_TS_PROJECTION, &proj_mat); + wined3d_device_get_transform(device, WINED3D_TS_WORLD_MATRIX(0), &world_mat); TRACE("View mat:\n"); TRACE("%f %f %f %f\n", view_mat.u.s._11, view_mat.u.s._12, view_mat.u.s._13, view_mat.u.s._14); @@ -3288,8 +3273,8 @@ static HRESULT process_vertices_strided(struct wined3d_device *device, DWORD dwD /* Get the viewport */ wined3d_device_get_viewport(device, &vp); - TRACE("Viewport: X=%d, Y=%d, Width=%d, Height=%d, MinZ=%f, MaxZ=%f\n", - vp.X, vp.Y, vp.Width, vp.Height, vp.MinZ, vp.MaxZ); + TRACE("viewport x %u, y %u, width %u, height %u, min_z %.8e, max_z %.8e.\n", + vp.x, vp.y, vp.width, vp.height, vp.min_z, vp.max_z); multiply_matrix(&mat,&view_mat,&world_mat); multiply_matrix(&mat,&proj_mat,&mat); @@ -3303,7 +3288,7 @@ static HRESULT process_vertices_strided(struct wined3d_device *device, DWORD dwD ((DestFVF & WINED3DFVF_POSITION_MASK) == WINED3DFVF_XYZRHW ) ) { /* The position first */ const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_POSITION]; - const float *p = (const float *)(element->data + i * element->stride); + const float *p = (const float *)(element->data.addr + i * element->stride); float x, y, z, rhw; TRACE("In: ( %06.2f %06.2f %06.2f )\n", p[0], p[1], p[2]); @@ -3358,13 +3343,13 @@ static HRESULT process_vertices_strided(struct wined3d_device *device, DWORD dwD y *= -1; - x *= vp.Width / 2; - y *= vp.Height / 2; - z *= vp.MaxZ - vp.MinZ; + x *= vp.width / 2; + y *= vp.height / 2; + z *= vp.max_z - vp.min_z; - x += vp.Width / 2 + vp.X; - y += vp.Height / 2 + vp.Y; - z += vp.MinZ; + x += vp.width / 2 + vp.x; + y += vp.height / 2 + vp.y; + z += vp.min_z; rhw = 1 / rhw; } else { @@ -3417,9 +3402,10 @@ static HRESULT process_vertices_strided(struct wined3d_device *device, DWORD dwD dest_ptr += sizeof(DWORD); if(dest_conv) dest_conv += sizeof(DWORD); } - if (DestFVF & WINED3DFVF_NORMAL) { + if (DestFVF & WINED3DFVF_NORMAL) + { const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_NORMAL]; - const float *normal = (const float *)(element->data + i * element->stride); + const float *normal = (const float *)(element->data.addr + i * element->stride); /* AFAIK this should go into the lighting information */ FIXME("Didn't expect the destination to have a normal\n"); copy_and_next(dest_ptr, normal, 3 * sizeof(float)); @@ -3428,9 +3414,10 @@ static HRESULT process_vertices_strided(struct wined3d_device *device, DWORD dwD } } - if (DestFVF & WINED3DFVF_DIFFUSE) { + if (DestFVF & WINED3DFVF_DIFFUSE) + { const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_DIFFUSE]; - const DWORD *color_d = (const DWORD *)(element->data + i * element->stride); + const DWORD *color_d = (const DWORD *)(element->data.addr + i * element->stride); if (!(stream_info->use_map & (1 << WINED3D_FFP_DIFFUSE))) { static BOOL warned = FALSE; @@ -3463,7 +3450,7 @@ static HRESULT process_vertices_strided(struct wined3d_device *device, DWORD dwD { /* What's the color value in the feedback buffer? */ const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_SPECULAR]; - const DWORD *color_s = (const DWORD *)(element->data + i * element->stride); + const DWORD *color_s = (const DWORD *)(element->data.addr + i * element->stride); if (!(stream_info->use_map & (1 << WINED3D_FFP_SPECULAR))) { static BOOL warned = FALSE; @@ -3492,9 +3479,10 @@ static HRESULT process_vertices_strided(struct wined3d_device *device, DWORD dwD } } - for (tex_index = 0; tex_index < numTextures; tex_index++) { + for (tex_index = 0; tex_index < numTextures; ++tex_index) + { const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_TEXCOORD0 + tex_index]; - const float *tex_coord = (const float *)(element->data + i * element->stride); + const float *tex_coord = (const float *)(element->data.addr + i * element->stride); if (!(stream_info->use_map & (1 << (WINED3D_FFP_TEXCOORD0 + tex_index)))) { ERR("No source texture, but destination requests one\n"); @@ -3533,12 +3521,14 @@ static HRESULT process_vertices_strided(struct wined3d_device *device, DWORD dwD /* Do not call while under the GL lock. */ HRESULT CDECL wined3d_device_process_vertices(struct wined3d_device *device, UINT src_start_idx, UINT dst_idx, UINT vertex_count, struct wined3d_buffer *dst_buffer, - struct wined3d_vertex_declaration *declaration, DWORD flags, DWORD dst_fvf) + const struct wined3d_vertex_declaration *declaration, DWORD flags, DWORD dst_fvf) { - BOOL vbo = FALSE, streamWasUP = device->stateBlock->state.user_stream; + struct wined3d_state *state = &device->stateBlock->state; + BOOL vbo = FALSE, streamWasUP = state->user_stream; struct wined3d_stream_info stream_info; const struct wined3d_gl_info *gl_info; struct wined3d_context *context; + struct wined3d_shader *vs; HRESULT hr; TRACE("device %p, src_start_idx %u, dst_idx %u, vertex_count %u, " @@ -3553,12 +3543,15 @@ HRESULT CDECL wined3d_device_process_vertices(struct wined3d_device *device, context = context_acquire(device, NULL); gl_info = context->gl_info; - /* ProcessVertices reads from vertex buffers, which have to be assigned. DrawPrimitive and DrawPrimitiveUP - * control the streamIsUP flag, thus restore it afterwards. - */ - device->stateBlock->state.user_stream = FALSE; - device_stream_info_from_declaration(device, FALSE, &stream_info, &vbo); - device->stateBlock->state.user_stream = streamWasUP; + /* ProcessVertices reads from vertex buffers, which have to be assigned. + * DrawPrimitive and DrawPrimitiveUP control the streamIsUP flag, thus + * restore it afterwards. */ + vs = state->vertex_shader; + state->vertex_shader = NULL; + state->user_stream = FALSE; + device_stream_info_from_declaration(device, &stream_info, &vbo); + state->user_stream = streamWasUP; + state->vertex_shader = vs; if (vbo || src_start_idx) { @@ -3575,18 +3568,18 @@ HRESULT CDECL wined3d_device_process_vertices(struct wined3d_device *device, if (!(stream_info.use_map & (1 << i))) continue; e = &stream_info.elements[i]; - if (e->buffer_object) + if (e->data.buffer_object) { - struct wined3d_buffer *vb = device->stateBlock->state.streams[e->stream_idx].buffer; - e->buffer_object = 0; - e->data = (BYTE *)((ULONG_PTR)e->data + (ULONG_PTR)buffer_get_sysmem(vb, gl_info)); + struct wined3d_buffer *vb = state->streams[e->stream_idx].buffer; + e->data.buffer_object = 0; + e->data.addr = (BYTE *)((ULONG_PTR)e->data.addr + (ULONG_PTR)buffer_get_sysmem(vb, gl_info)); ENTER_GL(); GL_EXTCALL(glDeleteBuffersARB(1, &vb->buffer_object)); vb->buffer_object = 0; LEAVE_GL(); } - if (e->data) - e->data += e->stride * src_start_idx; + if (e->data.addr) + e->data.addr += e->stride * src_start_idx; } } @@ -3599,7 +3592,7 @@ HRESULT CDECL wined3d_device_process_vertices(struct wined3d_device *device, } HRESULT CDECL wined3d_device_set_texture_stage_state(struct wined3d_device *device, - UINT stage, WINED3DTEXTURESTAGESTATETYPE state, DWORD value) + UINT stage, enum wined3d_texture_stage_state state, DWORD value) { const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; DWORD old_value; @@ -3639,7 +3632,7 @@ HRESULT CDECL wined3d_device_set_texture_stage_state(struct wined3d_device *devi if (stage > device->stateBlock->state.lowest_disabled_stage && device->StateTable[STATE_TEXTURESTAGE(0, state)].representative - == STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP)) + == STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP)) { /* Colorop change above lowest disabled stage? That won't change * anything in the GL setup. Changes in other states are important on @@ -3647,11 +3640,11 @@ HRESULT CDECL wined3d_device_set_texture_stage_state(struct wined3d_device *devi return WINED3D_OK; } - if (state == WINED3DTSS_COLOROP) + if (state == WINED3D_TSS_COLOR_OP) { unsigned int i; - if (value == WINED3DTOP_DISABLE && old_value != WINED3DTOP_DISABLE) + if (value == WINED3D_TOP_DISABLE && old_value != WINED3D_TOP_DISABLE) { /* Previously enabled stage disabled now. Make sure to dirtify * all enabled stages above stage, they have to be disabled. @@ -3660,12 +3653,12 @@ HRESULT CDECL wined3d_device_set_texture_stage_state(struct wined3d_device *devi for (i = stage + 1; i < device->stateBlock->state.lowest_disabled_stage; ++i) { TRACE("Additionally dirtifying stage %u.\n", i); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_TEXTURESTAGE(i, WINED3DTSS_COLOROP)); + device_invalidate_state(device, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP)); } device->stateBlock->state.lowest_disabled_stage = stage; TRACE("New lowest disabled: %u.\n", stage); } - else if (value != WINED3DTOP_DISABLE && old_value == WINED3DTOP_DISABLE) + else if (value != WINED3D_TOP_DISABLE && old_value == WINED3D_TOP_DISABLE) { /* Previously disabled stage enabled. Stages above it may need * enabling. Stage must be lowest_disabled_stage here, if it's @@ -3677,23 +3670,23 @@ HRESULT CDECL wined3d_device_set_texture_stage_state(struct wined3d_device *devi * handled below. */ for (i = stage + 1; i < gl_info->limits.texture_stages; ++i) { - if (device->updateStateBlock->state.texture_states[i][WINED3DTSS_COLOROP] == WINED3DTOP_DISABLE) + if (device->updateStateBlock->state.texture_states[i][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_DISABLE) break; TRACE("Additionally dirtifying stage %u due to enable.\n", i); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_TEXTURESTAGE(i, WINED3DTSS_COLOROP)); + device_invalidate_state(device, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP)); } device->stateBlock->state.lowest_disabled_stage = i; TRACE("New lowest disabled: %u.\n", i); } } - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_TEXTURESTAGE(stage, state)); + device_invalidate_state(device, STATE_TEXTURESTAGE(stage, state)); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_texture_stage_state(struct wined3d_device *device, - UINT stage, WINED3DTEXTURESTAGESTATETYPE state, DWORD *value) +HRESULT CDECL wined3d_device_get_texture_stage_state(const struct wined3d_device *device, + UINT stage, enum wined3d_texture_stage_state state, DWORD *value) { TRACE("device %p, stage %u, state %s, value %p.\n", device, stage, debug_d3dtexturestate(state), value); @@ -3728,8 +3721,7 @@ HRESULT CDECL wined3d_device_set_texture(struct wined3d_device *device, return WINED3D_OK; } - /* SetTexture isn't allowed on textures in WINED3DPOOL_SCRATCH */ - if (texture && texture->resource.pool == WINED3DPOOL_SCRATCH) + if (texture && texture->resource.pool == WINED3D_POOL_SCRATCH) { WARN("Rejecting attempt to set scratch texture.\n"); return WINED3DERR_INVALIDCALL; @@ -3766,15 +3758,15 @@ HRESULT CDECL wined3d_device_set_texture(struct wined3d_device *device, wined3d_texture_incref(texture); if (!prev || texture->target != prev->target) - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_PIXELSHADER); + device_invalidate_state(device, STATE_PIXELSHADER); if (!prev && stage < gl_info->limits.texture_stages) { /* The source arguments for color and alpha ops have different - * meanings when a NULL texture is bound, so the COLOROP and - * ALPHAOP have to be dirtified. */ - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_TEXTURESTAGE(stage, WINED3DTSS_COLOROP)); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_TEXTURESTAGE(stage, WINED3DTSS_ALPHAOP)); + * meanings when a NULL texture is bound, so the COLOR_OP and + * ALPHA_OP have to be dirtified. */ + device_invalidate_state(device, STATE_TEXTURESTAGE(stage, WINED3D_TSS_COLOR_OP)); + device_invalidate_state(device, STATE_TEXTURESTAGE(stage, WINED3D_TSS_ALPHA_OP)); } if (bind_count == 1) @@ -3789,8 +3781,8 @@ HRESULT CDECL wined3d_device_set_texture(struct wined3d_device *device, if (!texture && stage < gl_info->limits.texture_stages) { - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_TEXTURESTAGE(stage, WINED3DTSS_COLOROP)); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_TEXTURESTAGE(stage, WINED3DTSS_ALPHAOP)); + device_invalidate_state(device, STATE_TEXTURESTAGE(stage, WINED3D_TSS_COLOR_OP)); + device_invalidate_state(device, STATE_TEXTURESTAGE(stage, WINED3D_TSS_ALPHA_OP)); } if (bind_count && prev->sampler == stage) @@ -3812,12 +3804,12 @@ HRESULT CDECL wined3d_device_set_texture(struct wined3d_device *device, } } - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(stage)); + device_invalidate_state(device, STATE_SAMPLER(stage)); return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_texture(struct wined3d_device *device, +HRESULT CDECL wined3d_device_get_texture(const struct wined3d_device *device, UINT stage, struct wined3d_texture **texture) { TRACE("device %p, stage %u, texture %p.\n", device, stage, texture); @@ -3840,8 +3832,8 @@ HRESULT CDECL wined3d_device_get_texture(struct wined3d_device *device, return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_back_buffer(struct wined3d_device *device, UINT swapchain_idx, - UINT backbuffer_idx, WINED3DBACKBUFFER_TYPE backbuffer_type, struct wined3d_surface **backbuffer) +HRESULT CDECL wined3d_device_get_back_buffer(const struct wined3d_device *device, UINT swapchain_idx, + UINT backbuffer_idx, enum wined3d_backbuffer_type backbuffer_type, struct wined3d_surface **backbuffer) { struct wined3d_swapchain *swapchain; HRESULT hr; @@ -3867,15 +3859,16 @@ HRESULT CDECL wined3d_device_get_back_buffer(struct wined3d_device *device, UINT return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_device_caps(struct wined3d_device *device, WINED3DCAPS *caps) +HRESULT CDECL wined3d_device_get_device_caps(const struct wined3d_device *device, WINED3DCAPS *caps) { TRACE("device %p, caps %p.\n", device, caps); - return wined3d_get_device_caps(device->wined3d, device->adapter->ordinal, device->devType, caps); + return wined3d_get_device_caps(device->wined3d, device->adapter->ordinal, + device->create_parms.device_type, caps); } -HRESULT CDECL wined3d_device_get_display_mode(struct wined3d_device *device, - UINT swapchain_idx, WINED3DDISPLAYMODE *mode) +HRESULT CDECL wined3d_device_get_display_mode(const struct wined3d_device *device, + UINT swapchain_idx, struct wined3d_display_mode *mode) { struct wined3d_swapchain *swapchain; HRESULT hr; @@ -3893,6 +3886,8 @@ HRESULT CDECL wined3d_device_get_display_mode(struct wined3d_device *device, } else { + const struct wined3d_adapter *adapter = device->adapter; + /* Don't read the real display mode, but return the stored mode * instead. X11 can't change the color depth, and some apps are * pretty angry if they SetDisplayMode from 24 to 16 bpp and find out @@ -3900,10 +3895,10 @@ HRESULT CDECL wined3d_device_get_display_mode(struct wined3d_device *device, * * Also don't relay to the swapchain because with ddraw it's possible * that there isn't a swapchain at all. */ - mode->Width = device->ddraw_width; - mode->Height = device->ddraw_height; - mode->Format = device->ddraw_format; - mode->RefreshRate = 0; + mode->width = adapter->screen_size.cx; + mode->height = adapter->screen_size.cy; + mode->format_id = adapter->screen_format; + mode->refresh_rate = 0; hr = WINED3D_OK; } @@ -3920,7 +3915,7 @@ HRESULT CDECL wined3d_device_begin_stateblock(struct wined3d_device *device) if (device->isRecordingState) return WINED3DERR_INVALIDCALL; - hr = wined3d_stateblock_create(device, WINED3DSBT_RECORDED, &stateblock); + hr = wined3d_stateblock_create(device, WINED3D_SBT_RECORDED, &stateblock); if (FAILED(hr)) return hr; @@ -3997,7 +3992,7 @@ HRESULT CDECL wined3d_device_end_scene(struct wined3d_device *device) return WINED3D_OK; } -HRESULT CDECL wined3d_device_present(struct wined3d_device *device, const RECT *src_rect, +HRESULT CDECL wined3d_device_present(const struct wined3d_device *device, const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override, const RGNDATA *dirty_region) { UINT i; @@ -4017,13 +4012,12 @@ HRESULT CDECL wined3d_device_present(struct wined3d_device *device, const RECT * /* Do not call while under the GL lock. */ HRESULT CDECL wined3d_device_clear(struct wined3d_device *device, DWORD rect_count, - const RECT *rects, DWORD flags, WINED3DCOLOR color, float depth, DWORD stencil) + const RECT *rects, DWORD flags, const struct wined3d_color *color, float depth, DWORD stencil) { - const WINED3DCOLORVALUE c = {D3DCOLOR_R(color), D3DCOLOR_G(color), D3DCOLOR_B(color), D3DCOLOR_A(color)}; RECT draw_rect; - TRACE("device %p, rect_count %u, rects %p, flags %#x, color 0x%08x, depth %.8e, stencil %u.\n", - device, rect_count, rects, flags, color, depth, stencil); + TRACE("device %p, rect_count %u, rects %p, flags %#x, color {%.8e, %.8e, %.8e, %.8e}, depth %.8e, stencil %u.\n", + device, rect_count, rects, flags, color->r, color->g, color->b, color->a, depth, stencil); if (flags & (WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL)) { @@ -4045,15 +4039,15 @@ HRESULT CDECL wined3d_device_clear(struct wined3d_device *device, DWORD rect_cou } } - device_get_draw_rect(device, &draw_rect); + wined3d_get_draw_rect(&device->stateBlock->state, &draw_rect); return device_clear_render_targets(device, device->adapter->gl_info.limits.buffers, - device->fb.render_targets, device->fb.depth_stencil, rect_count, rects, - &draw_rect, flags, &c, depth, stencil); + &device->fb, rect_count, rects, + &draw_rect, flags, color, depth, stencil); } void CDECL wined3d_device_set_primitive_type(struct wined3d_device *device, - WINED3DPRIMITIVETYPE primitive_type) + enum wined3d_primitive_type primitive_type) { TRACE("device %p, primitive_type %s\n", device, debug_d3dprimitivetype(primitive_type)); @@ -4061,8 +4055,8 @@ void CDECL wined3d_device_set_primitive_type(struct wined3d_device *device, device->updateStateBlock->state.gl_primitive_type = gl_primitive_type_from_d3d(primitive_type); } -void CDECL wined3d_device_get_primitive_type(struct wined3d_device *device, - WINED3DPRIMITIVETYPE *primitive_type) +void CDECL wined3d_device_get_primitive_type(const struct wined3d_device *device, + enum wined3d_primitive_type *primitive_type) { TRACE("device %p, primitive_type %p\n", device, primitive_type); @@ -4084,14 +4078,14 @@ HRESULT CDECL wined3d_device_draw_primitive(struct wined3d_device *device, UINT /* The index buffer is not needed here, but restore it, otherwise it is hell to keep track of */ if (device->stateBlock->state.user_stream) { - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_INDEXBUFFER); + device_invalidate_state(device, STATE_INDEXBUFFER); device->stateBlock->state.user_stream = FALSE; } if (device->stateBlock->state.load_base_vertex_index) { device->stateBlock->state.load_base_vertex_index = 0; - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_STREAMSRC); + device_invalidate_state(device, STATE_BASEVERTEXINDEX); } /* Account for the loading offset due to index buffers. Instead of @@ -4105,6 +4099,7 @@ HRESULT CDECL wined3d_device_draw_indexed_primitive(struct wined3d_device *devic struct wined3d_buffer *index_buffer; UINT index_size = 2; GLuint vbo; + const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; TRACE("device %p, start_idx %u, index_count %u.\n", device, start_idx, index_count); @@ -4127,7 +4122,7 @@ HRESULT CDECL wined3d_device_draw_indexed_primitive(struct wined3d_device *devic if (device->stateBlock->state.user_stream) { - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_INDEXBUFFER); + device_invalidate_state(device, STATE_INDEXBUFFER); device->stateBlock->state.user_stream = FALSE; } vbo = index_buffer->buffer_object; @@ -4137,10 +4132,11 @@ HRESULT CDECL wined3d_device_draw_indexed_primitive(struct wined3d_device *devic else index_size = 4; - if (device->stateBlock->state.load_base_vertex_index != device->stateBlock->state.base_vertex_index) + if (!gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX] && + device->stateBlock->state.load_base_vertex_index != device->stateBlock->state.base_vertex_index) { device->stateBlock->state.load_base_vertex_index = device->stateBlock->state.base_vertex_index; - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_STREAMSRC); + device_invalidate_state(device, STATE_BASEVERTEXINDEX); } drawPrimitive(device, index_count, start_idx, index_size, @@ -4173,10 +4169,14 @@ HRESULT CDECL wined3d_device_draw_primitive_up(struct wined3d_device *device, UI stream->offset = 0; stream->stride = stream_stride; device->stateBlock->state.user_stream = TRUE; - device->stateBlock->state.load_base_vertex_index = 0; + if (device->stateBlock->state.load_base_vertex_index) + { + device->stateBlock->state.load_base_vertex_index = 0; + device_invalidate_state(device, STATE_BASEVERTEXINDEX); + } /* TODO: Only mark dirty if drawing from a different UP address */ - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_STREAMSRC); + device_invalidate_state(device, STATE_STREAMSRC); drawPrimitive(device, vertex_count, 0, 0, NULL); @@ -4223,10 +4223,14 @@ HRESULT CDECL wined3d_device_draw_indexed_primitive_up(struct wined3d_device *de /* Set to 0 as per msdn. Do it now due to the stream source loading during drawPrimitive */ device->stateBlock->state.base_vertex_index = 0; - device->stateBlock->state.load_base_vertex_index = 0; - /* Mark the state dirty until we have nicer tracking of the stream source pointers */ - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_VDECL); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_INDEXBUFFER); + if (device->stateBlock->state.load_base_vertex_index) + { + device->stateBlock->state.load_base_vertex_index = 0; + device_invalidate_state(device, STATE_BASEVERTEXINDEX); + } + /* Invalidate the state until we have nicer tracking of the stream source pointers */ + device_invalidate_state(device, STATE_STREAMSRC); + device_invalidate_state(device, STATE_INDEXBUFFER); drawPrimitive(device, index_count, 0, index_size, index_data); @@ -4247,22 +4251,32 @@ HRESULT CDECL wined3d_device_draw_indexed_primitive_up(struct wined3d_device *de } HRESULT CDECL wined3d_device_draw_primitive_strided(struct wined3d_device *device, - UINT vertex_count, const WineDirect3DVertexStridedData *strided_data) + UINT vertex_count, const struct wined3d_strided_data *strided_data) { /* Mark the state dirty until we have nicer tracking. It's fine to change * baseVertexIndex because that call is only called by ddraw which does * not need that value. */ - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_VDECL); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_INDEXBUFFER); + device_invalidate_state(device, STATE_VDECL); + device_invalidate_state(device, STATE_STREAMSRC); + device_invalidate_state(device, STATE_INDEXBUFFER); + device->stateBlock->state.base_vertex_index = 0; device->up_strided = strided_data; drawPrimitive(device, vertex_count, 0, 0, NULL); device->up_strided = NULL; + + /* Invalidate the states again to make sure the values from the stateblock + * are properly applied in the next regular draw. Note that the application- + * provided strided data has ovwritten pretty much the entire vertex and + * and index stream related states */ + device_invalidate_state(device, STATE_VDECL); + device_invalidate_state(device, STATE_STREAMSRC); + device_invalidate_state(device, STATE_INDEXBUFFER); return WINED3D_OK; } HRESULT CDECL wined3d_device_draw_indexed_primitive_strided(struct wined3d_device *device, - UINT index_count, const WineDirect3DVertexStridedData *strided_data, + UINT index_count, const struct wined3d_strided_data *strided_data, UINT vertex_count, const void *index_data, enum wined3d_format_id index_data_format_id) { UINT index_size = index_data_format_id == WINED3DFMT_R32_UINT ? 4 : 2; @@ -4271,22 +4285,28 @@ HRESULT CDECL wined3d_device_draw_indexed_primitive_strided(struct wined3d_devic * its fine to change baseVertexIndex because that call is only called by ddraw which does not need * that value. */ - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_VDECL); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_INDEXBUFFER); + device_invalidate_state(device, STATE_VDECL); + device_invalidate_state(device, STATE_STREAMSRC); + device_invalidate_state(device, STATE_INDEXBUFFER); + device->stateBlock->state.user_stream = TRUE; device->stateBlock->state.base_vertex_index = 0; device->up_strided = strided_data; drawPrimitive(device, index_count, 0, index_size, index_data); device->up_strided = NULL; + + device_invalidate_state(device, STATE_VDECL); + device_invalidate_state(device, STATE_STREAMSRC); + device_invalidate_state(device, STATE_INDEXBUFFER); return WINED3D_OK; } /* This is a helper function for UpdateTexture, there is no UpdateVolume method in D3D. */ -static HRESULT IWineD3DDeviceImpl_UpdateVolume(struct wined3d_device *device, +static HRESULT device_update_volume(struct wined3d_device *device, struct wined3d_volume *src_volume, struct wined3d_volume *dst_volume) { - WINED3DLOCKED_BOX src; - WINED3DLOCKED_BOX dst; + struct wined3d_mapped_box src; + struct wined3d_mapped_box dst; HRESULT hr; TRACE("device %p, src_volume %p, dst_volume %p.\n", @@ -4303,7 +4323,7 @@ static HRESULT IWineD3DDeviceImpl_UpdateVolume(struct wined3d_device *device, return hr; } - memcpy(dst.pBits, src.pBits, dst_volume->resource.size); + memcpy(dst.data, src.data, dst_volume->resource.size); hr = wined3d_volume_unmap(dst_volume); if (FAILED(hr)) @@ -4317,8 +4337,8 @@ static HRESULT IWineD3DDeviceImpl_UpdateVolume(struct wined3d_device *device, HRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device, struct wined3d_texture *src_texture, struct wined3d_texture *dst_texture) { + enum wined3d_resource_type type; unsigned int level_count, i; - WINED3DRESOURCETYPE type; HRESULT hr; TRACE("device %p, src_texture %p, dst_texture %p.\n", device, src_texture, dst_texture); @@ -4337,8 +4357,8 @@ HRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device, } /* Verify that the source and destination textures are the same type. */ - type = wined3d_texture_get_type(src_texture); - if (wined3d_texture_get_type(dst_texture) != type) + type = src_texture->resource.type; + if (dst_texture->resource.type != type) { WARN("Source and destination have different types, returning WINED3DERR_INVALIDCALL.\n"); return WINED3DERR_INVALIDCALL; @@ -4358,7 +4378,7 @@ HRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device, /* Update every surface level of the texture. */ switch (type) { - case WINED3DRTYPE_TEXTURE: + case WINED3D_RTYPE_TEXTURE: { struct wined3d_surface *src_surface; struct wined3d_surface *dst_surface; @@ -4370,14 +4390,14 @@ HRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device, hr = wined3d_device_update_surface(device, src_surface, NULL, dst_surface, NULL); if (FAILED(hr)) { - WARN("IWineD3DDevice_UpdateSurface failed, hr %#x.\n", hr); + WARN("Failed to update surface, hr %#x.\n", hr); return hr; } } break; } - case WINED3DRTYPE_CUBETEXTURE: + case WINED3D_RTYPE_CUBE_TEXTURE: { struct wined3d_surface *src_surface; struct wined3d_surface *dst_surface; @@ -4389,23 +4409,23 @@ HRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device, hr = wined3d_device_update_surface(device, src_surface, NULL, dst_surface, NULL); if (FAILED(hr)) { - WARN("IWineD3DDevice_UpdateSurface failed, hr %#x.\n", hr); + WARN("Failed to update surface, hr %#x.\n", hr); return hr; } } break; } - case WINED3DRTYPE_VOLUMETEXTURE: + case WINED3D_RTYPE_VOLUME_TEXTURE: { for (i = 0; i < level_count; ++i) { - hr = IWineD3DDeviceImpl_UpdateVolume(device, + hr = device_update_volume(device, volume_from_resource(wined3d_texture_get_sub_resource(src_texture, i)), volume_from_resource(wined3d_texture_get_sub_resource(dst_texture, i))); if (FAILED(hr)) { - WARN("IWineD3DDeviceImpl_UpdateVolume failed, hr %#x.\n", hr); + WARN("Failed to update volume, hr %#x.\n", hr); return hr; } } @@ -4420,7 +4440,7 @@ HRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device, return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_front_buffer_data(struct wined3d_device *device, +HRESULT CDECL wined3d_device_get_front_buffer_data(const struct wined3d_device *device, UINT swapchain_idx, struct wined3d_surface *dst_surface) { struct wined3d_swapchain *swapchain; @@ -4437,7 +4457,7 @@ HRESULT CDECL wined3d_device_get_front_buffer_data(struct wined3d_device *device return hr; } -HRESULT CDECL wined3d_device_validate_device(struct wined3d_device *device, DWORD *num_passes) +HRESULT CDECL wined3d_device_validate_device(const struct wined3d_device *device, DWORD *num_passes) { const struct wined3d_state *state = &device->stateBlock->state; struct wined3d_texture *texture; @@ -4447,12 +4467,12 @@ HRESULT CDECL wined3d_device_validate_device(struct wined3d_device *device, DWOR for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) { - if (state->sampler_states[i][WINED3DSAMP_MINFILTER] == WINED3DTEXF_NONE) + if (state->sampler_states[i][WINED3D_SAMP_MIN_FILTER] == WINED3D_TEXF_NONE) { WARN("Sampler state %u has minfilter D3DTEXF_NONE, returning D3DERR_UNSUPPORTEDTEXTUREFILTER\n", i); return WINED3DERR_UNSUPPORTEDTEXTUREFILTER; } - if (state->sampler_states[i][WINED3DSAMP_MAGFILTER] == WINED3DTEXF_NONE) + if (state->sampler_states[i][WINED3D_SAMP_MAG_FILTER] == WINED3D_TEXF_NONE) { WARN("Sampler state %u has magfilter D3DTEXF_NONE, returning D3DERR_UNSUPPORTEDTEXTUREFILTER\n", i); return WINED3DERR_UNSUPPORTEDTEXTUREFILTER; @@ -4461,26 +4481,26 @@ HRESULT CDECL wined3d_device_validate_device(struct wined3d_device *device, DWOR texture = state->textures[i]; if (!texture || texture->resource.format->flags & WINED3DFMT_FLAG_FILTERING) continue; - if (state->sampler_states[i][WINED3DSAMP_MAGFILTER] != WINED3DTEXF_POINT) + if (state->sampler_states[i][WINED3D_SAMP_MAG_FILTER] != WINED3D_TEXF_POINT) { WARN("Non-filterable texture and mag filter enabled on samper %u, returning E_FAIL\n", i); return E_FAIL; } - if (state->sampler_states[i][WINED3DSAMP_MINFILTER] != WINED3DTEXF_POINT) + if (state->sampler_states[i][WINED3D_SAMP_MIN_FILTER] != WINED3D_TEXF_POINT) { WARN("Non-filterable texture and min filter enabled on samper %u, returning E_FAIL\n", i); return E_FAIL; } - if (state->sampler_states[i][WINED3DSAMP_MIPFILTER] != WINED3DTEXF_NONE - && state->sampler_states[i][WINED3DSAMP_MIPFILTER] != WINED3DTEXF_POINT) + if (state->sampler_states[i][WINED3D_SAMP_MIP_FILTER] != WINED3D_TEXF_NONE + && state->sampler_states[i][WINED3D_SAMP_MIP_FILTER] != WINED3D_TEXF_POINT) { WARN("Non-filterable texture and mip filter enabled on samper %u, returning E_FAIL\n", i); return E_FAIL; } } - if (state->render_states[WINED3DRS_ZENABLE] || state->render_states[WINED3DRS_ZWRITEENABLE] || - state->render_states[WINED3DRS_STENCILENABLE]) + if (state->render_states[WINED3D_RS_ZENABLE] || state->render_states[WINED3D_RS_ZWRITEENABLE] + || state->render_states[WINED3D_RS_STENCILENABLE]) { struct wined3d_surface *ds = device->fb.depth_stencil; struct wined3d_surface *target = device->fb.render_targets[0]; @@ -4500,137 +4520,6 @@ HRESULT CDECL wined3d_device_validate_device(struct wined3d_device *device, DWOR return WINED3D_OK; } -static void dirtify_p8_texture_samplers(struct wined3d_device *device) -{ - UINT i; - - for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) - { - struct wined3d_texture *texture = device->stateBlock->state.textures[i]; - if (texture && (texture->resource.format->id == WINED3DFMT_P8_UINT - || texture->resource.format->id == WINED3DFMT_P8_UINT_A8_UNORM)) - { - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(i)); - } - } -} - -HRESULT CDECL wined3d_device_set_palette_entries(struct wined3d_device *device, - UINT palette_idx, const PALETTEENTRY *entries) -{ - UINT i; - - TRACE("device %p, palette_idx %u, entries %p.\n", device, palette_idx, entries); - - if (palette_idx >= MAX_PALETTES) - { - WARN("Invalid palette index %u.\n", palette_idx); - return WINED3DERR_INVALIDCALL; - } - - if (palette_idx >= device->palette_count) - { - UINT new_size = device->palette_count; - PALETTEENTRY **palettes; - - do - { - new_size *= 2; - } while (palette_idx >= new_size); - palettes = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, device->palettes, sizeof(*palettes) * new_size); - if (!palettes) - { - ERR("Out of memory!\n"); - return E_OUTOFMEMORY; - } - device->palettes = palettes; - device->palette_count = new_size; - } - - if (!device->palettes[palette_idx]) - { - device->palettes[palette_idx] = HeapAlloc(GetProcessHeap(), 0, sizeof(PALETTEENTRY) * 256); - if (!device->palettes[palette_idx]) - { - ERR("Out of memory!\n"); - return E_OUTOFMEMORY; - } - } - - for (i = 0; i < 256; ++i) - { - device->palettes[palette_idx][i].peRed = entries[i].peRed; - device->palettes[palette_idx][i].peGreen = entries[i].peGreen; - device->palettes[palette_idx][i].peBlue = entries[i].peBlue; - device->palettes[palette_idx][i].peFlags = entries[i].peFlags; - } - - if (palette_idx == device->currentPalette) - dirtify_p8_texture_samplers(device); - - return WINED3D_OK; -} - -HRESULT CDECL wined3d_device_get_palette_entries(struct wined3d_device *device, - UINT palette_idx, PALETTEENTRY *entries) -{ - UINT i; - - TRACE("device %p, palette_idx %u, entries %p.\n", device, palette_idx, entries); - - if (palette_idx >= device->palette_count || !device->palettes[palette_idx]) - { - /* What happens in such situation isn't documented; Native seems to - * silently abort on such conditions. */ - WARN("Invalid palette index %u.\n", palette_idx); - return WINED3DERR_INVALIDCALL; - } - - for (i = 0; i < 256; ++i) - { - entries[i].peRed = device->palettes[palette_idx][i].peRed; - entries[i].peGreen = device->palettes[palette_idx][i].peGreen; - entries[i].peBlue = device->palettes[palette_idx][i].peBlue; - entries[i].peFlags = device->palettes[palette_idx][i].peFlags; - } - - return WINED3D_OK; -} - -HRESULT CDECL wined3d_device_set_current_texture_palette(struct wined3d_device *device, UINT palette_idx) -{ - TRACE("device %p, palette_idx %u.\n", device, palette_idx); - - /* Native appears to silently abort on attempt to make an uninitialized - * palette current and render. (tested with reference rasterizer). */ - if (palette_idx >= device->palette_count || !device->palettes[palette_idx]) - { - WARN("Invalid palette index %u.\n", palette_idx); - return WINED3DERR_INVALIDCALL; - } - - /* TODO: stateblocks? */ - if (device->currentPalette != palette_idx) - { - device->currentPalette = palette_idx; - dirtify_p8_texture_samplers(device); - } - - return WINED3D_OK; -} - -HRESULT CDECL wined3d_device_get_current_texture_palette(struct wined3d_device *device, UINT *palette_idx) -{ - TRACE("device %p, palette_idx %p.\n", device, palette_idx); - - if (!palette_idx) - return WINED3DERR_INVALIDCALL; - - *palette_idx = device->currentPalette; - - return WINED3D_OK; -} - HRESULT CDECL wined3d_device_set_software_vertex_processing(struct wined3d_device *device, BOOL software) { static BOOL warned; @@ -4648,7 +4537,7 @@ HRESULT CDECL wined3d_device_set_software_vertex_processing(struct wined3d_devic return WINED3D_OK; } -BOOL CDECL wined3d_device_get_software_vertex_processing(struct wined3d_device *device) +BOOL CDECL wined3d_device_get_software_vertex_processing(const struct wined3d_device *device) { static BOOL warned; @@ -4663,8 +4552,8 @@ BOOL CDECL wined3d_device_get_software_vertex_processing(struct wined3d_device * return device->softwareVertexProcessing; } -HRESULT CDECL wined3d_device_get_raster_status(struct wined3d_device *device, - UINT swapchain_idx, WINED3DRASTER_STATUS *raster_status) +HRESULT CDECL wined3d_device_get_raster_status(const struct wined3d_device *device, + UINT swapchain_idx, struct wined3d_raster_status *raster_status) { struct wined3d_swapchain *swapchain; HRESULT hr; @@ -4708,7 +4597,7 @@ HRESULT CDECL wined3d_device_set_npatch_mode(struct wined3d_device *device, floa return WINED3D_OK; } -float CDECL wined3d_device_get_npatch_mode(struct wined3d_device *device) +float CDECL wined3d_device_get_npatch_mode(const struct wined3d_device *device) { static BOOL warned; @@ -4727,142 +4616,22 @@ HRESULT CDECL wined3d_device_update_surface(struct wined3d_device *device, struct wined3d_surface *src_surface, const RECT *src_rect, struct wined3d_surface *dst_surface, const POINT *dst_point) { - const struct wined3d_format *src_format; - const struct wined3d_format *dst_format; - const struct wined3d_gl_info *gl_info; - struct wined3d_context *context; - const unsigned char *data; - UINT update_w, update_h; - CONVERT_TYPES convert; - UINT src_w, src_h; - UINT dst_x, dst_y; - DWORD sampler; - struct wined3d_format format; - TRACE("device %p, src_surface %p, src_rect %s, dst_surface %p, dst_point %s.\n", device, src_surface, wine_dbgstr_rect(src_rect), dst_surface, wine_dbgstr_point(dst_point)); - if (src_surface->resource.pool != WINED3DPOOL_SYSTEMMEM || dst_surface->resource.pool != WINED3DPOOL_DEFAULT) + if (src_surface->resource.pool != WINED3D_POOL_SYSTEM_MEM || dst_surface->resource.pool != WINED3D_POOL_DEFAULT) { WARN("source %p must be SYSTEMMEM and dest %p must be DEFAULT, returning WINED3DERR_INVALIDCALL\n", src_surface, dst_surface); return WINED3DERR_INVALIDCALL; } - src_format = src_surface->resource.format; - dst_format = dst_surface->resource.format; - - if (src_format->id != dst_format->id) - { - WARN("Source and destination surfaces should have the same format.\n"); - return WINED3DERR_INVALIDCALL; - } - - dst_x = dst_point ? dst_point->x : 0; - dst_y = dst_point ? dst_point->y : 0; - - /* This call loads the OpenGL surface directly, instead of copying the - * surface to the destination's sysmem copy. If surface conversion is - * needed, use BltFast instead to copy in sysmem and use regular surface - * loading. */ - d3dfmt_get_conv(dst_surface, FALSE, TRUE, &format, &convert); - if (convert != NO_CONVERSION || format.convert) - return wined3d_surface_bltfast(dst_surface, dst_x, dst_y, src_surface, src_rect, 0); - - context = context_acquire(device, NULL); - gl_info = context->gl_info; - - ENTER_GL(); - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB)); - checkGLcall("glActiveTextureARB"); - LEAVE_GL(); - - /* Make sure the surface is loaded and up to date */ - surface_internal_preload(dst_surface, SRGB_RGB); - surface_bind(dst_surface, gl_info, FALSE); - - src_w = src_surface->resource.width; - src_h = src_surface->resource.height; - update_w = src_rect ? src_rect->right - src_rect->left : src_w; - update_h = src_rect ? src_rect->bottom - src_rect->top : src_h; - - data = src_surface->resource.allocatedMemory; - if (!data) ERR("Source surface has no allocated memory, but should be a sysmem surface.\n"); - - ENTER_GL(); - - if (dst_format->flags & WINED3DFMT_FLAG_COMPRESSED) - { - UINT row_length = wined3d_format_calculate_size(src_format, 1, update_w, 1); - UINT row_count = (update_h + src_format->block_height - 1) / src_format->block_height; - UINT src_pitch = wined3d_format_calculate_size(src_format, 1, src_w, 1); - - if (src_rect) - { - data += (src_rect->top / src_format->block_height) * src_pitch; - data += (src_rect->left / src_format->block_width) * src_format->block_byte_count; - } - - TRACE("glCompressedTexSubImage2DARB, target %#x, level %d, x %d, y %d, w %d, h %d, " - "format %#x, image_size %#x, data %p.\n", dst_surface->texture_target, dst_surface->texture_level, - dst_x, dst_y, update_w, update_h, dst_format->glFormat, row_count * row_length, data); - - if (row_length == src_pitch) - { - GL_EXTCALL(glCompressedTexSubImage2DARB(dst_surface->texture_target, dst_surface->texture_level, - dst_x, dst_y, update_w, update_h, dst_format->glInternal, row_count * row_length, data)); - } - else - { - UINT row, y; - - /* glCompressedTexSubImage2DARB() ignores pixel store state, so we - * can't use the unpack row length like below. */ - for (row = 0, y = dst_y; row < row_count; ++row) - { - GL_EXTCALL(glCompressedTexSubImage2DARB(dst_surface->texture_target, dst_surface->texture_level, - dst_x, y, update_w, src_format->block_height, dst_format->glInternal, row_length, data)); - y += src_format->block_height; - data += src_pitch; - } - } - checkGLcall("glCompressedTexSubImage2DARB"); - } - else - { - if (src_rect) - { - data += src_rect->top * src_w * src_format->byte_count; - data += src_rect->left * src_format->byte_count; - } - - TRACE("glTexSubImage2D, target %#x, level %d, x %d, y %d, w %d, h %d, format %#x, type %#x, data %p.\n", - dst_surface->texture_target, dst_surface->texture_level, dst_x, dst_y, - update_w, update_h, dst_format->glFormat, dst_format->glType, data); - - glPixelStorei(GL_UNPACK_ROW_LENGTH, src_w); - glTexSubImage2D(dst_surface->texture_target, dst_surface->texture_level, dst_x, dst_y, - update_w, update_h, dst_format->glFormat, dst_format->glType, data); - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - checkGLcall("glTexSubImage2D"); - } - - LEAVE_GL(); - context_release(context); - - surface_modify_location(dst_surface, SFLAG_INTEXTURE, TRUE); - sampler = device->rev_tex_unit_map[0]; - if (sampler != WINED3D_UNMAPPED_STAGE) - { - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(sampler)); - } - - return WINED3D_OK; + return surface_upload_from_surface(dst_surface, dst_point, src_surface, src_rect); } HRESULT CDECL wined3d_device_draw_rect_patch(struct wined3d_device *device, UINT handle, - const float *num_segs, const WINED3DRECTPATCH_INFO *rect_patch_info) + const float *num_segs, const struct wined3d_rect_patch_info *rect_patch_info) { struct WineD3DRectPatch *patch; GLenum old_primitive_type; @@ -4919,13 +4688,13 @@ HRESULT CDECL wined3d_device_draw_rect_patch(struct wined3d_device *device, UINT if (num_segs[0] != patch->numSegs[0] || num_segs[1] != patch->numSegs[1] || num_segs[2] != patch->numSegs[2] || num_segs[3] != patch->numSegs[3] - || (rect_patch_info && memcmp(rect_patch_info, &patch->RectPatchInfo, sizeof(*rect_patch_info)))) + || (rect_patch_info && memcmp(rect_patch_info, &patch->rect_patch_info, sizeof(*rect_patch_info)))) { HRESULT hr; TRACE("Tesselation density or patch info changed, retesselating\n"); if (rect_patch_info) - patch->RectPatchInfo = *rect_patch_info; + patch->rect_patch_info = *rect_patch_info; patch->numSegs[0] = num_segs[0]; patch->numSegs[1] = num_segs[1]; @@ -4945,12 +4714,10 @@ HRESULT CDECL wined3d_device_draw_rect_patch(struct wined3d_device *device, UINT } } - device->currentPatch = patch; old_primitive_type = device->stateBlock->state.gl_primitive_type; device->stateBlock->state.gl_primitive_type = GL_TRIANGLES; wined3d_device_draw_primitive_strided(device, patch->numSegs[0] * patch->numSegs[1] * 2 * 3, &patch->strided); device->stateBlock->state.gl_primitive_type = old_primitive_type; - device->currentPatch = NULL; /* Destroy uncached patches */ if (!handle) @@ -4962,7 +4729,7 @@ HRESULT CDECL wined3d_device_draw_rect_patch(struct wined3d_device *device, UINT } HRESULT CDECL wined3d_device_draw_tri_patch(struct wined3d_device *device, UINT handle, - const float *segment_count, const WINED3DTRIPATCH_INFO *patch_info) + const float *segment_count, const struct wined3d_tri_patch_info *patch_info) { FIXME("device %p, handle %#x, segment_count %p, patch_info %p stub!\n", device, handle, segment_count, patch_info); @@ -4999,40 +4766,50 @@ HRESULT CDECL wined3d_device_delete_patch(struct wined3d_device *device, UINT ha /* Do not call while under the GL lock. */ HRESULT CDECL wined3d_device_color_fill(struct wined3d_device *device, - struct wined3d_surface *surface, const RECT *rect, const WINED3DCOLORVALUE *color) + struct wined3d_surface *surface, const RECT *rect, const struct wined3d_color *color) { + RECT r; + TRACE("device %p, surface %p, rect %s, color {%.8e, %.8e, %.8e, %.8e}.\n", device, surface, wine_dbgstr_rect(rect), color->r, color->g, color->b, color->a); - if (surface->resource.pool != WINED3DPOOL_DEFAULT && surface->resource.pool != WINED3DPOOL_SYSTEMMEM) + if (surface->resource.pool != WINED3D_POOL_DEFAULT && surface->resource.pool != WINED3D_POOL_SYSTEM_MEM) { - FIXME("call to colorfill with non WINED3DPOOL_DEFAULT or WINED3DPOOL_SYSTEMMEM surface\n"); + WARN("Color-fill not allowed on %s surfaces.\n", debug_d3dpool(surface->resource.pool)); return WINED3DERR_INVALIDCALL; } + if (!rect) + { + SetRect(&r, 0, 0, surface->resource.width, surface->resource.height); + rect = &r; + } + return surface_color_fill(surface, rect, color); } /* Do not call while under the GL lock. */ void CDECL wined3d_device_clear_rendertarget_view(struct wined3d_device *device, - struct wined3d_rendertarget_view *rendertarget_view, const WINED3DCOLORVALUE *color) + struct wined3d_rendertarget_view *rendertarget_view, const struct wined3d_color *color) { struct wined3d_resource *resource; HRESULT hr; + RECT rect; resource = rendertarget_view->resource; - if (resource->resourceType != WINED3DRTYPE_SURFACE) + if (resource->type != WINED3D_RTYPE_SURFACE) { FIXME("Only supported on surface resources\n"); return; } - hr = surface_color_fill(surface_from_resource(resource), NULL, color); + SetRect(&rect, 0, 0, resource->width, resource->height); + hr = surface_color_fill(surface_from_resource(resource), &rect, color); if (FAILED(hr)) ERR("Color fill failed, hr %#x.\n", hr); } -HRESULT CDECL wined3d_device_get_render_target(struct wined3d_device *device, +HRESULT CDECL wined3d_device_get_render_target(const struct wined3d_device *device, UINT render_target_idx, struct wined3d_surface **render_target) { TRACE("device %p, render_target_idx %u, render_target %p.\n", @@ -5045,15 +4822,18 @@ HRESULT CDECL wined3d_device_get_render_target(struct wined3d_device *device, } *render_target = device->fb.render_targets[render_target_idx]; - if (*render_target) - wined3d_surface_incref(*render_target); - TRACE("Returning render target %p.\n", *render_target); + if (!*render_target) + return WINED3DERR_NOTFOUND; + + wined3d_surface_incref(*render_target); + return WINED3D_OK; } -HRESULT CDECL wined3d_device_get_depth_stencil(struct wined3d_device *device, struct wined3d_surface **depth_stencil) +HRESULT CDECL wined3d_device_get_depth_stencil(const struct wined3d_device *device, + struct wined3d_surface **depth_stencil) { TRACE("device %p, depth_stencil %p.\n", device, depth_stencil); @@ -5116,21 +4896,23 @@ HRESULT CDECL wined3d_device_set_render_target(struct wined3d_device *device, /* Set the viewport and scissor rectangles, if requested. Tests show * that stateblock recording is ignored, the change goes directly * into the primary stateblock. */ - device->stateBlock->state.viewport.Height = device->fb.render_targets[0]->resource.height; - device->stateBlock->state.viewport.Width = device->fb.render_targets[0]->resource.width; - device->stateBlock->state.viewport.X = 0; - device->stateBlock->state.viewport.Y = 0; - device->stateBlock->state.viewport.MaxZ = 1.0f; - device->stateBlock->state.viewport.MinZ = 0.0f; - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_VIEWPORT); + device->stateBlock->state.viewport.height = device->fb.render_targets[0]->resource.height; + device->stateBlock->state.viewport.width = device->fb.render_targets[0]->resource.width; + device->stateBlock->state.viewport.x = 0; + device->stateBlock->state.viewport.y = 0; + device->stateBlock->state.viewport.max_z = 1.0f; + device->stateBlock->state.viewport.min_z = 0.0f; + device_invalidate_state(device, STATE_VIEWPORT); device->stateBlock->state.scissor_rect.top = 0; device->stateBlock->state.scissor_rect.left = 0; - device->stateBlock->state.scissor_rect.right = device->stateBlock->state.viewport.Width; - device->stateBlock->state.scissor_rect.bottom = device->stateBlock->state.viewport.Height; - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SCISSORRECT); + device->stateBlock->state.scissor_rect.right = device->stateBlock->state.viewport.width; + device->stateBlock->state.scissor_rect.bottom = device->stateBlock->state.viewport.height; + device_invalidate_state(device, STATE_SCISSORRECT); } + device_invalidate_state(device, STATE_FRAMEBUFFER); + return WINED3D_OK; } @@ -5149,10 +4931,10 @@ HRESULT CDECL wined3d_device_set_depth_stencil(struct wined3d_device *device, st if (prev) { - if (device->swapchains[0]->presentParms.Flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL + if (device->swapchains[0]->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL || prev->flags & SFLAG_DISCARD) { - surface_modify_ds_location(prev, SFLAG_DS_DISCARDED, + surface_modify_ds_location(prev, SFLAG_LOST, prev->resource.width, prev->resource.height); if (prev == device->onscreen_depth_stencil) { @@ -5165,21 +4947,23 @@ HRESULT CDECL wined3d_device_set_depth_stencil(struct wined3d_device *device, st device->fb.depth_stencil = depth_stencil; if (depth_stencil) wined3d_surface_incref(depth_stencil); - if (prev) - wined3d_surface_decref(prev); if (!prev != !depth_stencil) { /* Swapping NULL / non NULL depth stencil affects the depth and tests */ - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_ZENABLE)); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_STENCILENABLE)); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_STENCILWRITEMASK)); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_DEPTHBIAS)); + device_invalidate_state(device, STATE_RENDER(WINED3D_RS_ZENABLE)); + device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILENABLE)); + device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK)); + device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS)); } else if (prev && prev->resource.format->depth_size != depth_stencil->resource.format->depth_size) { - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_DEPTHBIAS)); + device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS)); } + if (prev) + wined3d_surface_decref(prev); + + device_invalidate_state(device, STATE_FRAMEBUFFER); return WINED3D_OK; } @@ -5187,7 +4971,7 @@ HRESULT CDECL wined3d_device_set_depth_stencil(struct wined3d_device *device, st HRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device, UINT x_hotspot, UINT y_hotspot, struct wined3d_surface *cursor_image) { - WINED3DLOCKED_RECT lockedRect; + struct wined3d_mapped_rect mapped_rect; TRACE("device %p, x_hotspot %u, y_hotspot %u, cursor_image %p.\n", device, x_hotspot, y_hotspot, cursor_image); @@ -5205,7 +4989,7 @@ HRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device if (cursor_image) { - WINED3DLOCKED_RECT rect; + struct wined3d_mapped_rect rect; /* MSDN: Cursor must be A8R8G8B8 */ if (cursor_image->resource.format->id != WINED3DFMT_B8G8R8A8_UNORM) @@ -5215,12 +4999,12 @@ HRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device } /* MSDN: Cursor must be smaller than the display mode */ - if (cursor_image->resource.width > device->ddraw_width - || cursor_image->resource.height > device->ddraw_height) + if (cursor_image->resource.width > device->adapter->screen_size.cx + || cursor_image->resource.height > device->adapter->screen_size.cy) { WARN("Surface %p dimensions are %ux%u, but screen dimensions are %ux%u.\n", cursor_image, cursor_image->resource.width, cursor_image->resource.height, - device->ddraw_width, device->ddraw_height); + device->adapter->screen_size.cx, device->adapter->screen_size.cy); return WINED3DERR_INVALIDCALL; } @@ -5238,21 +5022,20 @@ HRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; const struct wined3d_format *format = wined3d_get_format(gl_info, WINED3DFMT_B8G8R8A8_UNORM); struct wined3d_context *context; - char *mem, *bits = rect.pBits; + char *mem, *bits = rect.data; GLint intfmt = format->glInternal; GLint gl_format = format->glFormat; GLint type = format->glType; INT height = device->cursorHeight; INT width = device->cursorWidth; INT bpp = format->byte_count; - DWORD sampler; INT i; /* Reformat the texture memory (pitch and width can be * different) */ mem = HeapAlloc(GetProcessHeap(), 0, width * height * bpp); for(i = 0; i < height; i++) - memcpy(&mem[width * bpp * i], &bits[rect.Pitch * i], width * bpp); + memcpy(&mem[width * bpp * i], &bits[rect.row_pitch * i], width * bpp); wined3d_surface_unmap(cursor_image); context = context_acquire(device, NULL); @@ -5265,19 +5048,11 @@ HRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)"); } - /* Make sure that a proper texture unit is selected */ - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB)); - checkGLcall("glActiveTextureARB"); - sampler = device->rev_tex_unit_map[0]; - if (sampler != WINED3D_UNMAPPED_STAGE) - { - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(sampler)); - } + invalidate_active_texture(device, context); /* Create a new cursor texture */ glGenTextures(1, &device->cursorTexture); checkGLcall("glGenTextures"); - glBindTexture(GL_TEXTURE_2D, device->cursorTexture); - checkGLcall("glBindTexture"); + context_bind_texture(context, GL_TEXTURE_2D, device->cursorTexture); /* Copy the bitmap memory into the cursor texture */ glTexImage2D(GL_TEXTURE_2D, 0, intfmt, width, height, 0, gl_format, type, mem); checkGLcall("glTexImage2D"); @@ -5309,7 +5084,7 @@ HRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device * chunks. */ DWORD *maskBits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (cursor_image->resource.width * cursor_image->resource.height / 8)); - wined3d_surface_map(cursor_image, &lockedRect, NULL, + wined3d_surface_map(cursor_image, &mapped_rect, NULL, WINED3DLOCK_NO_DIRTY_UPDATE | WINED3DLOCK_READONLY); TRACE("width: %u height: %u.\n", cursor_image->resource.width, cursor_image->resource.height); @@ -5319,7 +5094,7 @@ HRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device cursorInfo.hbmMask = CreateBitmap(cursor_image->resource.width, cursor_image->resource.height, 1, 1, maskBits); cursorInfo.hbmColor = CreateBitmap(cursor_image->resource.width, cursor_image->resource.height, - 1, 32, lockedRect.pBits); + 1, 32, mapped_rect.data); wined3d_surface_unmap(cursor_image); /* Create our cursor and clean up. */ cursor = CreateIconIndirect(&cursorInfo); @@ -5346,10 +5121,16 @@ void CDECL wined3d_device_set_cursor_position(struct wined3d_device *device, device->xScreenSpace = x_screen_space; device->yScreenSpace = y_screen_space; - /* switch to the software cursor if position diverges from the hardware one */ if (device->hardwareCursor) { POINT pt; + + GetCursorPos( &pt ); + if (x_screen_space == pt.x && y_screen_space == pt.y) + return; + SetCursorPos( x_screen_space, y_screen_space ); + + /* Switch to the software cursor if position diverges from the hardware one. */ GetCursorPos( &pt ); if (x_screen_space != pt.x || y_screen_space != pt.y) { @@ -5395,104 +5176,41 @@ BOOL CDECL wined3d_device_show_cursor(struct wined3d_device *device, BOOL show) return oldVisible; } -static HRESULT WINAPI evict_managed_resource(struct wined3d_resource *resource, void *data) +void CDECL wined3d_device_evict_managed_resources(struct wined3d_device *device) { - TRACE("checking resource %p for eviction\n", resource); + struct wined3d_resource *resource, *cursor; - if (resource->pool == WINED3DPOOL_MANAGED) - { - TRACE("Evicting %p.\n", resource); - resource->resource_ops->resource_unload(resource); - } - - return S_OK; -} - -HRESULT CDECL wined3d_device_evict_managed_resources(struct wined3d_device *device) -{ TRACE("device %p.\n", device); - wined3d_device_enum_resources(device, evict_managed_resource, NULL); + LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry) + { + TRACE("Checking resource %p for eviction.\n", resource); + + if (resource->pool == WINED3D_POOL_MANAGED) + { + TRACE("Evicting %p.\n", resource); + resource->resource_ops->resource_unload(resource); + } + } + /* Invalidate stream sources, the buffer(s) may have been evicted. */ - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_STREAMSRC); - - return WINED3D_OK; + device_invalidate_state(device, STATE_STREAMSRC); } -static HRESULT updateSurfaceDesc(struct wined3d_surface *surface, - const WINED3DPRESENT_PARAMETERS *pPresentationParameters) -{ - struct wined3d_device *device = surface->resource.device; - const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; - - /* Reallocate proper memory for the front and back buffer and adjust their sizes */ - if (surface->flags & SFLAG_DIBSECTION) - { - /* Release the DC */ - SelectObject(surface->hDC, surface->dib.holdbitmap); - DeleteDC(surface->hDC); - /* Release the DIB section */ - DeleteObject(surface->dib.DIBsection); - surface->dib.bitmap_data = NULL; - surface->resource.allocatedMemory = NULL; - surface->flags &= ~SFLAG_DIBSECTION; - } - surface->resource.width = pPresentationParameters->BackBufferWidth; - surface->resource.height = pPresentationParameters->BackBufferHeight; - if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] || gl_info->supported[ARB_TEXTURE_RECTANGLE] - || gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT]) - { - surface->pow2Width = pPresentationParameters->BackBufferWidth; - surface->pow2Height = pPresentationParameters->BackBufferHeight; - } else { - surface->pow2Width = surface->pow2Height = 1; - while (surface->pow2Width < pPresentationParameters->BackBufferWidth) surface->pow2Width <<= 1; - while (surface->pow2Height < pPresentationParameters->BackBufferHeight) surface->pow2Height <<= 1; - } - - if (surface->texture_name) - { - struct wined3d_context *context = context_acquire(device, NULL); - ENTER_GL(); - glDeleteTextures(1, &surface->texture_name); - LEAVE_GL(); - context_release(context); - surface->texture_name = 0; - surface->flags &= ~SFLAG_CLIENT; - } - if (surface->pow2Width != pPresentationParameters->BackBufferWidth - || surface->pow2Height != pPresentationParameters->BackBufferHeight) - { - surface->flags |= SFLAG_NONPOW2; - } - else - { - surface->flags &= ~SFLAG_NONPOW2; - } - HeapFree(GetProcessHeap(), 0, surface->resource.heapMemory); - surface->resource.allocatedMemory = NULL; - surface->resource.heapMemory = NULL; - surface->resource.size = wined3d_surface_get_pitch(surface) * surface->pow2Width; - - /* Put all surfaces into sysmem - the drawable might disappear if the backbuffer was rendered - * to a FBO */ - if (!surface_init_sysmem(surface)) - { - return E_OUTOFMEMORY; - } - return WINED3D_OK; -} - -static BOOL is_display_mode_supported(struct wined3d_device *device, const WINED3DPRESENT_PARAMETERS *pp) +static BOOL is_display_mode_supported(const struct wined3d_device *device, + const struct wined3d_swapchain_desc *swapchain_desc) { + struct wined3d_display_mode m; UINT i, count; - WINED3DDISPLAYMODE m; HRESULT hr; /* All Windowed modes are supported, as is leaving the current mode */ - if(pp->Windowed) return TRUE; - if(!pp->BackBufferWidth) return TRUE; - if(!pp->BackBufferHeight) return TRUE; + if (swapchain_desc->windowed) + return TRUE; + if (!swapchain_desc->backbuffer_width) + return TRUE; + if (!swapchain_desc->backbuffer_height) + return TRUE; count = wined3d_get_adapter_mode_count(device->wined3d, device->adapter->ordinal, WINED3DFMT_UNKNOWN); for (i = 0; i < count; ++i) @@ -5501,7 +5219,7 @@ static BOOL is_display_mode_supported(struct wined3d_device *device, const WINED hr = wined3d_enum_adapter_modes(device->wined3d, device->adapter->ordinal, WINED3DFMT_UNKNOWN, i, &m); if (FAILED(hr)) ERR("Failed to enumerate adapter mode.\n"); - if (m.Width == pp->BackBufferWidth && m.Height == pp->BackBufferHeight) + if (m.width == swapchain_desc->backbuffer_width && m.height == swapchain_desc->backbuffer_height) /* Mode found, it is supported. */ return TRUE; } @@ -5512,6 +5230,7 @@ static BOOL is_display_mode_supported(struct wined3d_device *device, const WINED /* Do not call while under the GL lock. */ static void delete_opengl_contexts(struct wined3d_device *device, struct wined3d_swapchain *swapchain) { + struct wined3d_resource *resource, *cursor; const struct wined3d_gl_info *gl_info; struct wined3d_context *context; struct wined3d_shader *shader; @@ -5519,7 +5238,13 @@ static void delete_opengl_contexts(struct wined3d_device *device, struct wined3d context = context_acquire(device, NULL); gl_info = context->gl_info; - wined3d_device_enum_resources(device, device_unload_resource, NULL); + LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry) + { + TRACE("Unloading resource %p.\n", resource); + + resource->resource_ops->resource_unload(resource); + } + LIST_FOR_EACH_ENTRY(shader, &device->shaders, struct wined3d_shader, shader_list_entry) { device->shader_backend->shader_destroy(shader); @@ -5531,12 +5256,10 @@ static void delete_opengl_contexts(struct wined3d_device *device, struct wined3d glDeleteTextures(1, &device->depth_blt_texture); device->depth_blt_texture = 0; } - if (device->depth_blt_rb) + if (device->cursorTexture) { - gl_info->fbo_ops.glDeleteRenderbuffers(1, &device->depth_blt_rb); - device->depth_blt_rb = 0; - device->depth_blt_rb_w = 0; - device->depth_blt_rb_h = 0; + glDeleteTextures(1, &device->cursorTexture); + device->cursorTexture = 0; } LEAVE_GL(); @@ -5549,11 +5272,11 @@ static void delete_opengl_contexts(struct wined3d_device *device, struct wined3d while (device->context_count) { - context_destroy(device, device->contexts[0]); + swapchain_destroy_contexts(device->contexts[0]->swapchain); } + HeapFree(GetProcessHeap(), 0, swapchain->context); swapchain->context = NULL; - swapchain->num_contexts = 0; } /* Do not call while under the GL lock. */ @@ -5581,7 +5304,7 @@ static HRESULT create_primary_opengl_context(struct wined3d_device *device, stru swapchain->context[0] = context; swapchain->num_contexts = 1; - create_dummy_textures(device); + create_dummy_textures(device, context); context_release(context); hr = device->shader_backend->shader_alloc_private(device); @@ -5622,14 +5345,32 @@ err: /* Do not call while under the GL lock. */ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device, - WINED3DPRESENT_PARAMETERS *present_parameters) + const struct wined3d_swapchain_desc *swapchain_desc, + wined3d_device_reset_cb callback) { + struct wined3d_resource *resource, *cursor; struct wined3d_swapchain *swapchain; + struct wined3d_display_mode mode; BOOL DisplayModeChanged = FALSE; - WINED3DDISPLAYMODE mode; + BOOL update_desc = FALSE; HRESULT hr; - TRACE("device %p, present_parameters %p.\n", device, present_parameters); + TRACE("device %p, swapchain_desc %p.\n", device, swapchain_desc); + + stateblock_unbind_resources(device->stateBlock); + + if (device->onscreen_depth_stencil) + { + wined3d_surface_decref(device->onscreen_depth_stencil); + device->onscreen_depth_stencil = NULL; + } + + LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry) + { + TRACE("Enumerating resource %p.\n", resource); + if (FAILED(hr = callback(resource))) + return hr; + } hr = wined3d_device_get_swapchain(device, 0, &swapchain); if (FAILED(hr)) @@ -5638,12 +5379,12 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device, return hr; } - if (!is_display_mode_supported(device, present_parameters)) + if (!is_display_mode_supported(device, swapchain_desc)) { - WARN("Rejecting Reset() call because the requested display mode is not supported\n"); - WARN("Requested mode: %d, %d.\n", - present_parameters->BackBufferWidth, - present_parameters->BackBufferHeight); + WARN("Rejecting reset() call because the requested display mode is not supported.\n"); + WARN("Requested mode: %ux%u.\n", + swapchain_desc->backbuffer_width, + swapchain_desc->backbuffer_height); wined3d_swapchain_decref(swapchain); return WINED3DERR_INVALIDCALL; } @@ -5656,51 +5397,50 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device, * TODO: Figure out what happens to explicit swapchains, or if we have more than one implicit swapchain */ TRACE("New params:\n"); - TRACE("BackBufferWidth = %d\n", present_parameters->BackBufferWidth); - TRACE("BackBufferHeight = %d\n", present_parameters->BackBufferHeight); - TRACE("BackBufferFormat = %s\n", debug_d3dformat(present_parameters->BackBufferFormat)); - TRACE("BackBufferCount = %d\n", present_parameters->BackBufferCount); - TRACE("MultiSampleType = %d\n", present_parameters->MultiSampleType); - TRACE("MultiSampleQuality = %d\n", present_parameters->MultiSampleQuality); - TRACE("SwapEffect = %d\n", present_parameters->SwapEffect); - TRACE("hDeviceWindow = %p\n", present_parameters->hDeviceWindow); - TRACE("Windowed = %s\n", present_parameters->Windowed ? "true" : "false"); - TRACE("EnableAutoDepthStencil = %s\n", present_parameters->EnableAutoDepthStencil ? "true" : "false"); - TRACE("Flags = %08x\n", present_parameters->Flags); - TRACE("FullScreen_RefreshRateInHz = %d\n", present_parameters->FullScreen_RefreshRateInHz); - TRACE("PresentationInterval = %d\n", present_parameters->PresentationInterval); + TRACE("backbuffer_width %u\n", swapchain_desc->backbuffer_width); + TRACE("backbuffer_height %u\n", swapchain_desc->backbuffer_height); + TRACE("backbuffer_format %s\n", debug_d3dformat(swapchain_desc->backbuffer_format)); + TRACE("backbuffer_count %u\n", swapchain_desc->backbuffer_count); + TRACE("multisample_type %#x\n", swapchain_desc->multisample_type); + TRACE("multisample_quality %u\n", swapchain_desc->multisample_quality); + TRACE("swap_effect %#x\n", swapchain_desc->swap_effect); + TRACE("device_window %p\n", swapchain_desc->device_window); + TRACE("windowed %#x\n", swapchain_desc->windowed); + TRACE("enable_auto_depth_stencil %#x\n", swapchain_desc->enable_auto_depth_stencil); + if (swapchain_desc->enable_auto_depth_stencil) + TRACE("auto_depth_stencil_format %s\n", debug_d3dformat(swapchain_desc->auto_depth_stencil_format)); + TRACE("flags %#x\n", swapchain_desc->flags); + TRACE("refresh_rate %u\n", swapchain_desc->refresh_rate); + TRACE("swap_interval %u\n", swapchain_desc->swap_interval); + TRACE("auto_restore_display_mode %#x\n", swapchain_desc->auto_restore_display_mode); /* No special treatment of these parameters. Just store them */ - swapchain->presentParms.SwapEffect = present_parameters->SwapEffect; - swapchain->presentParms.Flags = present_parameters->Flags; - swapchain->presentParms.PresentationInterval = present_parameters->PresentationInterval; - swapchain->presentParms.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz; + swapchain->desc.swap_effect = swapchain_desc->swap_effect; + swapchain->desc.flags = swapchain_desc->flags; + swapchain->desc.swap_interval = swapchain_desc->swap_interval; + swapchain->desc.refresh_rate = swapchain_desc->refresh_rate; /* What to do about these? */ - if (present_parameters->BackBufferCount - && present_parameters->BackBufferCount != swapchain->presentParms.BackBufferCount) + if (swapchain_desc->backbuffer_count + && swapchain_desc->backbuffer_count != swapchain->desc.backbuffer_count) FIXME("Cannot change the back buffer count yet.\n"); - if (present_parameters->BackBufferFormat != WINED3DFMT_UNKNOWN - && present_parameters->BackBufferFormat != swapchain->presentParms.BackBufferFormat) - FIXME("Cannot change the back buffer format yet.\n"); - - if (present_parameters->hDeviceWindow - && present_parameters->hDeviceWindow != swapchain->presentParms.hDeviceWindow) + if (swapchain_desc->device_window + && swapchain_desc->device_window != swapchain->desc.device_window) FIXME("Cannot change the device window yet.\n"); - if (present_parameters->EnableAutoDepthStencil && !device->auto_depth_stencil) + if (swapchain_desc->enable_auto_depth_stencil && !device->auto_depth_stencil) { HRESULT hrc; TRACE("Creating the depth stencil buffer\n"); hrc = device->device_parent->ops->create_depth_stencil(device->device_parent, - present_parameters->BackBufferWidth, - present_parameters->BackBufferHeight, - present_parameters->AutoDepthStencilFormat, - present_parameters->MultiSampleType, - present_parameters->MultiSampleQuality, + swapchain_desc->backbuffer_width, + swapchain_desc->backbuffer_height, + swapchain_desc->auto_depth_stencil_format, + swapchain_desc->multisample_type, + swapchain_desc->multisample_quality, FALSE, &device->auto_depth_stencil); if (FAILED(hrc)) @@ -5718,7 +5458,7 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device, } /* Reset the depth stencil */ - if (present_parameters->EnableAutoDepthStencil) + if (swapchain_desc->enable_auto_depth_stencil) wined3d_device_set_depth_stencil(device, device->auto_depth_stencil); else wined3d_device_set_depth_stencil(device, NULL); @@ -5727,46 +5467,67 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device, wined3d_stateblock_decref(device->updateStateBlock); wined3d_stateblock_decref(device->stateBlock); - delete_opengl_contexts(device, swapchain); - - if (present_parameters->Windowed) + if (swapchain_desc->windowed) { - mode.Width = swapchain->orig_width; - mode.Height = swapchain->orig_height; - mode.RefreshRate = 0; - mode.Format = swapchain->presentParms.BackBufferFormat; + mode.width = swapchain->orig_width; + mode.height = swapchain->orig_height; + mode.refresh_rate = 0; + mode.format_id = swapchain->desc.backbuffer_format; } else { - mode.Width = present_parameters->BackBufferWidth; - mode.Height = present_parameters->BackBufferHeight; - mode.RefreshRate = present_parameters->FullScreen_RefreshRateInHz; - mode.Format = swapchain->presentParms.BackBufferFormat; + mode.width = swapchain_desc->backbuffer_width; + mode.height = swapchain_desc->backbuffer_height; + mode.refresh_rate = swapchain_desc->refresh_rate; + mode.format_id = swapchain_desc->backbuffer_format; } /* Should Width == 800 && Height == 0 set 800x600? */ - if (present_parameters->BackBufferWidth && present_parameters->BackBufferHeight - && (present_parameters->BackBufferWidth != swapchain->presentParms.BackBufferWidth - || present_parameters->BackBufferHeight != swapchain->presentParms.BackBufferHeight)) + if (swapchain_desc->backbuffer_width && swapchain_desc->backbuffer_height + && (swapchain_desc->backbuffer_width != swapchain->desc.backbuffer_width + || swapchain_desc->backbuffer_height != swapchain->desc.backbuffer_height)) + { + if (!swapchain_desc->windowed) + DisplayModeChanged = TRUE; + + swapchain->desc.backbuffer_width = swapchain_desc->backbuffer_width; + swapchain->desc.backbuffer_height = swapchain_desc->backbuffer_height; + update_desc = TRUE; + } + + if (swapchain_desc->backbuffer_format != WINED3DFMT_UNKNOWN + && swapchain_desc->backbuffer_format != swapchain->desc.backbuffer_format) + { + swapchain->desc.backbuffer_format = swapchain_desc->backbuffer_format; + update_desc = TRUE; + } + + if (swapchain_desc->multisample_type != swapchain->desc.multisample_type + || swapchain_desc->multisample_quality != swapchain->desc.multisample_quality) + { + swapchain->desc.multisample_type = swapchain_desc->multisample_type; + swapchain->desc.multisample_quality = swapchain_desc->multisample_quality; + update_desc = TRUE; + } + + if (update_desc) { UINT i; - if (!present_parameters->Windowed) - DisplayModeChanged = TRUE; - - swapchain->presentParms.BackBufferWidth = present_parameters->BackBufferWidth; - swapchain->presentParms.BackBufferHeight = present_parameters->BackBufferHeight; - - hr = updateSurfaceDesc(swapchain->front_buffer, present_parameters); + hr = wined3d_surface_update_desc(swapchain->front_buffer, swapchain->desc.backbuffer_width, + swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format, + swapchain->desc.multisample_type, swapchain->desc.multisample_quality); if (FAILED(hr)) { wined3d_swapchain_decref(swapchain); return hr; } - for (i = 0; i < swapchain->presentParms.BackBufferCount; ++i) + for (i = 0; i < swapchain->desc.backbuffer_count; ++i) { - hr = updateSurfaceDesc(swapchain->back_buffers[i], present_parameters); + hr = wined3d_surface_update_desc(swapchain->back_buffers[i], swapchain->desc.backbuffer_width, + swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format, + swapchain->desc.multisample_type, swapchain->desc.multisample_quality); if (FAILED(hr)) { wined3d_swapchain_decref(swapchain); @@ -5775,7 +5536,9 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device, } if (device->auto_depth_stencil) { - hr = updateSurfaceDesc(device->auto_depth_stencil, present_parameters); + hr = wined3d_surface_update_desc(device->auto_depth_stencil, swapchain->desc.backbuffer_width, + swapchain->desc.backbuffer_height, device->auto_depth_stencil->resource.format->id, + swapchain->desc.multisample_type, swapchain->desc.multisample_quality); if (FAILED(hr)) { wined3d_swapchain_decref(swapchain); @@ -5784,18 +5547,21 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device, } } - if (!present_parameters->Windowed != !swapchain->presentParms.Windowed + if (device->d3d_initialized) + delete_opengl_contexts(device, swapchain); + + if (!swapchain_desc->windowed != !swapchain->desc.windowed || DisplayModeChanged) { wined3d_device_set_display_mode(device, 0, &mode); - if (!present_parameters->Windowed) + if (!swapchain_desc->windowed) { - if (swapchain->presentParms.Windowed) + if (swapchain->desc.windowed) { - HWND focus_window = device->createParms.hFocusWindow; + HWND focus_window = device->create_parms.focus_window; if (!focus_window) - focus_window = present_parameters->hDeviceWindow; + focus_window = swapchain_desc->device_window; if (FAILED(hr = wined3d_device_acquire_focus_window(device, focus_window))) { ERR("Failed to acquire focus window, hr %#x.\n", hr); @@ -5805,26 +5571,27 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device, /* switch from windowed to fs */ wined3d_device_setup_fullscreen_window(device, swapchain->device_window, - present_parameters->BackBufferWidth, - present_parameters->BackBufferHeight); + swapchain_desc->backbuffer_width, + swapchain_desc->backbuffer_height); } else { /* Fullscreen -> fullscreen mode change */ MoveWindow(swapchain->device_window, 0, 0, - present_parameters->BackBufferWidth, present_parameters->BackBufferHeight, - TRUE); + swapchain_desc->backbuffer_width, + swapchain_desc->backbuffer_height, + TRUE); } } - else if (!swapchain->presentParms.Windowed) + else if (!swapchain->desc.windowed) { /* Fullscreen -> windowed switch */ wined3d_device_restore_fullscreen_window(device, swapchain->device_window); wined3d_device_release_focus_window(device); } - swapchain->presentParms.Windowed = present_parameters->Windowed; + swapchain->desc.windowed = swapchain_desc->windowed; } - else if (!present_parameters->Windowed) + else if (!swapchain_desc->windowed) { DWORD style = device->style; DWORD exStyle = device->exStyle; @@ -5835,14 +5602,14 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device, device->style = 0; device->exStyle = 0; wined3d_device_setup_fullscreen_window(device, swapchain->device_window, - present_parameters->BackBufferWidth, - present_parameters->BackBufferHeight); + swapchain_desc->backbuffer_width, + swapchain_desc->backbuffer_height); device->style = style; device->exStyle = exStyle; } /* Note: No parent needed for initial internal stateblock */ - hr = wined3d_stateblock_create(device, WINED3DSBT_INIT, &device->stateBlock); + hr = wined3d_stateblock_create(device, WINED3D_SBT_INIT, &device->stateBlock); if (FAILED(hr)) ERR("Resetting the stateblock failed with error %#x.\n", hr); else @@ -5852,33 +5619,11 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device, stateblock_init_default_state(device->stateBlock); - if(wined3d_settings.offscreen_rendering_mode == ORM_FBO) - { - RECT client_rect; - GetClientRect(swapchain->win_handle, &client_rect); + swapchain_update_render_to_fbo(swapchain); + swapchain_update_draw_bindings(swapchain); - if(!swapchain->presentParms.BackBufferCount) - { - TRACE("Single buffered rendering\n"); - swapchain->render_to_fbo = FALSE; - } - else if(swapchain->presentParms.BackBufferWidth != client_rect.right || - swapchain->presentParms.BackBufferHeight != client_rect.bottom ) - { - TRACE("Rendering to FBO. Backbuffer %ux%u, window %ux%u\n", - swapchain->presentParms.BackBufferWidth, - swapchain->presentParms.BackBufferHeight, - client_rect.right, client_rect.bottom); - swapchain->render_to_fbo = TRUE; - } - else - { - TRACE("Rendering directly to GL_BACK\n"); - swapchain->render_to_fbo = FALSE; - } - } - - hr = create_primary_opengl_context(device, swapchain); + if (device->d3d_initialized) + hr = create_primary_opengl_context(device, swapchain); wined3d_swapchain_decref(swapchain); /* All done. There is no need to reload resources or shaders, this will happen automatically on the @@ -5897,17 +5642,17 @@ HRESULT CDECL wined3d_device_set_dialog_box_mode(struct wined3d_device *device, } -HRESULT CDECL wined3d_device_get_creation_parameters(struct wined3d_device *device, - WINED3DDEVICE_CREATION_PARAMETERS *parameters) +HRESULT CDECL wined3d_device_get_creation_parameters(const struct wined3d_device *device, + struct wined3d_device_creation_parameters *parameters) { TRACE("device %p, parameters %p.\n", device, parameters); - *parameters = device->createParms; + *parameters = device->create_parms; return WINED3D_OK; } -void CDECL wined3d_device_set_gamma_ramp(struct wined3d_device *device, - UINT swapchain_idx, DWORD flags, const WINED3DGAMMARAMP *ramp) +void CDECL wined3d_device_set_gamma_ramp(const struct wined3d_device *device, + UINT swapchain_idx, DWORD flags, const struct wined3d_gamma_ramp *ramp) { struct wined3d_swapchain *swapchain; @@ -5921,7 +5666,8 @@ void CDECL wined3d_device_set_gamma_ramp(struct wined3d_device *device, } } -void CDECL wined3d_device_get_gamma_ramp(struct wined3d_device *device, UINT swapchain_idx, WINED3DGAMMARAMP *ramp) +void CDECL wined3d_device_get_gamma_ramp(const struct wined3d_device *device, + UINT swapchain_idx, struct wined3d_gamma_ramp *ramp) { struct wined3d_swapchain *swapchain; @@ -5951,7 +5697,7 @@ static void device_resource_remove(struct wined3d_device *device, struct wined3d void device_resource_released(struct wined3d_device *device, struct wined3d_resource *resource) { - WINED3DRESOURCETYPE type = resource->resourceType; + enum wined3d_resource_type type = resource->type; unsigned int i; TRACE("device %p, resource %p, type %s.\n", device, resource, debug_d3dresourcetype(type)); @@ -5960,7 +5706,7 @@ void device_resource_released(struct wined3d_device *device, struct wined3d_reso switch (type) { - case WINED3DRTYPE_SURFACE: + case WINED3D_RTYPE_SURFACE: { struct wined3d_surface *surface = surface_from_resource(resource); @@ -5983,9 +5729,9 @@ void device_resource_released(struct wined3d_device *device, struct wined3d_reso } break; - case WINED3DRTYPE_TEXTURE: - case WINED3DRTYPE_CUBETEXTURE: - case WINED3DRTYPE_VOLUMETEXTURE: + case WINED3D_RTYPE_TEXTURE: + case WINED3D_RTYPE_CUBE_TEXTURE: + case WINED3D_RTYPE_VOLUME_TEXTURE: for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) { struct wined3d_texture *texture = wined3d_texture_from_resource(resource); @@ -6007,7 +5753,7 @@ void device_resource_released(struct wined3d_device *device, struct wined3d_reso } break; - case WINED3DRTYPE_BUFFER: + case WINED3D_RTYPE_BUFFER: { struct wined3d_buffer *buffer = buffer_from_resource(resource); @@ -6057,36 +5803,19 @@ void device_resource_released(struct wined3d_device *device, struct wined3d_reso TRACE("Resource released.\n"); } -HRESULT CDECL wined3d_device_enum_resources(struct wined3d_device *device, - D3DCB_ENUMRESOURCES callback, void *data) -{ - struct wined3d_resource *resource, *cursor; - - TRACE("device %p, callback %p, data %p.\n", device, callback, data); - - LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry) - { - TRACE("enumerating resource %p.\n", resource); - if (callback(resource, data) == S_FALSE) - { - TRACE("Canceling enumeration.\n"); - break; - } - } - - return WINED3D_OK; -} - -HRESULT CDECL wined3d_device_get_surface_from_dc(struct wined3d_device *device, +HRESULT CDECL wined3d_device_get_surface_from_dc(const struct wined3d_device *device, HDC dc, struct wined3d_surface **surface) { struct wined3d_resource *resource; TRACE("device %p, dc %p, surface %p.\n", device, dc, surface); + if (!dc) + return WINED3DERR_INVALIDCALL; + LIST_FOR_EACH_ENTRY(resource, &device->resources, struct wined3d_resource, resource_list_entry) { - if (resource->resourceType == WINED3DRTYPE_SURFACE) + if (resource->type == WINED3D_RTYPE_SURFACE) { struct wined3d_surface *s = surface_from_resource(resource); @@ -6103,14 +5832,14 @@ HRESULT CDECL wined3d_device_get_surface_from_dc(struct wined3d_device *device, } HRESULT device_init(struct wined3d_device *device, struct wined3d *wined3d, - UINT adapter_idx, WINED3DDEVTYPE device_type, HWND focus_window, DWORD flags, - struct wined3d_device_parent *device_parent) + UINT adapter_idx, enum wined3d_device_type device_type, HWND focus_window, DWORD flags, + BYTE surface_alignment, struct wined3d_device_parent *device_parent) { struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx]; const struct fragment_pipeline *fragment_pipeline; + struct wined3d_display_mode mode; struct shader_caps shader_caps; struct fragment_caps ffp_caps; - WINED3DDISPLAYMODE mode; unsigned int i; HRESULT hr; @@ -6121,8 +5850,7 @@ HRESULT device_init(struct wined3d_device *device, struct wined3d *wined3d, device->device_parent = device_parent; list_init(&device->resources); list_init(&device->shaders); - - device->surface_alignment = wined3d->dxVersion == 7 ? DDRAW_PITCH_ALIGNMENT : D3D8_PITCH_ALIGNMENT; + device->surface_alignment = surface_alignment; /* Get the initial screen setup for ddraw. */ hr = wined3d_get_adapter_display_mode(wined3d, adapter_idx, &mode); @@ -6132,17 +5860,16 @@ HRESULT device_init(struct wined3d_device *device, struct wined3d *wined3d, wined3d_decref(device->wined3d); return hr; } - device->ddraw_width = mode.Width; - device->ddraw_height = mode.Height; - device->ddraw_format = mode.Format; + adapter->screen_size.cx = mode.width; + adapter->screen_size.cy = mode.height; + adapter->screen_format = mode.format_id; /* Save the creation parameters. */ - device->createParms.AdapterOrdinal = adapter_idx; - device->createParms.DeviceType = device_type; - device->createParms.hFocusWindow = focus_window; - device->createParms.BehaviorFlags = flags; + device->create_parms.adapter_idx = adapter_idx; + device->create_parms.device_type = device_type; + device->create_parms.focus_window = focus_window; + device->create_parms.flags = flags; - device->devType = device_type; for (i = 0; i < PATCHMAP_SIZE; ++i) list_init(&device->patches[i]); select_shader_mode(&adapter->gl_info, &device->ps_selected_mode, &device->vs_selected_mode); @@ -6151,6 +5878,8 @@ HRESULT device_init(struct wined3d_device *device, struct wined3d *wined3d, if (device->shader_backend) { device->shader_backend->shader_get_caps(&adapter->gl_info, &shader_caps); + device->vshader_version = shader_caps.VertexShaderVersion; + device->pshader_version = shader_caps.PixelShaderVersion; device->d3d_vshader_constantF = shader_caps.MaxVertexShaderConst; device->d3d_pshader_constantF = shader_caps.MaxPixelShaderConst; device->vs_clipping = shader_caps.VSClipping; @@ -6173,11 +5902,27 @@ HRESULT device_init(struct wined3d_device *device, struct wined3d *wined3d, } device->blitter = adapter->blitter; + hr = wined3d_stateblock_create(device, WINED3D_SBT_INIT, &device->stateBlock); + if (FAILED(hr)) + { + WARN("Failed to create stateblock.\n"); + for (i = 0; i < sizeof(device->multistate_funcs) / sizeof(device->multistate_funcs[0]); ++i) + { + HeapFree(GetProcessHeap(), 0, device->multistate_funcs[i]); + } + wined3d_decref(device->wined3d); + return hr; + } + + TRACE("Created stateblock %p.\n", device->stateBlock); + device->updateStateBlock = device->stateBlock; + wined3d_stateblock_incref(device->updateStateBlock); + return WINED3D_OK; } -void IWineD3DDeviceImpl_MarkStateDirty(struct wined3d_device *device, DWORD state) +void device_invalidate_state(const struct wined3d_device *device, DWORD state) { DWORD rep = device->StateTable[state].representative; struct wined3d_context *context; @@ -6197,28 +5942,32 @@ void IWineD3DDeviceImpl_MarkStateDirty(struct wined3d_device *device, DWORD stat } } -void get_drawable_size_fbo(struct wined3d_context *context, UINT *width, UINT *height) +void get_drawable_size_fbo(const struct wined3d_context *context, UINT *width, UINT *height) { /* The drawable size of a fbo target is the opengl texture size, which is the power of two size. */ *width = context->current_rt->pow2Width; *height = context->current_rt->pow2Height; } -void get_drawable_size_backbuffer(struct wined3d_context *context, UINT *width, UINT *height) +void get_drawable_size_backbuffer(const struct wined3d_context *context, UINT *width, UINT *height) { - struct wined3d_swapchain *swapchain = context->swapchain; + const struct wined3d_swapchain *swapchain = context->swapchain; /* The drawable size of a backbuffer / aux buffer offscreen target is the size of the * current context's drawable, which is the size of the back buffer of the swapchain * the active context belongs to. */ - *width = swapchain->presentParms.BackBufferWidth; - *height = swapchain->presentParms.BackBufferHeight; + *width = swapchain->desc.backbuffer_width; + *height = swapchain->desc.backbuffer_height; } LRESULT device_process_message(struct wined3d_device *device, HWND window, BOOL unicode, UINT message, WPARAM wparam, LPARAM lparam, WNDPROC proc) { + wined3d_mutex_lock(); + if (device->filter_messages) { + wined3d_mutex_unlock(); + TRACE("Filtering message: window %p, message %#x, wparam %#lx, lparam %#lx.\n", window, message, wparam, lparam); if (unicode) @@ -6235,6 +5984,12 @@ LRESULT device_process_message(struct wined3d_device *device, HWND window, BOOL if (device->focus_window == window) device->focus_window = NULL; else ERR("Window %p is not the focus window for device %p.\n", window, device); } + else if (message == WM_DISPLAYCHANGE) + { + device->device_parent->ops->mode_changed(device->device_parent); + } + + wined3d_mutex_unlock(); if (unicode) return CallWindowProcW(proc, window, message, wparam, lparam); diff --git a/reactos/dll/directx/wine/wined3d/directx.c b/reactos/dll/directx/wine/wined3d/directx.c index d7a2c02c83f..90fea0dec56 100644 --- a/reactos/dll/directx/wine/wined3d/directx.c +++ b/reactos/dll/directx/wine/wined3d/directx.c @@ -1,12 +1,10 @@ /* - * IWineD3D implementation - * * Copyright 2002-2004 Jason Edmeades * Copyright 2003-2004 Raphael Junqueira * Copyright 2004 Christian Costa * Copyright 2005 Oliver Stieber * Copyright 2007-2008 Stefan Dösinger for CodeWeavers - * Copyright 2009-2010 Henri Verbeet for CodeWeavers + * Copyright 2009-2011 Henri Verbeet for CodeWeavers * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -32,15 +30,56 @@ WINE_DECLARE_DEBUG_CHANNEL(d3d_caps); #define WINE_DEFAULT_VIDMEM (64 * 1024 * 1024) +/* The driver names reflect the lowest GPU supported + * by a certain driver, so DRIVER_AMD_R300 supports + * R3xx, R4xx and R5xx GPUs. */ +enum wined3d_display_driver +{ + DRIVER_AMD_RAGE_128PRO, + DRIVER_AMD_R100, + DRIVER_AMD_R300, + DRIVER_AMD_R600, + DRIVER_INTEL_GMA800, + DRIVER_INTEL_GMA900, + DRIVER_INTEL_GMA950, + DRIVER_INTEL_GMA3000, + DRIVER_NVIDIA_TNT, + DRIVER_NVIDIA_GEFORCE2MX, + DRIVER_NVIDIA_GEFORCEFX, + DRIVER_NVIDIA_GEFORCE6, + DRIVER_UNKNOWN +}; + +enum wined3d_driver_model +{ + DRIVER_MODEL_WIN9X, + DRIVER_MODEL_NT40, + DRIVER_MODEL_NT5X, + DRIVER_MODEL_NT6X +}; + +enum wined3d_gl_vendor +{ + GL_VENDOR_UNKNOWN, + GL_VENDOR_APPLE, + GL_VENDOR_FGLRX, + GL_VENDOR_INTEL, + GL_VENDOR_MESA, + GL_VENDOR_NVIDIA, +}; + /* The d3d device ID */ static const GUID IID_D3DDEVICE_D3DUID = { 0xaeb2cdd4, 0x6e41, 0x43ea, { 0x94,0x1c,0x83,0x61,0xcc,0x76,0x07,0x81 } }; /* Extension detection */ -static const struct { +static const struct +{ const char *extension_string; - GL_SupportedExt extension; + enum wined3d_gl_extension extension; DWORD version; -} EXTENSION_MAP[] = { +} +EXTENSION_MAP[] = +{ /* APPLE */ {"GL_APPLE_client_storage", APPLE_CLIENT_STORAGE, 0 }, {"GL_APPLE_fence", APPLE_FENCE, 0 }, @@ -55,12 +94,14 @@ static const struct { {"GL_ARB_depth_clamp", ARB_DEPTH_CLAMP, 0 }, {"GL_ARB_depth_texture", ARB_DEPTH_TEXTURE, 0 }, {"GL_ARB_draw_buffers", ARB_DRAW_BUFFERS, 0 }, + {"GL_ARB_draw_elements_base_vertex", ARB_DRAW_ELEMENTS_BASE_VERTEX, 0 }, {"GL_ARB_fragment_program", ARB_FRAGMENT_PROGRAM, 0 }, {"GL_ARB_fragment_shader", ARB_FRAGMENT_SHADER, 0 }, {"GL_ARB_framebuffer_object", ARB_FRAMEBUFFER_OBJECT, 0 }, {"GL_ARB_geometry_shader4", ARB_GEOMETRY_SHADER4, 0 }, {"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL, 0 }, {"GL_ARB_half_float_vertex", ARB_HALF_FLOAT_VERTEX, 0 }, + {"GL_ARB_map_buffer_alignment", ARB_MAP_BUFFER_ALIGNMENT, 0 }, {"GL_ARB_map_buffer_range", ARB_MAP_BUFFER_RANGE, 0 }, {"GL_ARB_multisample", ARB_MULTISAMPLE, 0 }, /* needs GLX_ARB_MULTISAMPLE as well */ {"GL_ARB_multitexture", ARB_MULTITEXTURE, 0 }, @@ -221,7 +262,7 @@ struct wined3d_fake_gl_ctx HGLRC restore_gl_ctx; }; -static void WineD3D_ReleaseFakeGLContext(struct wined3d_fake_gl_ctx *ctx) +static void WineD3D_ReleaseFakeGLContext(const struct wined3d_fake_gl_ctx *ctx) { TRACE_(d3d_caps)("Destroying fake GL context.\n"); @@ -300,11 +341,6 @@ static BOOL WineD3D_CreateFakeGLContext(struct wined3d_fake_gl_ctx *ctx) } /* Make it the current GL context. */ - if (!context_set_current(NULL)) - { - ERR_(d3d_caps)("Failed to clear current D3D context.\n"); - } - if (!pwglMakeCurrent(ctx->dc, ctx->gl_ctx)) { ERR_(d3d_caps)("Failed to make fake GL context current.\n"); @@ -329,12 +365,10 @@ fail: } /* Adjust the amount of used texture memory */ -unsigned int WineD3DAdapterChangeGLRam(struct wined3d_device *device, int glram) +unsigned int adapter_adjust_memory(struct wined3d_adapter *adapter, int amount) { - struct wined3d_adapter *adapter = device->adapter; - - adapter->UsedTextureRam += glram; - TRACE("Adjusted gl ram by %d to %d\n", glram, adapter->UsedTextureRam); + adapter->UsedTextureRam += amount; + TRACE("Adjusted adapter memory by %d to %d.\n", amount, adapter->UsedTextureRam); return adapter->UsedTextureRam; } @@ -373,10 +407,6 @@ ULONG CDECL wined3d_decref(struct wined3d *wined3d) return refcount; } -/********************************************************** - * IWineD3D parts follows - **********************************************************/ - /* GL locking is done by the caller */ static inline BOOL test_arb_vs_offset_limit(const struct wined3d_gl_info *gl_info) { @@ -413,7 +443,7 @@ static inline BOOL test_arb_vs_offset_limit(const struct wined3d_gl_info *gl_inf return ret; } -static DWORD ver_for_ext(GL_SupportedExt ext) +static DWORD ver_for_ext(enum wined3d_gl_extension ext) { unsigned int i; for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) { @@ -560,13 +590,6 @@ static BOOL match_apple_nonr500ati(const struct wined3d_gl_info *gl_info, const return TRUE; } -static BOOL match_fglrx(const struct wined3d_gl_info *gl_info, const char *gl_renderer, - enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device) -{ - return gl_vendor == GL_VENDOR_FGLRX; - -} - static BOOL match_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer, enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device) { @@ -580,6 +603,12 @@ static BOOL match_dx10_capable(const struct wined3d_gl_info *gl_info, const char return gl_info->limits.glsl_varyings > 44; } +static BOOL match_not_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer, + enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device) +{ + return !match_dx10_capable(gl_info, gl_renderer, gl_vendor, card_vendor, device); +} + /* A GL context is provided by the caller */ static BOOL match_allows_spec_alpha(const struct wined3d_gl_info *gl_info, const char *gl_renderer, enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device) @@ -608,13 +637,6 @@ static BOOL match_allows_spec_alpha(const struct wined3d_gl_info *gl_info, const } } -static BOOL match_apple_nvts(const struct wined3d_gl_info *gl_info, const char *gl_renderer, - enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device) -{ - if (!match_apple(gl_info, gl_renderer, gl_vendor, card_vendor, device)) return FALSE; - return gl_info->supported[NV_TEXTURE_SHADER]; -} - /* A GL context is provided by the caller */ static BOOL match_broken_nv_clip(const struct wined3d_gl_info *gl_info, const char *gl_renderer, enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device) @@ -717,6 +739,42 @@ static BOOL match_fbo_tex_update(const struct wined3d_gl_info *gl_info, const ch return *(DWORD *)data == 0x11111111; } +/* Context activation is done by the caller. */ +static BOOL match_broken_rgba16(const struct wined3d_gl_info *gl_info, const char *gl_renderer, + enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device) +{ + /* GL_RGBA16 uses GL_RGBA8 internally on Geforce 7 and older cards. + * This leads to graphical bugs in Half Life 2 and Unreal engine games. */ + GLuint tex; + GLint size; + + ENTER_GL(); + + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT, NULL); + checkGLcall("glTexImage2D"); + + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &size); + checkGLcall("glGetTexLevelParameteriv"); + TRACE("Real color depth is %d\n", size); + + glBindTexture(GL_TEXTURE_2D, 0); + checkGLcall("glBindTexture"); + glDeleteTextures(1, &tex); + checkGLcall("glDeleteTextures"); + + LEAVE_GL(); + + return size < 16; +} + +static BOOL match_fglrx(const struct wined3d_gl_info *gl_info, const char *gl_renderer, + enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device) +{ + return gl_vendor == GL_VENDOR_FGLRX; +} + static void quirk_arb_constants(struct wined3d_gl_info *gl_info) { TRACE_(d3d_caps)("Using ARB vs constant limit(=%u) for GLSL.\n", gl_info->limits.arb_vs_native_constants); @@ -735,35 +793,12 @@ static void quirk_apple_glsl_constants(struct wined3d_gl_info *gl_info) gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 12); } -/* fglrx crashes with a very bad kernel panic if GL_POINT_SPRITE_ARB is set to GL_COORD_REPLACE_ARB - * on more than one texture unit. This means that the d3d9 visual point size test will cause a - * kernel panic on any machine running fglrx 9.3(latest that supports r300 to r500 cards). This - * quirk only enables point sprites on the first texture unit. This keeps point sprites working in - * most games, but avoids the crash - * - * A more sophisticated way would be to find all units that need texture coordinates and enable - * point sprites for one if only one is found, and software emulate point sprites in drawStridedSlow - * if more than one unit needs texture coordinates(This requires software ffp and vertex shaders though) - * - * Note that disabling the extension entirely does not gain predictability because there is no point - * sprite capability flag in d3d, so the potential rendering bugs are the same if we disable the extension. */ -static void quirk_one_point_sprite(struct wined3d_gl_info *gl_info) -{ - if (gl_info->supported[ARB_POINT_SPRITE]) - { - TRACE("Limiting point sprites to one texture unit.\n"); - gl_info->limits.point_sprite_units = 1; - } -} - static void quirk_amd_dx9(struct wined3d_gl_info *gl_info) { - quirk_arb_constants(gl_info); - /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL). * If real NP2 textures are used, the driver falls back to software. We could just remove the - * extension and use GL_ARB_texture_rectangle instead, but texture_rectangle is inconventient + * extension and use GL_ARB_texture_rectangle instead, but texture_rectangle is inconvenient * due to the non-normalized texture coordinates. Thus set an internal extension flag, * GL_WINE_normalized_texrect, which signals the code that it can use non power of two textures * as per GL_ARB_texture_non_power_of_two, but has to stick to the texture_rectangle limits. @@ -777,11 +812,6 @@ static void quirk_amd_dx9(struct wined3d_gl_info *gl_info) gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE; gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT] = TRUE; } - - /* fglrx has the same structural issues as the one described in quirk_apple_glsl_constants, although - * it is generally more efficient. Reserve just 8 constants. */ - TRACE_(d3d_caps)("Reserving 8 GLSL constants for compiler private use.\n"); - gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 8); } static void quirk_no_np2(struct wined3d_gl_info *gl_info) @@ -796,7 +826,7 @@ static void quirk_no_np2(struct wined3d_gl_info *gl_info) * Note that wine_normalized_texrect can't be used in this case because internally it uses ARB_tex_npot, * triggering the software fallback. There is not much we can do here apart from disabling the * software-emulated extension and reenable ARB_tex_rect (which was previously disabled - * in IWineD3DImpl_FillGLCaps). + * in wined3d_adapter_init_gl_caps). * This fixup removes performance problems on both the FX 5900 and FX 5700 (e.g. for framebuffer * post-processing effects in the game "Max Payne 2"). * The behaviour can be verified through a simple test app attached in bugreport #14724. */ @@ -834,12 +864,6 @@ static void quirk_allows_specular_alpha(struct wined3d_gl_info *gl_info) gl_info->quirks |= WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA; } -static void quirk_apple_nvts(struct wined3d_gl_info *gl_info) -{ - gl_info->supported[NV_TEXTURE_SHADER] = FALSE; - gl_info->supported[NV_TEXTURE_SHADER2] = FALSE; -} - static void quirk_disable_nvvp_clip(struct wined3d_gl_info *gl_info) { gl_info->quirks |= WINED3D_QUIRK_NV_CLIP_BROKEN; @@ -850,6 +874,26 @@ static void quirk_fbo_tex_update(struct wined3d_gl_info *gl_info) gl_info->quirks |= WINED3D_QUIRK_FBO_TEX_UPDATE; } +static void quirk_broken_rgba16(struct wined3d_gl_info *gl_info) +{ + gl_info->quirks |= WINED3D_QUIRK_BROKEN_RGBA16; +} + +static void quirk_infolog_spam(struct wined3d_gl_info *gl_info) +{ + gl_info->quirks |= WINED3D_QUIRK_INFO_LOG_SPAM; +} + +static void quirk_limited_tex_filtering(struct wined3d_gl_info *gl_info) +{ + /* Nvidia GeForce 6xxx and 7xxx support accelerated VTF only on a few + selected texture formats. They are apparently the only DX9 class GPUs + supporting VTF. + Also, DX9-era GPUs are somewhat limited with float textures + filtering and blending. */ + gl_info->quirks |= WINED3D_QUIRK_LIMITED_TEX_FILTERING; +} + struct driver_quirk { BOOL (*match)(const struct wined3d_gl_info *gl_info, const char *gl_renderer, @@ -863,7 +907,7 @@ static const struct driver_quirk quirk_table[] = { match_amd_r300_to_500, quirk_amd_dx9, - "AMD GLSL constant and normalized texrect quirk" + "AMD normalized texrect quirk" }, /* MacOS advertises more GLSL vertex shader uniforms than supported by the hardware, and if more are * used it falls back to software. While the compiler can detect if the shader uses all declared @@ -891,11 +935,6 @@ static const struct driver_quirk quirk_table[] = quirk_texcoord_w, "Init texcoord .w for Apple ATI >= r600 GPU driver" }, - { - match_fglrx, - quirk_one_point_sprite, - "Fglrx point sprite crash workaround" - }, { match_dx10_capable, quirk_clip_varying, @@ -916,14 +955,6 @@ static const struct driver_quirk quirk_table[] = quirk_allows_specular_alpha, "Allow specular alpha quirk" }, - { - /* The pixel formats provided by GL_NV_texture_shader are broken on OSX - * (rdar://5682521). - */ - match_apple_nvts, - quirk_apple_nvts, - "Apple NV_texture_shader disable" - }, { match_broken_nv_clip, quirk_disable_nvvp_clip, @@ -934,6 +965,21 @@ static const struct driver_quirk quirk_table[] = quirk_fbo_tex_update, "FBO rebind for attachment updates" }, + { + match_broken_rgba16, + quirk_broken_rgba16, + "True RGBA16 is not available" + }, + { + match_fglrx, + quirk_infolog_spam, + "Not printing GLSL infolog" + }, + { + match_not_dx10_capable, + quirk_limited_tex_filtering, + "Texture filtering, blending and VTF support is limited" + }, }; /* Certain applications (Steam) complain if we report an outdated driver version. In general, @@ -1071,10 +1117,15 @@ static const struct gpu_description gpu_description_table[] = {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT440, "NVIDIA GeForce GT 440", DRIVER_NVIDIA_GEFORCE6, 1024}, {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTS450, "NVIDIA GeForce GTS 450", DRIVER_NVIDIA_GEFORCE6, 1024}, {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX460, "NVIDIA GeForce GTX 460", DRIVER_NVIDIA_GEFORCE6, 768 }, + {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX460M, "NVIDIA GeForce GTX 460M", DRIVER_NVIDIA_GEFORCE6, 1536}, {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX465, "NVIDIA GeForce GTX 465", DRIVER_NVIDIA_GEFORCE6, 1024}, {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX470, "NVIDIA GeForce GTX 470", DRIVER_NVIDIA_GEFORCE6, 1280}, {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX480, "NVIDIA GeForce GTX 480", DRIVER_NVIDIA_GEFORCE6, 1536}, - {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX560, "NVIDIA GeForce GTX 560 TI", DRIVER_NVIDIA_GEFORCE6, 1024}, + {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT540M, "NVIDIA GeForce GT 540M", DRIVER_NVIDIA_GEFORCE6, 1024}, + {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX550, "NVIDIA GeForce GTX 550 Ti", DRIVER_NVIDIA_GEFORCE6, 1024}, + {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT555M, "NVIDIA GeForce GT 555M", DRIVER_NVIDIA_GEFORCE6, 1024}, + {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX560TI, "NVIDIA GeForce GTX 560 Ti", DRIVER_NVIDIA_GEFORCE6, 1024}, + {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX560, "NVIDIA GeForce GTX 560", DRIVER_NVIDIA_GEFORCE6, 1024}, {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX570, "NVIDIA GeForce GTX 570", DRIVER_NVIDIA_GEFORCE6, 1280}, {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX580, "NVIDIA GeForce GTX 580", DRIVER_NVIDIA_GEFORCE6, 1536}, @@ -1099,18 +1150,49 @@ static const struct gpu_description gpu_description_table[] = {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5700, "ATI Radeon HD 5700 Series", DRIVER_AMD_R600, 512 }, {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5800, "ATI Radeon HD 5800 Series", DRIVER_AMD_R600, 1024}, {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5900, "ATI Radeon HD 5900 Series", DRIVER_AMD_R600, 1024}, - {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6310, "AMD Radeon HD 6310 Graphics", DRIVER_AMD_R600, 1024}, + {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6300, "AMD Radeon HD 6300 series Graphics", DRIVER_AMD_R600, 1024}, + {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6400, "AMD Radeon HD 6400 Series", DRIVER_AMD_R600, 1024}, + {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6410D, "AMD Radeon HD 6410D", DRIVER_AMD_R600, 1024}, + {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6550D, "AMD Radeon HD 6550D", DRIVER_AMD_R600, 1024}, + {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6600, "AMD Radeon HD 6600 Series", DRIVER_AMD_R600, 1024}, + {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6600M, "AMD Radeon HD 6600M Series", DRIVER_AMD_R600, 512 }, {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6800, "AMD Radeon HD 6800 Series", DRIVER_AMD_R600, 1024}, {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6900, "AMD Radeon HD 6900 Series", DRIVER_AMD_R600, 2048}, /* Intel cards */ - {HW_VENDOR_INTEL, CARD_INTEL_I830G, "Intel(R) 82830M Graphics Controller", DRIVER_INTEL_GMA800, 32 }, - {HW_VENDOR_INTEL, CARD_INTEL_I855G, "Intel(R) 82852/82855 GM/GME Graphics Controller", DRIVER_INTEL_GMA800, 32 }, - {HW_VENDOR_INTEL, CARD_INTEL_I865G, "Intel(R) 82865G Graphics Controller", DRIVER_INTEL_GMA800, 32 }, - {HW_VENDOR_INTEL, CARD_INTEL_I915G, "Intel(R) 82915G/GV/910GL Express Chipset Family", DRIVER_INTEL_GMA900, 64 }, - {HW_VENDOR_INTEL, CARD_INTEL_I915GM, "Mobile Intel(R) 915GM/GMS,910GML Express Chipset Family", DRIVER_INTEL_GMA900, 64 }, - {HW_VENDOR_INTEL, CARD_INTEL_I945GM, "Mobile Intel(R) 945GM Express Chipset Family", DRIVER_INTEL_GMA950, 64 }, - {HW_VENDOR_INTEL, CARD_INTEL_X3100, "Mobile Intel(R) 965 Express Chipset Family", DRIVER_INTEL_GMA3000, 128}, - {HW_VENDOR_INTEL, CARD_INTEL_GM45, "Mobile Intel(R) GM45 Express Chipset Family", DRIVER_INTEL_GMA3000, 512} + {HW_VENDOR_INTEL, CARD_INTEL_830M, "Intel(R) 82830M Graphics Controller", DRIVER_INTEL_GMA800, 32 }, + {HW_VENDOR_INTEL, CARD_INTEL_855GM, "Intel(R) 82852/82855 GM/GME Graphics Controller", DRIVER_INTEL_GMA800, 32 }, + {HW_VENDOR_INTEL, CARD_INTEL_845G, "Intel(R) 845G", DRIVER_INTEL_GMA800, 32 }, + {HW_VENDOR_INTEL, CARD_INTEL_865G, "Intel(R) 82865G Graphics Controller", DRIVER_INTEL_GMA800, 32 }, + {HW_VENDOR_INTEL, CARD_INTEL_915G, "Intel(R) 82915G/GV/910GL Express Chipset Family", DRIVER_INTEL_GMA900, 64 }, + {HW_VENDOR_INTEL, CARD_INTEL_E7221G, "Intel(R) E7221G", DRIVER_INTEL_GMA900, 64 }, + {HW_VENDOR_INTEL, CARD_INTEL_915GM, "Mobile Intel(R) 915GM/GMS,910GML Express Chipset Family", DRIVER_INTEL_GMA900, 64 }, + {HW_VENDOR_INTEL, CARD_INTEL_945G, "Intel(R) 945G", DRIVER_INTEL_GMA950, 64 }, + {HW_VENDOR_INTEL, CARD_INTEL_945GM, "Mobile Intel(R) 945GM Express Chipset Family", DRIVER_INTEL_GMA950, 64 }, + {HW_VENDOR_INTEL, CARD_INTEL_945GME, "Intel(R) 945GME", DRIVER_INTEL_GMA950, 64 }, + {HW_VENDOR_INTEL, CARD_INTEL_Q35, "Intel(R) Q35", DRIVER_INTEL_GMA950, 64 }, + {HW_VENDOR_INTEL, CARD_INTEL_G33, "Intel(R) G33", DRIVER_INTEL_GMA950, 64 }, + {HW_VENDOR_INTEL, CARD_INTEL_Q33, "Intel(R) Q33", DRIVER_INTEL_GMA950, 64 }, + {HW_VENDOR_INTEL, CARD_INTEL_PNVG, "Intel(R) IGD", DRIVER_INTEL_GMA950, 64 }, + {HW_VENDOR_INTEL, CARD_INTEL_PNVM, "Intel(R) IGD", DRIVER_INTEL_GMA950, 64 }, + {HW_VENDOR_INTEL, CARD_INTEL_965Q, "Intel(R) 965Q", DRIVER_INTEL_GMA3000, 128}, + {HW_VENDOR_INTEL, CARD_INTEL_965G, "Intel(R) 965G", DRIVER_INTEL_GMA3000, 128}, + {HW_VENDOR_INTEL, CARD_INTEL_946GZ, "Intel(R) 946GZ", DRIVER_INTEL_GMA3000, 128}, + {HW_VENDOR_INTEL, CARD_INTEL_965GM, "Mobile Intel(R) 965 Express Chipset Family", DRIVER_INTEL_GMA3000, 128}, + {HW_VENDOR_INTEL, CARD_INTEL_965GME, "Intel(R) 965GME", DRIVER_INTEL_GMA3000, 128}, + {HW_VENDOR_INTEL, CARD_INTEL_GM45, "Mobile Intel(R) GM45 Express Chipset Family", DRIVER_INTEL_GMA3000, 512}, + {HW_VENDOR_INTEL, CARD_INTEL_IGD, "Intel(R) Integrated Graphics Device", DRIVER_INTEL_GMA3000, 512}, + {HW_VENDOR_INTEL, CARD_INTEL_G45, "Intel(R) G45/G43", DRIVER_INTEL_GMA3000, 512}, + {HW_VENDOR_INTEL, CARD_INTEL_Q45, "Intel(R) Q45/Q43", DRIVER_INTEL_GMA3000, 512}, + {HW_VENDOR_INTEL, CARD_INTEL_G41, "Intel(R) G41", DRIVER_INTEL_GMA3000, 512}, + {HW_VENDOR_INTEL, CARD_INTEL_B43, "Intel(R) B43", DRIVER_INTEL_GMA3000, 512}, + {HW_VENDOR_INTEL, CARD_INTEL_ILKD, "Intel(R) Ironlake Desktop", DRIVER_INTEL_GMA3000, 1024}, + {HW_VENDOR_INTEL, CARD_INTEL_ILKM, "Intel(R) Ironlake Mobile", DRIVER_INTEL_GMA3000, 1024}, + {HW_VENDOR_INTEL, CARD_INTEL_SNBD, "Intel(R) Sandybridge Desktop", DRIVER_INTEL_GMA3000, 1024}, + {HW_VENDOR_INTEL, CARD_INTEL_SNBM, "Intel(R) Sandybridge Mobile", DRIVER_INTEL_GMA3000, 1024}, + {HW_VENDOR_INTEL, CARD_INTEL_SNBS, "Intel(R) Sandybridge Server", DRIVER_INTEL_GMA3000, 1024}, + {HW_VENDOR_INTEL, CARD_INTEL_IVBD, "Intel(R) Ivybridge Desktop", DRIVER_INTEL_GMA3000, 1024}, + {HW_VENDOR_INTEL, CARD_INTEL_IVBM, "Intel(R) Ivybridge Mobile", DRIVER_INTEL_GMA3000, 1024}, + {HW_VENDOR_INTEL, CARD_INTEL_IVBS, "Intel(R) Ivybridge Server", DRIVER_INTEL_GMA3000, 1024}, }; static const struct driver_version_information *get_driver_version_info(enum wined3d_display_driver driver, @@ -1316,7 +1398,8 @@ static DWORD wined3d_parse_gl_version(const char *gl_version) return MAKEDWORD_VERSION(major, minor); } -static enum wined3d_gl_vendor wined3d_guess_gl_vendor(struct wined3d_gl_info *gl_info, const char *gl_vendor_string, const char *gl_renderer) +static enum wined3d_gl_vendor wined3d_guess_gl_vendor(const struct wined3d_gl_info *gl_info, + const char *gl_vendor_string, const char *gl_renderer) { /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from @@ -1384,6 +1467,7 @@ static enum wined3d_pci_vendor wined3d_guess_card_vendor(const char *gl_vendor_s if (strstr(gl_vendor_string, "Intel(R)") /* Intel switched from Intel(R) to Intel® recently, so just match Intel. */ || strstr(gl_renderer, "Intel") + || strstr(gl_renderer, "i915") || strstr(gl_vendor_string, "Intel Inc.")) return HW_VENDOR_INTEL; @@ -1398,14 +1482,35 @@ static enum wined3d_pci_vendor wined3d_guess_card_vendor(const char *gl_vendor_s return HW_VENDOR_NVIDIA; } +static UINT d3d_level_from_gl_info(const struct wined3d_gl_info *gl_info) +{ + UINT level = 0; + if (gl_info->supported[ARB_MULTITEXTURE]) + level = 6; + if (gl_info->supported[ARB_TEXTURE_COMPRESSION] + && gl_info->supported[ARB_TEXTURE_CUBE_MAP] + && gl_info->supported[ARB_TEXTURE_ENV_DOT3]) + level = 7; + if (level == 7 && gl_info->supported[ARB_MULTISAMPLE] + && gl_info->supported[ARB_TEXTURE_BORDER_CLAMP]) + level = 8; + if (level == 8 && gl_info->supported[ARB_FRAGMENT_PROGRAM] + && gl_info->supported[ARB_VERTEX_SHADER]) + level = 9; + if (level == 9 && gl_info->supported[EXT_GPU_SHADER4]) + level = 10; + + return level; +} static enum wined3d_pci_device select_card_nvidia_binary(const struct wined3d_gl_info *gl_info, const char *gl_renderer) { + UINT d3d_level = d3d_level_from_gl_info(gl_info); unsigned int i; - if (WINE_D3D10_CAPABLE(gl_info)) + if (d3d_level >= 10) { static const struct { @@ -1416,10 +1521,15 @@ static enum wined3d_pci_device select_card_nvidia_binary(const struct wined3d_gl { {"GTX 580", CARD_NVIDIA_GEFORCE_GTX580}, /* Geforce 500 - highend */ {"GTX 570", CARD_NVIDIA_GEFORCE_GTX570}, /* Geforce 500 - midend high */ - {"GTX 560 TI", CARD_NVIDIA_GEFORCE_GTX560}, /* Geforce 500 - midend */ + {"GTX 560 Ti", CARD_NVIDIA_GEFORCE_GTX560TI}, /* Geforce 500 - midend */ + {"GTX 560", CARD_NVIDIA_GEFORCE_GTX560}, /* Geforce 500 - midend */ + {"GT 555M", CARD_NVIDIA_GEFORCE_GT555M}, /* Geforce 500 - midend mobile */ + {"GTX 550 Ti", CARD_NVIDIA_GEFORCE_GTX550}, /* Geforce 500 - midend */ + {"GT 540M", CARD_NVIDIA_GEFORCE_GT540M}, /* Geforce 500 - midend mobile */ {"GTX 480", CARD_NVIDIA_GEFORCE_GTX480}, /* Geforce 400 - highend */ {"GTX 470", CARD_NVIDIA_GEFORCE_GTX470}, /* Geforce 400 - midend high */ {"GTX 465", CARD_NVIDIA_GEFORCE_GTX465}, /* Geforce 400 - midend */ + {"GTX 460M", CARD_NVIDIA_GEFORCE_GTX460M}, /* Geforce 400 - highend mobile */ {"GTX 460", CARD_NVIDIA_GEFORCE_GTX460}, /* Geforce 400 - midend */ {"GTS 450", CARD_NVIDIA_GEFORCE_GTS450}, /* Geforce 400 - midend low */ {"GT 440", CARD_NVIDIA_GEFORCE_GT440}, /* Geforce 400 - lowend */ @@ -1480,7 +1590,7 @@ static enum wined3d_pci_device select_card_nvidia_binary(const struct wined3d_gl /* Both the GeforceFX, 6xxx and 7xxx series support D3D9. The last two types have more * shader capabilities, so we use the shader capabilities to distinguish between FX and 6xxx/7xxx. */ - if (WINE_D3D9_CAPABLE(gl_info) && gl_info->supported[NV_VERTEX_PROGRAM3]) + if (d3d_level >= 9 && gl_info->supported[NV_VERTEX_PROGRAM3]) { static const struct { @@ -1514,7 +1624,7 @@ static enum wined3d_pci_device select_card_nvidia_binary(const struct wined3d_gl return CARD_NVIDIA_GEFORCE_6200; /* Geforce 6100/6150/6200/7300/7400/7500 */ } - if (WINE_D3D9_CAPABLE(gl_info)) + if (d3d_level >= 9) { /* GeforceFX - highend */ if (strstr(gl_renderer, "5800") @@ -1538,7 +1648,7 @@ static enum wined3d_pci_device select_card_nvidia_binary(const struct wined3d_gl return CARD_NVIDIA_GEFORCEFX_5200; /* GeforceFX 5100/5200/5250/5300/5500 */ } - if (WINE_D3D8_CAPABLE(gl_info)) + if (d3d_level >= 8) { if (strstr(gl_renderer, "GeForce4 Ti") || strstr(gl_renderer, "Quadro4")) { @@ -1548,7 +1658,7 @@ static enum wined3d_pci_device select_card_nvidia_binary(const struct wined3d_gl return CARD_NVIDIA_GEFORCE3; /* Geforce3 standard/Ti200/Ti500, Quadro DCC */ } - if (WINE_D3D7_CAPABLE(gl_info)) + if (d3d_level >= 7) { if (strstr(gl_renderer, "GeForce4 MX")) { @@ -1579,11 +1689,13 @@ static enum wined3d_pci_device select_card_nvidia_binary(const struct wined3d_gl static enum wined3d_pci_device select_card_amd_binary(const struct wined3d_gl_info *gl_info, const char *gl_renderer) { + UINT d3d_level = d3d_level_from_gl_info(gl_info); + /* See http://developer.amd.com/drivers/pc_vendor_id/Pages/default.aspx * * Beware: renderer string do not match exact card model, * eg HD 4800 is returned for multiple cards, even for RV790 based ones. */ - if (WINE_D3D10_CAPABLE(gl_info)) + if (d3d_level >= 10) { unsigned int i; @@ -1594,6 +1706,17 @@ static enum wined3d_pci_device select_card_amd_binary(const struct wined3d_gl_in } cards[] = { + /* Northern Islands */ + {"HD 6900", CARD_AMD_RADEON_HD6900}, + {"HD 6800", CARD_AMD_RADEON_HD6800}, + {"HD 6630M",CARD_AMD_RADEON_HD6600M}, + {"HD 6600M",CARD_AMD_RADEON_HD6600M}, + {"HD 6600", CARD_AMD_RADEON_HD6600}, + {"HD 6500M",CARD_AMD_RADEON_HD6600M}, + {"HD 6500", CARD_AMD_RADEON_HD6600}, + {"HD 6400", CARD_AMD_RADEON_HD6400}, + {"HD 6300", CARD_AMD_RADEON_HD6300}, + {"HD 6200", CARD_AMD_RADEON_HD6300}, /* Evergreen */ {"HD 5870", CARD_AMD_RADEON_HD5800}, /* Radeon EG CYPRESS PRO */ {"HD 5850", CARD_AMD_RADEON_HD5800}, /* Radeon EG CYPRESS XT */ @@ -1648,7 +1771,7 @@ static enum wined3d_pci_device select_card_amd_binary(const struct wined3d_gl_in return CARD_AMD_RADEON_HD3200; } - if (WINE_D3D8_CAPABLE(gl_info)) + if (d3d_level >= 9) { /* Radeon R5xx */ if (strstr(gl_renderer, "X1600") @@ -1687,15 +1810,11 @@ static enum wined3d_pci_device select_card_amd_binary(const struct wined3d_gl_in return CARD_AMD_RADEON_9500; /* Radeon 9500/9550/9600/9700/9800/X300/X550/X600 */ } - if (WINE_D3D8_CAPABLE(gl_info)) - { + if (d3d_level >= 8) return CARD_AMD_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */ - } - if (WINE_D3D7_CAPABLE(gl_info)) - { + if (d3d_level >= 7) return CARD_AMD_RADEON_7200; /* Radeon 7000/7100/7200/7500 */ - } return CARD_AMD_RAGE_128PRO; } @@ -1703,31 +1822,75 @@ static enum wined3d_pci_device select_card_amd_binary(const struct wined3d_gl_in static enum wined3d_pci_device select_card_intel(const struct wined3d_gl_info *gl_info, const char *gl_renderer) { - if (strstr(gl_renderer, "GM45")) return CARD_INTEL_GM45; - if (strstr(gl_renderer, "X3100") || strstr(gl_renderer, "965GM")) + unsigned int i; + + static const struct { - /* MacOS calls the card GMA X3100, otherwise known as GM965/GL960 */ - return CARD_INTEL_X3100; + const char *renderer; + enum wined3d_pci_device id; + } + cards[] = + { + /* Ivybridge */ + {"Ivybridge Server", CARD_INTEL_IVBS}, + {"Ivybridge Mobile", CARD_INTEL_IVBM}, + {"Ivybridge Desktop", CARD_INTEL_IVBD}, + /* Sandybridge */ + {"Sandybridge Server", CARD_INTEL_SNBS}, + {"Sandybridge Mobile", CARD_INTEL_SNBM}, + {"Sandybridge Desktop", CARD_INTEL_SNBD}, + /* Ironlake */ + {"Ironlake Mobile", CARD_INTEL_ILKM}, + {"Ironlake Desktop", CARD_INTEL_ILKD}, + /* G4x */ + {"B43", CARD_INTEL_B43}, + {"G41", CARD_INTEL_G41}, + {"G45", CARD_INTEL_G45}, + {"Q45", CARD_INTEL_Q45}, + {"Integrated Graphics Device", CARD_INTEL_IGD}, + {"GM45", CARD_INTEL_GM45}, + /* i965 */ + {"965GME", CARD_INTEL_965GME}, + {"965GM", CARD_INTEL_965GM}, + {"X3100", CARD_INTEL_965GM}, /* MacOS */ + {"946GZ", CARD_INTEL_946GZ}, + {"965G", CARD_INTEL_965G}, + {"965Q", CARD_INTEL_965Q}, + /* i945 */ + {"Pineview M", CARD_INTEL_PNVM}, + {"Pineview G", CARD_INTEL_PNVG}, + {"IGD", CARD_INTEL_PNVG}, + {"Q33", CARD_INTEL_Q33}, + {"G33", CARD_INTEL_G33}, + {"Q35", CARD_INTEL_Q35}, + {"945GME", CARD_INTEL_945GME}, + {"945GM", CARD_INTEL_945GM}, + {"GMA 950", CARD_INTEL_945GM}, /* MacOS */ + {"945G", CARD_INTEL_945G}, + /* i915 */ + {"915GM", CARD_INTEL_915GM}, + {"E7221G", CARD_INTEL_E7221G}, + {"915G", CARD_INTEL_915G}, + /* i8xx */ + {"865G", CARD_INTEL_865G}, + {"845G", CARD_INTEL_845G}, + {"855GM", CARD_INTEL_855GM}, + {"830M", CARD_INTEL_830M}, + }; + + for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i) + { + if (strstr(gl_renderer, cards[i].renderer)) + return cards[i].id; } - if (strstr(gl_renderer, "GMA 950") || strstr(gl_renderer, "945GM")) - { - /* MacOS calls the card GMA 950, but everywhere else the PCI ID is named 945GM */ - return CARD_INTEL_I945GM; - } - - if (strstr(gl_renderer, "915GM")) return CARD_INTEL_I915GM; - if (strstr(gl_renderer, "915G")) return CARD_INTEL_I915G; - if (strstr(gl_renderer, "865G")) return CARD_INTEL_I865G; - if (strstr(gl_renderer, "855G")) return CARD_INTEL_I855G; - if (strstr(gl_renderer, "830G")) return CARD_INTEL_I830G; - return CARD_INTEL_I915G; - + return CARD_INTEL_915G; } static enum wined3d_pci_device select_card_amd_mesa(const struct wined3d_gl_info *gl_info, const char *gl_renderer) { + UINT d3d_level; unsigned int i; /* See http://developer.amd.com/drivers/pc_vendor_id/Pages/default.aspx @@ -1750,7 +1913,11 @@ static enum wined3d_pci_device select_card_amd_mesa(const struct wined3d_gl_info /* Northern Islands */ {"CAYMAN", CARD_AMD_RADEON_HD6900}, {"BARTS", CARD_AMD_RADEON_HD6800}, - {"PALM", CARD_AMD_RADEON_HD6310}, + {"TURKS", CARD_AMD_RADEON_HD6600}, + {"SUMO2", CARD_AMD_RADEON_HD6410D}, /* SUMO2 first, because we do a strstr(). */ + {"SUMO", CARD_AMD_RADEON_HD6550D}, + {"CAICOS", CARD_AMD_RADEON_HD6400}, + {"PALM", CARD_AMD_RADEON_HD6300}, /* Evergreen */ {"HEMLOCK", CARD_AMD_RADEON_HD5900}, {"CYPRESS", CARD_AMD_RADEON_HD5800}, @@ -1817,7 +1984,11 @@ static enum wined3d_pci_device select_card_amd_mesa(const struct wined3d_gl_info } } - if (WINE_D3D9_CAPABLE(gl_info)) + d3d_level = d3d_level_from_gl_info(gl_info); + if (d3d_level >= 10) + return CARD_AMD_RADEON_HD2600; + + if (d3d_level >= 9) { static const struct { @@ -1851,17 +2022,15 @@ static enum wined3d_pci_device select_card_amd_mesa(const struct wined3d_gl_info if (strstr(gl_renderer, cards[i].renderer)) return cards[i].id; } + + return CARD_AMD_RADEON_9500; } - if (WINE_D3D8_CAPABLE(gl_info)) - { + if (d3d_level >= 8) return CARD_AMD_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */ - } - if (WINE_D3D7_CAPABLE(gl_info)) - { + if (d3d_level >= 7) return CARD_AMD_RADEON_7200; /* Radeon 7000/7100/7200/7500 */ - } return CARD_AMD_RAGE_128PRO; } @@ -1869,6 +2038,8 @@ static enum wined3d_pci_device select_card_amd_mesa(const struct wined3d_gl_info static enum wined3d_pci_device select_card_nvidia_mesa(const struct wined3d_gl_info *gl_info, const char *gl_renderer) { + UINT d3d_level; + if (strstr(gl_renderer, "Gallium")) { unsigned int i; @@ -1944,10 +2115,16 @@ static enum wined3d_pci_device select_card_nvidia_mesa(const struct wined3d_gl_i } FIXME_(d3d_caps)("Unknown renderer %s.\n", debugstr_a(gl_renderer)); - if (WINE_D3D9_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCEFX_5600; - if (WINE_D3D8_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCE3; - if (WINE_D3D7_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCE; - if (WINE_D3D6_CAPABLE(gl_info)) return CARD_NVIDIA_RIVA_TNT; + + d3d_level = d3d_level_from_gl_info(gl_info); + if (d3d_level >= 9) + return CARD_NVIDIA_GEFORCEFX_5600; + if (d3d_level >= 8) + return CARD_NVIDIA_GEFORCE3; + if (d3d_level >= 7) + return CARD_NVIDIA_GEFORCE; + if (d3d_level >= 6) + return CARD_NVIDIA_RIVA_TNT; return CARD_NVIDIA_RIVA_128; } @@ -1977,6 +2154,8 @@ static const struct vendor_card_selection vendor_card_select_table[] = static enum wined3d_pci_device wined3d_guess_card(const struct wined3d_gl_info *gl_info, const char *gl_renderer, enum wined3d_gl_vendor *gl_vendor, enum wined3d_pci_vendor *card_vendor) { + UINT d3d_level; + /* Above is a list of Nvidia and ATI GPUs. Both vendors have dozens of * different GPUs with roughly the same features. In most cases GPUs from a * certain family differ in clockspeeds, the amount of video memory and the @@ -2043,23 +2222,27 @@ static enum wined3d_pci_device wined3d_guess_card(const struct wined3d_gl_info * return vendor_card_select_table[i].select_card(gl_info, gl_renderer); } - FIXME_(d3d_caps)("No card selector available for GL vendor %d and card vendor %04x.\n", - *gl_vendor, *card_vendor); + FIXME_(d3d_caps)("No card selector available for GL vendor %#x and card vendor %04x (using GL_RENDERER %s).\n", + *gl_vendor, *card_vendor, debugstr_a(gl_renderer)); /* Default to generic Nvidia hardware based on the supported OpenGL extensions. The choice * for Nvidia was because the hardware and drivers they make are of good quality. This makes * them a good generic choice. */ *card_vendor = HW_VENDOR_NVIDIA; - if (WINE_D3D9_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCEFX_5600; - if (WINE_D3D8_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCE3; - if (WINE_D3D7_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCE; - if (WINE_D3D6_CAPABLE(gl_info)) return CARD_NVIDIA_RIVA_TNT; + d3d_level = d3d_level_from_gl_info(gl_info); + if (d3d_level >= 9) + return CARD_NVIDIA_GEFORCEFX_5600; + if (d3d_level >= 8) + return CARD_NVIDIA_GEFORCE3; + if (d3d_level >= 7) + return CARD_NVIDIA_GEFORCE; + if (d3d_level >= 6) + return CARD_NVIDIA_RIVA_TNT; return CARD_NVIDIA_RIVA_128; } -static const struct fragment_pipeline *select_fragment_implementation(struct wined3d_adapter *adapter) +static const struct fragment_pipeline *select_fragment_implementation(const struct wined3d_gl_info *gl_info) { - const struct wined3d_gl_info *gl_info = &adapter->gl_info; int vs_selected_mode, ps_selected_mode; select_shader_mode(gl_info, &ps_selected_mode, &vs_selected_mode); @@ -2072,19 +2255,18 @@ static const struct fragment_pipeline *select_fragment_implementation(struct win else return &ffp_fragment_pipeline; } -static const struct wined3d_shader_backend_ops *select_shader_backend(struct wined3d_adapter *adapter) +static const struct wined3d_shader_backend_ops *select_shader_backend(const struct wined3d_gl_info *gl_info) { int vs_selected_mode, ps_selected_mode; - select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode); + select_shader_mode(gl_info, &ps_selected_mode, &vs_selected_mode); if (vs_selected_mode == SHADER_GLSL || ps_selected_mode == SHADER_GLSL) return &glsl_shader_backend; if (vs_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_ARB) return &arb_program_shader_backend; return &none_shader_backend; } -static const struct blit_shader *select_blit_implementation(struct wined3d_adapter *adapter) +static const struct blit_shader *select_blit_implementation(const struct wined3d_gl_info *gl_info) { - const struct wined3d_gl_info *gl_info = &adapter->gl_info; int vs_selected_mode, ps_selected_mode; select_shader_mode(gl_info, &ps_selected_mode, &vs_selected_mode); @@ -2111,7 +2293,7 @@ static void load_gl_funcs(struct wined3d_gl_info *gl_info, DWORD gl_version) } /* Context activation is done by the caller. */ -static BOOL IWineD3DImpl_FillGLCaps(struct wined3d_adapter *adapter) +static BOOL wined3d_adapter_init_gl_caps(struct wined3d_adapter *adapter) { struct wined3d_driver_info *driver_info = &adapter->driver_info; struct wined3d_gl_info *gl_info = &adapter->gl_info; @@ -2170,10 +2352,12 @@ static BOOL IWineD3DImpl_FillGLCaps(struct wined3d_adapter *adapter) gl_info->limits.blends = 1; gl_info->limits.buffers = 1; gl_info->limits.textures = 1; + gl_info->limits.texture_coords = 1; gl_info->limits.fragment_samplers = 1; gl_info->limits.vertex_samplers = 0; gl_info->limits.combined_samplers = gl_info->limits.fragment_samplers + gl_info->limits.vertex_samplers; gl_info->limits.sampler_stages = 1; + gl_info->limits.vertex_attribs = 16; gl_info->limits.glsl_vs_float_constants = 0; gl_info->limits.glsl_ps_float_constants = 0; gl_info->limits.arb_vs_float_constants = 0; @@ -2330,6 +2514,15 @@ static BOOL IWineD3DImpl_FillGLCaps(struct wined3d_adapter *adapter) } } + if (gl_info->supported[ARB_MAP_BUFFER_ALIGNMENT]) + { + glGetIntegerv(GL_MIN_MAP_BUFFER_ALIGNMENT, &gl_max); + TRACE_(d3d_caps)("Minimum buffer map alignment: %d.\n", gl_max); + } + else + { + WARN_(d3d_caps)("Driver doesn't guarantee a minimum buffer map alignment.\n"); + } if (gl_info->supported[NV_REGISTER_COMBINERS]) { glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &gl_max); @@ -2347,6 +2540,9 @@ static BOOL IWineD3DImpl_FillGLCaps(struct wined3d_adapter *adapter) glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max); gl_info->limits.textures = min(MAX_TEXTURES, gl_max); TRACE_(d3d_caps)("Max textures: %d.\n", gl_info->limits.textures); + glGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, &gl_max); + gl_info->limits.texture_coords = min(MAX_TEXTURES, gl_max); + TRACE_(d3d_caps)("Max texture coords: %d.\n", gl_info->limits.texture_coords); if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) { @@ -2367,6 +2563,8 @@ static BOOL IWineD3DImpl_FillGLCaps(struct wined3d_adapter *adapter) gl_info->limits.vertex_samplers = tmp; glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp); gl_info->limits.combined_samplers = tmp; + glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &tmp); + gl_info->limits.vertex_attribs = tmp; /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup * is known at shader link time. In a vertex shader + pixel shader combination this isn't @@ -2514,21 +2712,13 @@ static BOOL IWineD3DImpl_FillGLCaps(struct wined3d_adapter *adapter) /* GL_ARB_half_float_vertex is a subset of GL_NV_half_float. */ gl_info->supported[ARB_HALF_FLOAT_VERTEX] = TRUE; } - if (gl_info->supported[ARB_POINT_SPRITE]) - { - gl_info->limits.point_sprite_units = gl_info->limits.textures; - } - else - { - gl_info->limits.point_sprite_units = 0; - } checkGLcall("extension detection"); LEAVE_GL(); - adapter->fragment_pipe = select_fragment_implementation(adapter); - adapter->shader_backend = select_shader_backend(adapter); - adapter->blitter = select_blit_implementation(adapter); + adapter->fragment_pipe = select_fragment_implementation(gl_info); + adapter->shader_backend = select_shader_backend(gl_info); + adapter->blitter = select_blit_implementation(gl_info); adapter->fragment_pipe->get_caps(gl_info, &fragment_caps); gl_info->limits.texture_stages = fragment_caps.MaxTextureBlendStages; @@ -2560,6 +2750,11 @@ static BOOL IWineD3DImpl_FillGLCaps(struct wined3d_adapter *adapter) gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv = gl_info->glGetFramebufferAttachmentParameteriv; gl_info->fbo_ops.glBlitFramebuffer = gl_info->glBlitFramebuffer; gl_info->fbo_ops.glGenerateMipmap = gl_info->glGenerateMipmap; + if (wined3d_settings.allow_multisampling) + { + glGetIntegerv(GL_MAX_SAMPLES, &gl_max); + gl_info->limits.samples = gl_max; + } } else { @@ -2595,6 +2790,11 @@ static BOOL IWineD3DImpl_FillGLCaps(struct wined3d_adapter *adapter) if (gl_info->supported[EXT_FRAMEBUFFER_MULTISAMPLE]) { gl_info->fbo_ops.glRenderbufferStorageMultisample = gl_info->glRenderbufferStorageMultisampleEXT; + if (wined3d_settings.allow_multisampling) + { + glGetIntegerv(GL_MAX_SAMPLES, &gl_max); + gl_info->limits.samples = gl_max; + } } } @@ -2611,13 +2811,13 @@ static BOOL IWineD3DImpl_FillGLCaps(struct wined3d_adapter *adapter) device = wined3d_guess_card(gl_info, gl_renderer_str, &gl_vendor, &card_vendor); TRACE_(d3d_caps)("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", card_vendor, device); - gl_info->wrap_lookup[WINED3DTADDRESS_WRAP - WINED3DTADDRESS_WRAP] = GL_REPEAT; - gl_info->wrap_lookup[WINED3DTADDRESS_MIRROR - WINED3DTADDRESS_WRAP] = + gl_info->wrap_lookup[WINED3D_TADDRESS_WRAP - WINED3D_TADDRESS_WRAP] = GL_REPEAT; + gl_info->wrap_lookup[WINED3D_TADDRESS_MIRROR - WINED3D_TADDRESS_WRAP] = gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT; - gl_info->wrap_lookup[WINED3DTADDRESS_CLAMP - WINED3DTADDRESS_WRAP] = GL_CLAMP_TO_EDGE; - gl_info->wrap_lookup[WINED3DTADDRESS_BORDER - WINED3DTADDRESS_WRAP] = + gl_info->wrap_lookup[WINED3D_TADDRESS_CLAMP - WINED3D_TADDRESS_WRAP] = GL_CLAMP_TO_EDGE; + gl_info->wrap_lookup[WINED3D_TADDRESS_BORDER - WINED3D_TADDRESS_WRAP] = gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT; - gl_info->wrap_lookup[WINED3DTADDRESS_MIRRORONCE - WINED3DTADDRESS_WRAP] = + gl_info->wrap_lookup[WINED3D_TADDRESS_MIRROR_ONCE - WINED3D_TADDRESS_WRAP] = gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT; /* Make sure there's an active HDC else the WGL extensions will fail */ @@ -2752,7 +2952,7 @@ UINT CDECL wined3d_get_adapter_mode_count(const struct wined3d *wined3d, UINT ad /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */ HRESULT CDECL wined3d_enum_adapter_modes(const struct wined3d *wined3d, UINT adapter_idx, - enum wined3d_format_id format_id, UINT mode_idx, WINED3DDISPLAYMODE *mode) + enum wined3d_format_id format_id, UINT mode_idx, struct wined3d_display_mode *mode) { TRACE_(d3d_caps)("wined3d %p, adapter_idx %u, format %s, mode_idx %u, mode %p.\n", wined3d, adapter_idx, debug_d3dformat(format_id), mode_idx, mode); @@ -2803,16 +3003,16 @@ HRESULT CDECL wined3d_enum_adapter_modes(const struct wined3d *wined3d, UINT ada /* Now get the display mode via the calculated index */ if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0)) { - mode->Width = DevModeW.dmPelsWidth; - mode->Height = DevModeW.dmPelsHeight; - mode->RefreshRate = DEFAULT_REFRESH_RATE; + mode->width = DevModeW.dmPelsWidth; + mode->height = DevModeW.dmPelsHeight; + mode->refresh_rate = DEFAULT_REFRESH_RATE; if (DevModeW.dmFields & DM_DISPLAYFREQUENCY) - mode->RefreshRate = DevModeW.dmDisplayFrequency; + mode->refresh_rate = DevModeW.dmDisplayFrequency; if (format_id == WINED3DFMT_UNKNOWN) - mode->Format = pixelformat_for_depth(DevModeW.dmBitsPerPel); + mode->format_id = pixelformat_for_depth(DevModeW.dmBitsPerPel); else - mode->Format = format_id; + mode->format_id = format_id; } else { @@ -2821,8 +3021,8 @@ HRESULT CDECL wined3d_enum_adapter_modes(const struct wined3d *wined3d, UINT ada } TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n", - mode->Width, mode->Height, mode->RefreshRate, mode->Format, - debug_d3dformat(mode->Format), DevModeW.dmBitsPerPel); + mode->width, mode->height, mode->refresh_rate, mode->format_id, + debug_d3dformat(mode->format_id), DevModeW.dmBitsPerPel); } else { @@ -2833,7 +3033,7 @@ HRESULT CDECL wined3d_enum_adapter_modes(const struct wined3d *wined3d, UINT ada } HRESULT CDECL wined3d_get_adapter_display_mode(const struct wined3d *wined3d, UINT adapter_idx, - WINED3DDISPLAYMODE *mode) + struct wined3d_display_mode *mode) { TRACE("wined3d %p, adapter_idx %u, display_mode %p.\n", wined3d, adapter_idx, mode); @@ -2849,28 +3049,28 @@ HRESULT CDECL wined3d_get_adapter_display_mode(const struct wined3d *wined3d, UI DevModeW.dmSize = sizeof(DevModeW); EnumDisplaySettingsExW(NULL, ENUM_CURRENT_SETTINGS, &DevModeW, 0); - mode->Width = DevModeW.dmPelsWidth; - mode->Height = DevModeW.dmPelsHeight; + mode->width = DevModeW.dmPelsWidth; + mode->height = DevModeW.dmPelsHeight; bpp = DevModeW.dmBitsPerPel; - mode->RefreshRate = DEFAULT_REFRESH_RATE; - if (DevModeW.dmFields&DM_DISPLAYFREQUENCY) - mode->RefreshRate = DevModeW.dmDisplayFrequency; - mode->Format = pixelformat_for_depth(bpp); + mode->refresh_rate = DEFAULT_REFRESH_RATE; + if (DevModeW.dmFields & DM_DISPLAYFREQUENCY) + mode->refresh_rate = DevModeW.dmDisplayFrequency; + mode->format_id = pixelformat_for_depth(bpp); } else { FIXME_(d3d_caps)("Adapter not primary display\n"); } - TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", mode->Width, - mode->Height, mode->RefreshRate, debug_d3dformat(mode->Format)); + TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", mode->width, + mode->height, mode->refresh_rate, debug_d3dformat(mode->format_id)); return WINED3D_OK; } /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER, and fields being inserted in the middle, a new structure is used in place */ HRESULT CDECL wined3d_get_adapter_identifier(const struct wined3d *wined3d, - UINT adapter_idx, DWORD flags, WINED3DADAPTER_IDENTIFIER *identifier) + UINT adapter_idx, DWORD flags, struct wined3d_adapter_identifier *identifier) { const struct wined3d_adapter *adapter; size_t len; @@ -2932,14 +3132,11 @@ HRESULT CDECL wined3d_get_adapter_identifier(const struct wined3d *wined3d, return WINED3D_OK; } -static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(const struct wined3d_gl_info *gl_info, +static BOOL wined3d_check_pixel_format_color(const struct wined3d_gl_info *gl_info, const struct wined3d_pixel_format *cfg, const struct wined3d_format *format) { BYTE redSize, greenSize, blueSize, alphaSize, colorBits; - if(!cfg) - return FALSE; - /* Float formats need FBOs. If FBOs are used this function isn't called */ if (format->flags & WINED3DFMT_FLAG_FLOAT) return FALSE; @@ -2969,15 +3166,12 @@ static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(const struct wined return FALSE; } -static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(const struct wined3d_gl_info *gl_info, +static BOOL wined3d_check_pixel_format_depth(const struct wined3d_gl_info *gl_info, const struct wined3d_pixel_format *cfg, const struct wined3d_format *format) { BYTE depthSize, stencilSize; BOOL lockable = FALSE; - if(!cfg) - return FALSE; - if (!getDepthStencilBits(format, &depthSize, &stencilSize)) { ERR("Unable to check compatibility for format %s.\n", debug_d3dformat(format->id)); @@ -3005,7 +3199,7 @@ static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(const struct wined3 } HRESULT CDECL wined3d_check_depth_stencil_match(const struct wined3d *wined3d, - UINT adapter_idx, WINED3DDEVTYPE device_type, enum wined3d_format_id adapter_format_id, + UINT adapter_idx, enum wined3d_device_type device_type, enum wined3d_format_id adapter_format_id, enum wined3d_format_id render_target_format_id, enum wined3d_format_id depth_stencil_format_id) { const struct wined3d_format *rt_format; @@ -3039,16 +3233,14 @@ HRESULT CDECL wined3d_check_depth_stencil_match(const struct wined3d *wined3d, unsigned int i; cfgs = adapter->cfgs; - cfg_count = adapter->nCfgs; + cfg_count = adapter->cfg_count; for (i = 0; i < cfg_count; ++i) { - if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info, &cfgs[i], rt_format)) + if (wined3d_check_pixel_format_color(&adapter->gl_info, &cfgs[i], rt_format) + && wined3d_check_pixel_format_depth(&adapter->gl_info, &cfgs[i], ds_format)) { - if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, &cfgs[i], ds_format)) - { - TRACE_(d3d_caps)("Formats match.\n"); - return WINED3D_OK; - } + TRACE_(d3d_caps)("Formats match.\n"); + return WINED3D_OK; } } } @@ -3061,11 +3253,10 @@ HRESULT CDECL wined3d_check_depth_stencil_match(const struct wined3d *wined3d, } HRESULT CDECL wined3d_check_device_multisample_type(const struct wined3d *wined3d, UINT adapter_idx, - WINED3DDEVTYPE device_type, enum wined3d_format_id surface_format_id, BOOL windowed, - WINED3DMULTISAMPLE_TYPE multisample_type, DWORD *quality_levels) + enum wined3d_device_type device_type, enum wined3d_format_id surface_format_id, BOOL windowed, + enum wined3d_multisample_type multisample_type, DWORD *quality_levels) { - const struct wined3d_adapter *adapter; - const struct wined3d_format *format; + const struct wined3d_gl_info *gl_info; TRACE_(d3d_caps)("wined3d %p, adapter_idx %u, device_type %s, surface_format %s,\n" "windowed %#x, multisample_type %#x, quality_levels %p.\n", @@ -3075,88 +3266,27 @@ HRESULT CDECL wined3d_check_device_multisample_type(const struct wined3d *wined3 if (adapter_idx >= wined3d->adapter_count) return WINED3DERR_INVALIDCALL; - /* TODO: Handle windowed, add more quality levels. */ + gl_info = &wined3d->adapters[adapter_idx].gl_info; - if (WINED3DMULTISAMPLE_NONE == multisample_type) + if (multisample_type > gl_info->limits.samples) { - if (quality_levels) *quality_levels = 1; - return WINED3D_OK; - } + TRACE("Returning not supported.\n"); + if (quality_levels) + *quality_levels = 0; - /* By default multisampling is disabled right now as it causes issues - * on some Nvidia driver versions and it doesn't work well in combination - * with FBOs yet. */ - if (!wined3d_settings.allow_multisampling) return WINED3DERR_NOTAVAILABLE; - - adapter = &wined3d->adapters[adapter_idx]; - format = wined3d_get_format(&adapter->gl_info, surface_format_id); - if (!format) return WINED3DERR_INVALIDCALL; - - if (format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)) - { - const struct wined3d_pixel_format *cfgs; - unsigned int i, cfg_count; - - cfgs = adapter->cfgs; - cfg_count = adapter->nCfgs; - for (i = 0; i < cfg_count; ++i) - { - if(cfgs[i].numSamples != multisample_type) - continue; - - if (!IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, &cfgs[i], format)) - continue; - - TRACE("Found pixel format %u to support multisample_type %#x for format %s.\n", - cfgs[i].iPixelFormat, multisample_type, debug_d3dformat(surface_format_id)); - - if (quality_levels) *quality_levels = 1; - - return WINED3D_OK; - } } - else if (format->flags & WINED3DFMT_FLAG_RENDERTARGET) + + if (quality_levels) { - BYTE redSize, greenSize, blueSize, alphaSize, colorBits; - const struct wined3d_pixel_format *cfgs; - unsigned int i, cfg_count; - - if (!getColorBits(format, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits)) - { - ERR("Unable to get color bits for format %s, can't check multisampling capability.\n", - debug_d3dformat(surface_format_id)); - return WINED3DERR_NOTAVAILABLE; - } - - cfgs = adapter->cfgs; - cfg_count = adapter->nCfgs; - for (i = 0; i < cfg_count; ++i) - { - if(cfgs[i].numSamples != multisample_type) - continue; - if(cfgs[i].redSize != redSize) - continue; - if(cfgs[i].greenSize != greenSize) - continue; - if(cfgs[i].blueSize != blueSize) - continue; - /* Not all drivers report alpha-less formats since they use 32-bit - * anyway, so accept alpha even if we didn't ask for it. */ - if(alphaSize && cfgs[i].alphaSize != alphaSize) - continue; - if (cfgs[i].colorSize != (format->byte_count << 3)) - continue; - - TRACE("Found pixel format %u to support multisample_type %#x for format %s.\n", - cfgs[i].iPixelFormat, multisample_type, debug_d3dformat(surface_format_id)); - - if (quality_levels) *quality_levels = 1; - - return WINED3D_OK; - } + if (multisample_type == WINED3D_MULTISAMPLE_NON_MASKABLE) + /* FIXME: This is probably wrong. */ + *quality_levels = gl_info->limits.samples; + else + *quality_levels = 1; } - return WINED3DERR_NOTAVAILABLE; + + return WINED3D_OK; } /* Check if we support bumpmapping for a format */ @@ -3173,11 +3303,21 @@ static BOOL CheckBumpMapCapability(const struct wined3d_adapter *adapter, const static BOOL CheckDepthStencilCapability(const struct wined3d_adapter *adapter, const struct wined3d_format *display_format, const struct wined3d_format *ds_format) { - int it=0; - /* Only allow depth/stencil formats */ if (!(ds_format->depth_size || ds_format->stencil_size)) return FALSE; + /* Blacklist formats not supported on Windows */ + switch (ds_format->id) + { + case WINED3DFMT_S1_UINT_D15_UNORM: /* Breaks the shadowvol2 dx7 sdk sample */ + case WINED3DFMT_S4X4_UINT_D24_UNORM: + TRACE_(d3d_caps)("[FAILED] - not supported on windows\n"); + return FALSE; + + default: + break; + } + if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) { /* With FBOs WGL limitations do not apply, but the format needs to be FBO attachable */ @@ -3185,17 +3325,15 @@ static BOOL CheckDepthStencilCapability(const struct wined3d_adapter *adapter, } else { + unsigned int i; + /* Walk through all WGL pixel formats to find a match */ - for (it = 0; it < adapter->nCfgs; ++it) + for (i = 0; i < adapter->cfg_count; ++i) { - const struct wined3d_pixel_format *cfg = &adapter->cfgs[it]; - if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info, cfg, display_format)) - { - if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, cfg, ds_format)) - { - return TRUE; - } - } + const struct wined3d_pixel_format *cfg = &adapter->cfgs[i]; + if (wined3d_check_pixel_format_color(&adapter->gl_info, cfg, display_format) + && wined3d_check_pixel_format_depth(&adapter->gl_info, cfg, ds_format)) + return TRUE; } } @@ -3205,7 +3343,9 @@ static BOOL CheckDepthStencilCapability(const struct wined3d_adapter *adapter, static BOOL CheckFilterCapability(const struct wined3d_adapter *adapter, const struct wined3d_format *format) { /* The flags entry of a format contains the filtering capability */ - if (format->flags & WINED3DFMT_FLAG_FILTERING) return TRUE; + if ((format->flags & WINED3DFMT_FLAG_FILTERING) + || !(adapter->gl_info.quirks & WINED3D_QUIRK_LIMITED_TEX_FILTERING)) + return TRUE; return FALSE; } @@ -3221,7 +3361,7 @@ static BOOL CheckRenderTargetCapability(const struct wined3d_adapter *adapter, BYTE AdapterRed, AdapterGreen, AdapterBlue, AdapterAlpha, AdapterTotalSize; BYTE CheckRed, CheckGreen, CheckBlue, CheckAlpha, CheckTotalSize; const struct wined3d_pixel_format *cfgs = adapter->cfgs; - int it; + unsigned int i; getColorBits(adapter_format, &AdapterRed, &AdapterGreen, &AdapterBlue, &AdapterAlpha, &AdapterTotalSize); getColorBits(check_format, &CheckRed, &CheckGreen, &CheckBlue, &CheckAlpha, &CheckTotalSize); @@ -3235,13 +3375,13 @@ static BOOL CheckRenderTargetCapability(const struct wined3d_adapter *adapter, /* Check if there is a WGL pixel format matching the requirements, the format should also be window * drawable (not offscreen; e.g. Nvidia offers R5G6B5 for pbuffers even when X is running at 24bit) */ - for (it = 0; it < adapter->nCfgs; ++it) + for (i = 0; i < adapter->cfg_count; ++i) { - if (cfgs[it].windowDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info, - &cfgs[it], check_format)) + if (cfgs[i].windowDrawable + && wined3d_check_pixel_format_color(&adapter->gl_info, &cfgs[i], check_format)) { TRACE_(d3d_caps)("Pixel format %d is compatible with format %s.\n", - cfgs[it].iPixelFormat, debug_d3dformat(check_format->id)); + cfgs[i].iPixelFormat, debug_d3dformat(check_format->id)); return TRUE; } } @@ -3315,7 +3455,9 @@ static BOOL CheckTextureCapability(const struct wined3d_adapter *adapter, const /***** * supported: RGB(A) formats */ - case WINED3DFMT_B8G8R8_UNORM: /* Enable for dx7, blacklisted for 8 and 9 above */ + case WINED3DFMT_B8G8R8_UNORM: + TRACE_(d3d_caps)("[FAILED] - Not enumerated on Windows\n"); + return FALSE; case WINED3DFMT_B8G8R8A8_UNORM: case WINED3DFMT_B8G8R8X8_UNORM: case WINED3DFMT_B5G6R5_UNORM: @@ -3365,9 +3507,7 @@ static BOOL CheckTextureCapability(const struct wined3d_adapter *adapter, const */ case WINED3DFMT_D16_LOCKABLE: case WINED3DFMT_D16_UNORM: - case WINED3DFMT_S1_UINT_D15_UNORM: case WINED3DFMT_X8D24_UNORM: - case WINED3DFMT_S4X4_UINT_D24_UNORM: case WINED3DFMT_D24_UNORM_S8_UINT: case WINED3DFMT_S8_UINT_D24_FLOAT: case WINED3DFMT_D32_UNORM: @@ -3380,6 +3520,12 @@ static BOOL CheckTextureCapability(const struct wined3d_adapter *adapter, const return TRUE; return FALSE; + /* Not supported on Windows */ + case WINED3DFMT_S1_UINT_D15_UNORM: + case WINED3DFMT_S4X4_UINT_D24_UNORM: + TRACE_(d3d_caps)("[FAILED] - not supported on windows\n"); + return FALSE; + /***** * Not supported everywhere(depends on GL_ATI_envmap_bumpmap or * GL_NV_texture_shader). Emulated by shaders @@ -3423,6 +3569,8 @@ static BOOL CheckTextureCapability(const struct wined3d_adapter *adapter, const case WINED3DFMT_R16G16B16A16_SNORM: case WINED3DFMT_R10G10B10_SNORM_A2_UNORM: case WINED3DFMT_R10G11B11_SNORM: + case WINED3DFMT_R16: + case WINED3DFMT_AL16: TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */ return FALSE; @@ -3447,8 +3595,16 @@ static BOOL CheckTextureCapability(const struct wined3d_adapter *adapter, const TRACE_(d3d_caps)("[FAILED]\n"); return FALSE; - /* Not supported */ case WINED3DFMT_R16G16B16A16_UNORM: + if (gl_info->quirks & WINED3D_QUIRK_BROKEN_RGBA16) + { + TRACE_(d3d_caps)("[FAILED]\n"); + return FALSE; + } + TRACE_(d3d_caps)("[OK]\n"); + return TRUE; + + /* Not supported */ case WINED3DFMT_B2G3R3A8_UNORM: TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */ return FALSE; @@ -3541,7 +3697,7 @@ static BOOL CheckTextureCapability(const struct wined3d_adapter *adapter, const /* These formats seem to be similar to the HILO formats in GL_NV_texture_shader. NVHU * is said to be GL_UNSIGNED_HILO16, NVHS GL_SIGNED_HILO16. Rumours say that d3d computes * a 3rd channel similarly to D3DFMT_CxV8U8(So NVHS could be called D3DFMT_CxV16U16). - * ATI refused to support formats which can easilly be emulated with pixel shaders, so + * ATI refused to support formats which can easily be emulated with pixel shaders, so * Applications have to deal with not having NVHS and NVHU. */ TRACE_(d3d_caps)("[FAILED]\n"); @@ -3572,6 +3728,8 @@ static BOOL CheckSurfaceCapability(const struct wined3d_adapter *adapter, switch (check_format->id) { case WINED3DFMT_B8G8R8_UNORM: + TRACE_(d3d_caps)("[FAILED] - Not enumerated on Windows\n"); + return FALSE; case WINED3DFMT_B8G8R8A8_UNORM: case WINED3DFMT_B8G8R8X8_UNORM: case WINED3DFMT_B5G6R5_UNORM: @@ -3604,8 +3762,8 @@ static BOOL CheckSurfaceCapability(const struct wined3d_adapter *adapter, /* If opengl can't process the format natively, the blitter may be able to convert it */ if (adapter->blitter->blit_supported(&adapter->gl_info, WINED3D_BLIT_OP_COLOR_BLIT, - NULL, WINED3DPOOL_DEFAULT, 0, check_format, - NULL, WINED3DPOOL_DEFAULT, 0, adapter_format)) + NULL, WINED3D_POOL_DEFAULT, 0, check_format, + NULL, WINED3D_POOL_DEFAULT, 0, adapter_format)) { TRACE_(d3d_caps)("[OK]\n"); return TRUE; @@ -3619,12 +3777,24 @@ static BOOL CheckSurfaceCapability(const struct wined3d_adapter *adapter, static BOOL CheckVertexTextureCapability(const struct wined3d_adapter *adapter, const struct wined3d_format *format) { - return adapter->gl_info.limits.vertex_samplers && (format->flags & WINED3DFMT_FLAG_VTF); + const struct wined3d_gl_info *gl_info = &adapter->gl_info; + + if (!gl_info->limits.vertex_samplers || !(format->flags & WINED3DFMT_FLAG_VTF)) + return FALSE; + + switch (format->id) + { + case WINED3DFMT_R32G32B32A32_FLOAT: + case WINED3DFMT_R32_FLOAT: + return TRUE; + default: + return !(gl_info->quirks & WINED3D_QUIRK_LIMITED_TEX_FILTERING); + } } HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT adapter_idx, - WINED3DDEVTYPE device_type, enum wined3d_format_id adapter_format_id, DWORD usage, - WINED3DRESOURCETYPE resource_type, enum wined3d_format_id check_format_id, WINED3DSURFTYPE surface_type) + enum wined3d_device_type device_type, enum wined3d_format_id adapter_format_id, DWORD usage, + enum wined3d_resource_type resource_type, enum wined3d_format_id check_format_id, WINED3DSURFTYPE surface_type) { const struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx]; const struct wined3d_gl_info *gl_info = &adapter->gl_info; @@ -3643,7 +3813,7 @@ HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT ad switch (resource_type) { - case WINED3DRTYPE_CUBETEXTURE: + case WINED3D_RTYPE_CUBE_TEXTURE: /* Cubetexture allows: * - WINED3DUSAGE_AUTOGENMIPMAP * - WINED3DUSAGE_DEPTHSTENCIL @@ -3760,7 +3930,7 @@ HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT ad } break; - case WINED3DRTYPE_SURFACE: + case WINED3D_RTYPE_SURFACE: /* Surface allows: * - WINED3DUSAGE_DEPTHSTENCIL * - WINED3DUSAGE_NONSECURE (d3d9ex) @@ -3803,7 +3973,7 @@ HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT ad } break; - case WINED3DRTYPE_TEXTURE: + case WINED3D_RTYPE_TEXTURE: /* Texture allows: * - WINED3DUSAGE_AUTOGENMIPMAP * - WINED3DUSAGE_DEPTHSTENCIL @@ -3941,8 +4111,8 @@ HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT ad } break; - case WINED3DRTYPE_VOLUMETEXTURE: - case WINED3DRTYPE_VOLUME: + case WINED3D_RTYPE_VOLUME_TEXTURE: + case WINED3D_RTYPE_VOLUME: /* Volume is to VolumeTexture what Surface is to Texture, but its * usage caps are not documented. Most driver seem to offer * (nearly) the same on Volume and VolumeTexture, so do that too. @@ -4114,7 +4284,7 @@ HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT ad } HRESULT CDECL wined3d_check_device_format_conversion(const struct wined3d *wined3d, UINT adapter_idx, - WINED3DDEVTYPE device_type, enum wined3d_format_id src_format, enum wined3d_format_id dst_format) + enum wined3d_device_type device_type, enum wined3d_format_id src_format, enum wined3d_format_id dst_format) { FIXME("wined3d %p, adapter_idx %u, device_type %s, src_format %s, dst_format %s stub!\n", wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(src_format), @@ -4123,8 +4293,9 @@ HRESULT CDECL wined3d_check_device_format_conversion(const struct wined3d *wined return WINED3D_OK; } -HRESULT CDECL wined3d_check_device_type(const struct wined3d *wined3d, UINT adapter_idx, WINED3DDEVTYPE device_type, - enum wined3d_format_id display_format, enum wined3d_format_id backbuffer_format, BOOL windowed) +HRESULT CDECL wined3d_check_device_type(const struct wined3d *wined3d, UINT adapter_idx, + enum wined3d_device_type device_type, enum wined3d_format_id display_format, + enum wined3d_format_id backbuffer_format, BOOL windowed) { UINT mode_count; HRESULT hr; @@ -4214,7 +4385,7 @@ HRESULT CDECL wined3d_check_device_type(const struct wined3d *wined3d, UINT adap /* Use CheckDeviceFormat to see if the backbuffer_format is usable with the given display_format */ hr = wined3d_check_device_format(wined3d, adapter_idx, device_type, display_format, - WINED3DUSAGE_RENDERTARGET, WINED3DRTYPE_SURFACE, backbuffer_format, SURFACE_OPENGL); + WINED3DUSAGE_RENDERTARGET, WINED3D_RTYPE_SURFACE, backbuffer_format, SURFACE_OPENGL); if (FAILED(hr)) TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s / %s.\n", debug_d3dformat(display_format), debug_d3dformat(backbuffer_format)); @@ -4222,11 +4393,8 @@ HRESULT CDECL wined3d_check_device_type(const struct wined3d *wined3d, UINT adap return hr; } -/* Note: d3d8 passes in a pointer to a D3DCAPS8 structure, which is a true - subset of a D3DCAPS9 structure. However, it has to come via a void * - as the d3d8 interface cannot import the d3d9 header */ HRESULT CDECL wined3d_get_device_caps(const struct wined3d *wined3d, UINT adapter_idx, - WINED3DDEVTYPE device_type, WINED3DCAPS *caps) + enum wined3d_device_type device_type, WINED3DCAPS *caps) { const struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx]; const struct wined3d_gl_info *gl_info = &adapter->gl_info; @@ -4248,7 +4416,7 @@ HRESULT CDECL wined3d_get_device_caps(const struct wined3d *wined3d, UINT adapte The following fields apply to both d3d8 and d3d9 ------------------------------------------------ */ /* Not quite true, but use h/w supported by opengl I suppose */ - caps->DeviceType = (device_type == WINED3DDEVTYPE_HAL) ? WINED3DDEVTYPE_HAL : WINED3DDEVTYPE_REF; + caps->DeviceType = (device_type == WINED3D_DEVICE_TYPE_HAL) ? WINED3D_DEVICE_TYPE_HAL : WINED3D_DEVICE_TYPE_REF; caps->AdapterOrdinal = adapter_idx; caps->Caps = 0; @@ -4635,7 +4803,7 @@ HRESULT CDECL wined3d_get_device_caps(const struct wined3d *wined3d, UINT adapte if (vs_selected_mode == SHADER_NONE) { TRACE_(d3d_caps)("Vertex shader disabled in config, reporting version 0.0\n"); - caps->VertexShaderVersion = WINED3DVS_VERSION(0,0); + caps->VertexShaderVersion = 0; caps->MaxVertexShaderConst = 0; } else @@ -4647,7 +4815,7 @@ HRESULT CDECL wined3d_get_device_caps(const struct wined3d *wined3d, UINT adapte if (ps_selected_mode == SHADER_NONE) { TRACE_(d3d_caps)("Pixel shader disabled in config, reporting version 0.0\n"); - caps->PixelShaderVersion = WINED3DPS_VERSION(0,0); + caps->PixelShaderVersion = 0; caps->PixelShader1xMaxValue = 0.0f; } else { caps->PixelShaderVersion = shader_caps.PixelShaderVersion; @@ -4662,44 +4830,44 @@ HRESULT CDECL wined3d_get_device_caps(const struct wined3d *wined3d, UINT adapte * are the same among all shader models. So to avoid code duplication set the shader version * specific, but otherwise constant caps here */ - if (caps->VertexShaderVersion == WINED3DVS_VERSION(3,0)) + if (caps->VertexShaderVersion >= 3) { /* Where possible set the caps based on OpenGL extensions and if they * aren't set (in case of software rendering) use the VS 3.0 from * MSDN or else if there's OpenGL spec use a hardcoded value minimum * VS3.0 value. */ - caps->VS20Caps.Caps = WINED3DVS20CAPS_PREDICATION; + caps->VS20Caps.caps = WINED3DVS20CAPS_PREDICATION; /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */ - caps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH; - caps->VS20Caps.NumTemps = max(32, adapter->gl_info.limits.arb_vs_temps); + caps->VS20Caps.dynamic_flow_control_depth = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH; + caps->VS20Caps.temp_count = max(32, adapter->gl_info.limits.arb_vs_temps); /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */ - caps->VS20Caps.StaticFlowControlDepth = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH; + caps->VS20Caps.static_flow_control_depth = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH; caps->MaxVShaderInstructionsExecuted = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */ caps->MaxVertexShader30InstructionSlots = max(512, adapter->gl_info.limits.arb_vs_instructions); } - else if (caps->VertexShaderVersion == WINED3DVS_VERSION(2,0)) + else if (caps->VertexShaderVersion == 2) { - caps->VS20Caps.Caps = 0; - caps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH; - caps->VS20Caps.NumTemps = max(12, adapter->gl_info.limits.arb_vs_temps); - caps->VS20Caps.StaticFlowControlDepth = 1; + caps->VS20Caps.caps = 0; + caps->VS20Caps.dynamic_flow_control_depth = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH; + caps->VS20Caps.temp_count = max(12, adapter->gl_info.limits.arb_vs_temps); + caps->VS20Caps.static_flow_control_depth = 1; caps->MaxVShaderInstructionsExecuted = 65535; caps->MaxVertexShader30InstructionSlots = 0; } else { /* VS 1.x */ - caps->VS20Caps.Caps = 0; - caps->VS20Caps.DynamicFlowControlDepth = 0; - caps->VS20Caps.NumTemps = 0; - caps->VS20Caps.StaticFlowControlDepth = 0; + caps->VS20Caps.caps = 0; + caps->VS20Caps.dynamic_flow_control_depth = 0; + caps->VS20Caps.temp_count = 0; + caps->VS20Caps.static_flow_control_depth = 0; caps->MaxVShaderInstructionsExecuted = 0; caps->MaxVertexShader30InstructionSlots = 0; } - if (caps->PixelShaderVersion == WINED3DPS_VERSION(3,0)) + if (caps->PixelShaderVersion >= 3) { /* Where possible set the caps based on OpenGL extensions and if they * aren't set (in case of software rendering) use the PS 3.0 from @@ -4709,49 +4877,49 @@ HRESULT CDECL wined3d_get_device_caps(const struct wined3d *wined3d, UINT adapte /* Caps is more or less undocumented on MSDN but it appears to be * used for PS20Caps based on results from R9600/FX5900/Geforce6800 * cards from Windows */ - caps->PS20Caps.Caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE | + caps->PS20Caps.caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE | WINED3DPS20CAPS_GRADIENTINSTRUCTIONS | WINED3DPS20CAPS_PREDICATION | WINED3DPS20CAPS_NODEPENDENTREADLIMIT | WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT; /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */ - caps->PS20Caps.DynamicFlowControlDepth = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH; - caps->PS20Caps.NumTemps = max(32, adapter->gl_info.limits.arb_ps_temps); + caps->PS20Caps.dynamic_flow_control_depth = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH; + caps->PS20Caps.temp_count = max(32, adapter->gl_info.limits.arb_ps_temps); /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */ - caps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH; + caps->PS20Caps.static_flow_control_depth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */ - caps->PS20Caps.NumInstructionSlots = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS; + caps->PS20Caps.instruction_slot_count = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS; caps->MaxPShaderInstructionsExecuted = 65535; caps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS, adapter->gl_info.limits.arb_ps_instructions); } - else if(caps->PixelShaderVersion == WINED3DPS_VERSION(2,0)) + else if(caps->PixelShaderVersion == 2) { /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */ - caps->PS20Caps.Caps = 0; - caps->PS20Caps.DynamicFlowControlDepth = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */ - caps->PS20Caps.NumTemps = max(12, adapter->gl_info.limits.arb_ps_temps); - caps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */ + caps->PS20Caps.caps = 0; + caps->PS20Caps.dynamic_flow_control_depth = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */ + caps->PS20Caps.temp_count = max(12, adapter->gl_info.limits.arb_ps_temps); + caps->PS20Caps.static_flow_control_depth = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */ /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */ - caps->PS20Caps.NumInstructionSlots = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS; + caps->PS20Caps.instruction_slot_count = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS; caps->MaxPShaderInstructionsExecuted = 512; /* Minimum value, a GeforceFX uses 1024 */ caps->MaxPixelShader30InstructionSlots = 0; } else /* PS 1.x */ { - caps->PS20Caps.Caps = 0; - caps->PS20Caps.DynamicFlowControlDepth = 0; - caps->PS20Caps.NumTemps = 0; - caps->PS20Caps.StaticFlowControlDepth = 0; - caps->PS20Caps.NumInstructionSlots = 0; + caps->PS20Caps.caps = 0; + caps->PS20Caps.dynamic_flow_control_depth = 0; + caps->PS20Caps.temp_count = 0; + caps->PS20Caps.static_flow_control_depth = 0; + caps->PS20Caps.instruction_slot_count = 0; caps->MaxPShaderInstructionsExecuted = 0; caps->MaxPixelShader30InstructionSlots = 0; } - if (caps->VertexShaderVersion >= WINED3DVS_VERSION(2,0)) + if (caps->VertexShaderVersion >= 2) { /* OpenGL supports all the formats below, perhaps not always * without conversion, but it supports them. @@ -4804,28 +4972,28 @@ HRESULT CDECL wined3d_get_device_caps(const struct wined3d *wined3d, UINT adapte WINEDDPCAPS_PRIMARYSURFACE; /* Fill the ddraw caps structure */ - caps->DirectDrawCaps.Caps = WINEDDCAPS_GDI | + caps->ddraw_caps.caps = WINEDDCAPS_GDI | WINEDDCAPS_PALETTE | blit_caps; - caps->DirectDrawCaps.Caps2 = WINEDDCAPS2_CERTIFIED | - WINEDDCAPS2_NOPAGELOCKREQUIRED | - WINEDDCAPS2_PRIMARYGAMMA | - WINEDDCAPS2_WIDESURFACES | + caps->ddraw_caps.caps2 = WINEDDCAPS2_CERTIFIED | + WINEDDCAPS2_NOPAGELOCKREQUIRED | + WINEDDCAPS2_PRIMARYGAMMA | + WINEDDCAPS2_WIDESURFACES | WINEDDCAPS2_CANRENDERWINDOWED; - caps->DirectDrawCaps.CKeyCaps = ckey_caps; - caps->DirectDrawCaps.FXCaps = fx_caps; - caps->DirectDrawCaps.PalCaps = pal_caps; - caps->DirectDrawCaps.SVBCaps = blit_caps; - caps->DirectDrawCaps.SVBCKeyCaps = ckey_caps; - caps->DirectDrawCaps.SVBFXCaps = fx_caps; - caps->DirectDrawCaps.VSBCaps = blit_caps; - caps->DirectDrawCaps.VSBCKeyCaps = ckey_caps; - caps->DirectDrawCaps.VSBFXCaps = fx_caps; - caps->DirectDrawCaps.SSBCaps = blit_caps; - caps->DirectDrawCaps.SSBCKeyCaps = ckey_caps; - caps->DirectDrawCaps.SSBFXCaps = fx_caps; + caps->ddraw_caps.color_key_caps = ckey_caps; + caps->ddraw_caps.fx_caps = fx_caps; + caps->ddraw_caps.pal_caps = pal_caps; + caps->ddraw_caps.svb_caps = blit_caps; + caps->ddraw_caps.svb_color_key_caps = ckey_caps; + caps->ddraw_caps.svb_fx_caps = fx_caps; + caps->ddraw_caps.vsb_caps = blit_caps; + caps->ddraw_caps.vsb_color_key_caps = ckey_caps; + caps->ddraw_caps.vsb_fx_caps = fx_caps; + caps->ddraw_caps.ssb_caps = blit_caps; + caps->ddraw_caps.ssb_color_key_caps = ckey_caps; + caps->ddraw_caps.ssb_fx_caps = fx_caps; - caps->DirectDrawCaps.ddsCaps = WINEDDSCAPS_ALPHA | + caps->ddraw_caps.dds_caps = WINEDDSCAPS_ALPHA | WINEDDSCAPS_BACKBUFFER | WINEDDSCAPS_FLIP | WINEDDSCAPS_FRONTBUFFER | @@ -4835,23 +5003,24 @@ HRESULT CDECL wined3d_get_device_caps(const struct wined3d *wined3d, UINT adapte WINEDDSCAPS_SYSTEMMEMORY | WINEDDSCAPS_VIDEOMEMORY | WINEDDSCAPS_VISIBLE; - caps->DirectDrawCaps.StrideAlign = DDRAW_PITCH_ALIGNMENT; + caps->ddraw_caps.stride_align = DDRAW_PITCH_ALIGNMENT; /* Set D3D caps if OpenGL is available. */ if (adapter->opengl) { - caps->DirectDrawCaps.ddsCaps |= WINEDDSCAPS_3DDEVICE | + caps->ddraw_caps.dds_caps |= WINEDDSCAPS_3DDEVICE | WINEDDSCAPS_MIPMAP | WINEDDSCAPS_TEXTURE | WINEDDSCAPS_ZBUFFER; - caps->DirectDrawCaps.Caps |= WINEDDCAPS_3D; + caps->ddraw_caps.caps |= WINEDDCAPS_3D; } return WINED3D_OK; } -HRESULT CDECL wined3d_device_create(struct wined3d *wined3d, UINT adapter_idx, WINED3DDEVTYPE device_type, - HWND focus_window, DWORD flags, struct wined3d_device_parent *device_parent, struct wined3d_device **device) +HRESULT CDECL wined3d_device_create(struct wined3d *wined3d, UINT adapter_idx, enum wined3d_device_type device_type, + HWND focus_window, DWORD flags, BYTE surface_alignment, struct wined3d_device_parent *device_parent, + struct wined3d_device **device) { struct wined3d_device *object; HRESULT hr; @@ -4871,7 +5040,8 @@ HRESULT CDECL wined3d_device_create(struct wined3d *wined3d, UINT adapter_idx, W return E_OUTOFMEMORY; } - hr = device_init(object, wined3d, adapter_idx, device_type, focus_window, flags, device_parent); + hr = device_init(object, wined3d, adapter_idx, device_type, + focus_window, flags, surface_alignment, device_parent); if (FAILED(hr)) { WARN("Failed to initialize device, hr %#x.\n", hr); @@ -5144,7 +5314,6 @@ static BOOL InitAdapters(struct wined3d *wined3d) struct wined3d_pixel_format *cfgs; int iPixelFormat; int res; - int i; DISPLAY_DEVICEW DisplayDevice; HDC hdc; @@ -5168,7 +5337,7 @@ static BOOL InitAdapters(struct wined3d *wined3d) goto nogl_adapter; } - ret = IWineD3DImpl_FillGLCaps(adapter); + ret = wined3d_adapter_init_gl_caps(adapter); if(!ret) { ERR("Failed to initialize gl caps for default adapter\n"); WineD3D_ReleaseFakeGLContext(&fake_gl_ctx); @@ -5195,15 +5364,17 @@ static BOOL InitAdapters(struct wined3d *wined3d) if (gl_info->supported[WGL_ARB_PIXEL_FORMAT]) { + GLint cfg_count; int attribute; int attribs[11]; int values[11]; int nAttribs = 0; attribute = WGL_NUMBER_PIXEL_FORMATS_ARB; - GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, &attribute, &adapter->nCfgs)); + GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, &attribute, &cfg_count)); + adapter->cfg_count = cfg_count; - adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, adapter->nCfgs * sizeof(*adapter->cfgs)); + adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, adapter->cfg_count * sizeof(*adapter->cfgs)); cfgs = adapter->cfgs; attribs[nAttribs++] = WGL_RED_BITS_ARB; attribs[nAttribs++] = WGL_GREEN_BITS_ARB; @@ -5217,7 +5388,7 @@ static BOOL InitAdapters(struct wined3d *wined3d) attribs[nAttribs++] = WGL_DOUBLE_BUFFER_ARB; attribs[nAttribs++] = WGL_AUX_BUFFERS_ARB; - for (iPixelFormat=1; iPixelFormat <= adapter->nCfgs; ++iPixelFormat) + for (iPixelFormat=1; iPixelFormat <= adapter->cfg_count; ++iPixelFormat) { res = GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, nAttribs, attribs, values)); @@ -5264,7 +5435,7 @@ static BOOL InitAdapters(struct wined3d *wined3d) { int nCfgs = DescribePixelFormat(hdc, 0, 0, 0); adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nCfgs * sizeof(*adapter->cfgs)); - adapter->nCfgs = 0; /* We won't accept all formats e.g. software accelerated ones will be skipped */ + adapter->cfg_count = 0; /* We won't accept all formats e.g. software accelerated ones will be skipped */ cfgs = adapter->cfgs; for(iPixelFormat=1; iPixelFormat<=nCfgs; iPixelFormat++) @@ -5305,11 +5476,13 @@ static BOOL InitAdapters(struct wined3d *wined3d) cfgs->redSize, cfgs->greenSize, cfgs->blueSize, cfgs->alphaSize, cfgs->depthSize, cfgs->stencilSize, cfgs->windowDrawable); cfgs++; - adapter->nCfgs++; + adapter->cfg_count++; } - /* Yikes we haven't found any suitable formats. This should only happen in case of GDI software rendering which we can't use anyway as its 3D functionality is very, very limited */ - if(!adapter->nCfgs) + /* We haven't found any suitable formats. This should only happen + * in case of GDI software rendering, which is pretty useless + * anyway. */ + if (!adapter->cfg_count) { ERR("Disabling Direct3D because no hardware accelerated pixel formats have been found!\n"); @@ -5319,25 +5492,6 @@ static BOOL InitAdapters(struct wined3d *wined3d) } } - /* D16, D24X8 and D24S8 are common depth / depth+stencil formats. All drivers support them though this doesn't - * mean that the format is offered in hardware. For instance Geforce8 cards don't have offer D16 in hardware - * but just fake it using D24(X8?) which is fine. D3D also allows that. - * Some display drivers (i915 on Linux) only report mixed depth+stencil formats like D24S8. MSDN clearly mentions - * that only on lockable formats (e.g. D16_locked) the bit order is guaranteed and that on other formats the - * driver is allowed to consume more bits EXCEPT for stencil bits. - * - * Mark an adapter with this broken stencil behavior. - */ - adapter->brokenStencil = TRUE; - for (i = 0, cfgs = adapter->cfgs; i < adapter->nCfgs; ++i) - { - /* Nearly all drivers offer depth formats without stencil, only on i915 this if-statement won't be entered. */ - if(cfgs[i].depthSize && !cfgs[i].stencilSize) { - adapter->brokenStencil = FALSE; - break; - } - } - WineD3D_ReleaseFakeGLContext(&fake_gl_ctx); select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode); @@ -5378,11 +5532,12 @@ const struct wined3d_parent_ops wined3d_null_parent_ops = }; /* Do not call while under the GL lock. */ -HRESULT wined3d_init(struct wined3d *wined3d, UINT version, void *parent) +HRESULT wined3d_init(struct wined3d *wined3d, UINT version, DWORD flags, void *parent) { wined3d->dxVersion = version; wined3d->ref = 1; wined3d->parent = parent; + wined3d->flags = flags; if (!InitAdapters(wined3d)) { diff --git a/reactos/dll/directx/wine/wined3d/drawprim.c b/reactos/dll/directx/wine/wined3d/drawprim.c index 4dbba92710b..a5e81db0aa6 100644 --- a/reactos/dll/directx/wine/wined3d/drawprim.c +++ b/reactos/dll/directx/wine/wined3d/drawprim.c @@ -33,14 +33,24 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d_draw); #include /* GL locking is done by the caller */ -static void drawStridedFast(GLenum primitive_type, UINT count, UINT idx_size, const void *idx_data, UINT start_idx) +static void drawStridedFast(const struct wined3d_gl_info *gl_info, GLenum primitive_type, UINT count, UINT idx_size, + const void *idx_data, UINT start_idx, INT base_vertex_index) { if (idx_size) { - glDrawElements(primitive_type, count, - idx_size == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, - (const char *)idx_data + (idx_size * start_idx)); - checkGLcall("glDrawElements"); + GLenum idxtype = idx_size == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT; + if (gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX]) + { + GL_EXTCALL(glDrawElementsBaseVertex(primitive_type, count, idxtype, + (const char *)idx_data + (idx_size * start_idx), base_vertex_index)); + checkGLcall("glDrawElementsBaseVertex"); + } + else + { + glDrawElements(primitive_type, count, + idxtype, (const char *)idx_data + (idx_size * start_idx)); + checkGLcall("glDrawElements"); + } } else { @@ -55,7 +65,7 @@ static void drawStridedFast(GLenum primitive_type, UINT count, UINT idx_size, co */ /* GL locking is done by the caller */ -static void drawStridedSlow(struct wined3d_device *device, const struct wined3d_context *context, +static void drawStridedSlow(const struct wined3d_device *device, const struct wined3d_context *context, const struct wined3d_stream_info *si, UINT NumVertexes, GLenum glPrimType, const void *idxData, UINT idxSize, UINT startIdx) { @@ -64,8 +74,7 @@ static void drawStridedSlow(struct wined3d_device *device, const struct wined3d_ const DWORD *pIdxBufL = NULL; UINT vx_index; const struct wined3d_state *state = &device->stateBlock->state; - const struct wined3d_stream_state *streams = state->streams; - LONG SkipnStrides = startIdx + state->load_base_vertex_index; + LONG SkipnStrides = startIdx; BOOL pixelShader = use_ps(state); BOOL specular_fog = FALSE; const BYTE *texCoords[WINED3DDP_MAXTEXCOORD]; @@ -101,13 +110,13 @@ static void drawStridedSlow(struct wined3d_device *device, const struct wined3d_ if (si->use_map & (1 << WINED3D_FFP_POSITION)) { element = &si->elements[WINED3D_FFP_POSITION]; - position = element->data + streams[element->stream_idx].offset; + position = element->data.addr; } if (si->use_map & (1 << WINED3D_FFP_NORMAL)) { element = &si->elements[WINED3D_FFP_NORMAL]; - normal = element->data + streams[element->stream_idx].offset; + normal = element->data.addr; } else { @@ -118,7 +127,7 @@ static void drawStridedSlow(struct wined3d_device *device, const struct wined3d_ if (si->use_map & (1 << WINED3D_FFP_DIFFUSE)) { element = &si->elements[WINED3D_FFP_DIFFUSE]; - diffuse = element->data + streams[element->stream_idx].offset; + diffuse = element->data.addr; if (num_untracked_materials && element->format->id != WINED3DFMT_B8G8R8A8_UNORM) FIXME("Implement diffuse color tracking from %s\n", debug_d3dformat(element->format->id)); @@ -131,13 +140,13 @@ static void drawStridedSlow(struct wined3d_device *device, const struct wined3d_ if (si->use_map & (1 << WINED3D_FFP_SPECULAR)) { element = &si->elements[WINED3D_FFP_SPECULAR]; - specular = element->data + streams[element->stream_idx].offset; + specular = element->data.addr; /* special case where the fog density is stored in the specular alpha channel */ - if (state->render_states[WINED3DRS_FOGENABLE] - && (state->render_states[WINED3DRS_FOGVERTEXMODE] == WINED3DFOG_NONE + if (state->render_states[WINED3D_RS_FOGENABLE] + && (state->render_states[WINED3D_RS_FOGVERTEXMODE] == WINED3D_FOG_NONE || si->elements[WINED3D_FFP_POSITION].format->id == WINED3DFMT_R32G32B32A32_FLOAT) - && state->render_states[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) + && state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE) { if (gl_info->supported[EXT_FOG_COORD]) { @@ -164,7 +173,7 @@ static void drawStridedSlow(struct wined3d_device *device, const struct wined3d_ for (textureNo = 0; textureNo < texture_stages; ++textureNo) { - int coordIdx = state->texture_states[textureNo][WINED3DTSS_TEXCOORDINDEX]; + int coordIdx = state->texture_states[textureNo][WINED3D_TSS_TEXCOORD_INDEX]; DWORD texture_idx = device->texUnitMap[textureNo]; if (!gl_info->supported[ARB_MULTITEXTURE] && textureNo > 0) @@ -191,7 +200,7 @@ static void drawStridedSlow(struct wined3d_device *device, const struct wined3d_ if (si->use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx))) { element = &si->elements[WINED3D_FFP_TEXCOORD0 + coordIdx]; - texCoords[coordIdx] = element->data + streams[element->stream_idx].offset; + texCoords[coordIdx] = element->data.addr; tex_mask |= (1 << textureNo); } else @@ -220,9 +229,9 @@ static void drawStridedSlow(struct wined3d_device *device, const struct wined3d_ { /* Indexed so work out the number of strides to skip */ if (idxSize == 2) - SkipnStrides = pIdxBufS[startIdx + vx_index] + state->load_base_vertex_index; + SkipnStrides = pIdxBufS[startIdx + vx_index] + state->base_vertex_index; else - SkipnStrides = pIdxBufL[startIdx + vx_index] + state->load_base_vertex_index; + SkipnStrides = pIdxBufL[startIdx + vx_index] + state->base_vertex_index; } tmp_tex_mask = tex_mask; @@ -234,7 +243,7 @@ static void drawStridedSlow(struct wined3d_device *device, const struct wined3d_ if (!(tmp_tex_mask & 1)) continue; - coord_idx = state->texture_states[texture][WINED3DTSS_TEXCOORDINDEX]; + coord_idx = state->texture_states[texture][WINED3D_TSS_TEXCOORD_INDEX]; ptr = texCoords[coord_idx] + (SkipnStrides * si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].stride); texture_idx = device->texUnitMap[texture]; @@ -375,7 +384,7 @@ static inline void send_attribute(const struct wined3d_gl_info *gl_info, /* Are those 16 bit floats. C doesn't have a 16 bit float type. I could read the single bits and calculate a 4 * byte float according to the IEEE standard */ - if (gl_info->supported[NV_HALF_FLOAT]) + if (gl_info->supported[NV_HALF_FLOAT] && gl_info->supported[NV_VERTEX_PROGRAM]) { /* Not supported by GL_ARB_half_float_vertex */ GL_EXTCALL(glVertexAttrib2hvNV(index, ptr)); @@ -388,7 +397,7 @@ static inline void send_attribute(const struct wined3d_gl_info *gl_info, } break; case WINED3DFMT_R16G16B16A16_FLOAT: - if (gl_info->supported[NV_HALF_FLOAT]) + if (gl_info->supported[NV_HALF_FLOAT] && gl_info->supported[NV_VERTEX_PROGRAM]) { /* Not supported by GL_ARB_half_float_vertex */ GL_EXTCALL(glVertexAttrib4hvNV(index, ptr)); @@ -455,8 +464,7 @@ static void drawStridedSlowVs(const struct wined3d_gl_info *gl_info, const struc { if (!(si->use_map & (1 << i))) continue; - ptr = si->elements[i].data + si->elements[i].stride * SkipnStrides - + state->streams[si->elements[i].stream_idx].offset; + ptr = si->elements[i].data.addr + si->elements[i].stride * SkipnStrides; send_attribute(gl_info, si->elements[i].format->id, i, ptr); } @@ -469,11 +477,12 @@ static void drawStridedSlowVs(const struct wined3d_gl_info *gl_info, const struc /* GL locking is done by the caller */ static void drawStridedInstanced(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state, const struct wined3d_stream_info *si, UINT numberOfVertices, GLenum glPrimitiveType, - const void *idxData, UINT idxSize, UINT startIdx) + const void *idxData, UINT idxSize, UINT startIdx, UINT base_vertex_index) { UINT numInstances = 0, i; int numInstancedAttribs = 0, j; UINT instancedData[sizeof(si->elements) / sizeof(*si->elements) /* 16 */]; + GLenum idxtype = idxSize == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT; if (!idxSize) { @@ -518,10 +527,9 @@ static void drawStridedInstanced(const struct wined3d_gl_info *gl_info, const st for(i = 0; i < numInstances; i++) { /* Specify the instanced attributes using immediate mode calls */ for(j = 0; j < numInstancedAttribs; j++) { - const BYTE *ptr = si->elements[instancedData[j]].data - + si->elements[instancedData[j]].stride * i - + state->streams[si->elements[instancedData[j]].stream_idx].offset; - if (si->elements[instancedData[j]].buffer_object) + const BYTE *ptr = si->elements[instancedData[j]].data.addr + + si->elements[instancedData[j]].stride * i; + if (si->elements[instancedData[j]].data.buffer_object) { struct wined3d_buffer *vb = state->streams[si->elements[instancedData[j]].stream_idx].buffer; ptr += (ULONG_PTR)buffer_get_sysmem(vb, gl_info); @@ -530,9 +538,18 @@ static void drawStridedInstanced(const struct wined3d_gl_info *gl_info, const st send_attribute(gl_info, si->elements[instancedData[j]].format->id, instancedData[j], ptr); } - glDrawElements(glPrimitiveType, numberOfVertices, idxSize == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, - (const char *)idxData+(idxSize * startIdx)); - checkGLcall("glDrawElements"); + if (gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX]) + { + GL_EXTCALL(glDrawElementsBaseVertex(glPrimitiveType, numberOfVertices, idxtype, + (const char *)idxData+(idxSize * startIdx), base_vertex_index)); + checkGLcall("glDrawElementsBaseVertex"); + } + else + { + glDrawElements(glPrimitiveType, numberOfVertices, idxtype, + (const char *)idxData+(idxSize * startIdx)); + checkGLcall("glDrawElements"); + } } } @@ -548,11 +565,11 @@ static void remove_vbos(const struct wined3d_gl_info *gl_info, if (!(s->use_map & (1 << i))) continue; e = &s->elements[i]; - if (e->buffer_object) + if (e->data.buffer_object) { struct wined3d_buffer *vb = state->streams[e->stream_idx].buffer; - e->buffer_object = 0; - e->data = (BYTE *)((ULONG_PTR)e->data + (ULONG_PTR)buffer_get_sysmem(vb, gl_info)); + e->data.buffer_object = 0; + e->data.addr = (BYTE *)((ULONG_PTR)e->data.addr + (ULONG_PTR)buffer_get_sysmem(vb, gl_info)); } } } @@ -566,7 +583,7 @@ void drawPrimitive(struct wined3d_device *device, UINT index_count, UINT StartId if (!index_count) return; - if (state->render_states[WINED3DRS_COLORWRITEENABLE]) + if (state->render_states[WINED3D_RS_COLORWRITEENABLE]) { /* Invalidate the back buffer memory so LockRect will read it the next time */ for (i = 0; i < device->adapter->gl_info.limits.buffers; ++i) @@ -574,8 +591,8 @@ void drawPrimitive(struct wined3d_device *device, UINT index_count, UINT StartId struct wined3d_surface *target = device->fb.render_targets[i]; if (target) { - surface_load_location(target, SFLAG_INDRAWABLE, NULL); - surface_modify_location(target, SFLAG_INDRAWABLE, TRUE); + surface_load_location(target, target->draw_binding, NULL); + surface_modify_location(target, target->draw_binding, TRUE); } } } @@ -591,13 +608,6 @@ void drawPrimitive(struct wined3d_device *device, UINT index_count, UINT StartId return; } - if (!context_apply_draw_state(context, device)) - { - context_release(context); - WARN("Unable to apply draw state, skipping draw.\n"); - return; - } - if (device->fb.depth_stencil) { /* Note that this depends on the context_acquire() call above to set @@ -605,13 +615,13 @@ void drawPrimitive(struct wined3d_device *device, UINT index_count, UINT StartId * Z-compare function into account, but we could skip loading the * depthstencil for D3DCMP_NEVER and D3DCMP_ALWAYS as well. Also note * that we never copy the stencil data.*/ - DWORD location = context->render_offscreen ? SFLAG_DS_OFFSCREEN : SFLAG_DS_ONSCREEN; - if (state->render_states[WINED3DRS_ZWRITEENABLE] || state->render_states[WINED3DRS_ZENABLE]) + DWORD location = context->render_offscreen ? device->fb.depth_stencil->draw_binding : SFLAG_INDRAWABLE; + if (state->render_states[WINED3D_RS_ZWRITEENABLE] || state->render_states[WINED3D_RS_ZENABLE]) { struct wined3d_surface *ds = device->fb.depth_stencil; RECT current_rect, draw_rect, r; - if (location == SFLAG_DS_ONSCREEN && ds != device->onscreen_depth_stencil) + if (!context->render_offscreen && ds != device->onscreen_depth_stencil) device_switch_onscreen_ds(device, context, ds); if (ds->flags & location) @@ -619,24 +629,33 @@ void drawPrimitive(struct wined3d_device *device, UINT index_count, UINT StartId else SetRectEmpty(¤t_rect); - device_get_draw_rect(device, &draw_rect); + wined3d_get_draw_rect(state, &draw_rect); IntersectRect(&r, &draw_rect, ¤t_rect); if (!EqualRect(&r, &draw_rect)) surface_load_ds_location(ds, context, location); - - if (state->render_states[WINED3DRS_ZWRITEENABLE]) - { - surface_modify_ds_location(ds, location, ds->ds_current_size.cx, ds->ds_current_size.cy); - surface_modify_location(ds, SFLAG_INDRAWABLE, TRUE); - } } } + if (!context_apply_draw_state(context, device)) + { + context_release(context); + WARN("Unable to apply draw state, skipping draw.\n"); + return; + } + + if (device->fb.depth_stencil && state->render_states[WINED3D_RS_ZWRITEENABLE]) + { + struct wined3d_surface *ds = device->fb.depth_stencil; + DWORD location = context->render_offscreen ? ds->draw_binding : SFLAG_INDRAWABLE; + + surface_modify_ds_location(ds, location, ds->ds_current_size.cx, ds->ds_current_size.cy); + } + if ((!context->gl_info->supported[WINED3D_GL_VERSION_2_0] || (!glPointParameteri && !context->gl_info->supported[NV_POINT_SPRITE])) && context->render_offscreen - && state->render_states[WINED3DRS_POINTSPRITEENABLE] + && state->render_states[WINED3D_RS_POINTSPRITEENABLE] && state->gl_primitive_type == GL_POINTS) { FIXME("Point sprite coordinate origin switching not supported.\n"); @@ -646,6 +665,7 @@ void drawPrimitive(struct wined3d_device *device, UINT index_count, UINT StartId ENTER_GL(); { GLenum glPrimType = state->gl_primitive_type; + INT base_vertex_index = state->base_vertex_index; BOOL emulation = FALSE; const struct wined3d_stream_info *stream_info = &device->strided_streams; struct wined3d_stream_info stridedlcl; @@ -653,7 +673,7 @@ void drawPrimitive(struct wined3d_device *device, UINT index_count, UINT StartId if (!use_vs(state)) { if (!stream_info->position_transformed && context->num_untracked_materials - && state->render_states[WINED3DRS_LIGHTING]) + && state->render_states[WINED3D_RS_LIGHTING]) { static BOOL warned; if (!warned) { @@ -664,7 +684,7 @@ void drawPrimitive(struct wined3d_device *device, UINT index_count, UINT StartId } emulation = TRUE; } - else if (context->fog_coord && state->render_states[WINED3DRS_FOGENABLE]) + else if (context->fog_coord && state->render_states[WINED3D_RS_FOGENABLE]) { /* Either write a pipeline replacement shader or convert the specular alpha from unsigned byte * to a float in the vertex buffer @@ -711,11 +731,11 @@ void drawPrimitive(struct wined3d_device *device, UINT index_count, UINT StartId { /* Instancing emulation with mixing immediate mode and arrays */ drawStridedInstanced(context->gl_info, state, stream_info, - index_count, glPrimType, idxData, idxSize, StartIdx); + index_count, glPrimType, idxData, idxSize, StartIdx, base_vertex_index); } else { - drawStridedFast(glPrimType, index_count, idxSize, idxData, StartIdx); + drawStridedFast(context->gl_info, glPrimType, index_count, idxSize, idxData, StartIdx, base_vertex_index); } } @@ -771,12 +791,14 @@ static void normalize_normal(float *n) { HRESULT tesselate_rectpatch(struct wined3d_device *This, struct WineD3DRectPatch *patch) { unsigned int i, j, num_quads, out_vertex_size, buffer_size, d3d_out_vertex_size; + const struct wined3d_rect_patch_info *info = &patch->rect_patch_info; float max_x = 0.0f, max_y = 0.0f, max_z = 0.0f, neg_z = 0.0f; + struct wined3d_state *state = &This->stateBlock->state; struct wined3d_stream_info stream_info; struct wined3d_stream_info_element *e; struct wined3d_context *context; + struct wined3d_shader *vs; const BYTE *data; - const WINED3DRECTPATCH_INFO *info = &patch->RectPatchInfo; DWORD vtxStride; GLenum feedback_type; GLfloat *feedbuffer; @@ -787,21 +809,23 @@ HRESULT tesselate_rectpatch(struct wined3d_device *This, struct WineD3DRectPatch context = context_acquire(This, NULL); context_apply_blit_state(context, This); - /* First, locate the position data. This is provided in a vertex buffer in the stateblock. - * Beware of vbos - */ - device_stream_info_from_declaration(This, FALSE, &stream_info, NULL); + /* First, locate the position data. This is provided in a vertex buffer in + * the stateblock. Beware of VBOs. */ + vs = state->vertex_shader; + state->vertex_shader = NULL; + device_stream_info_from_declaration(This, &stream_info, NULL); + state->vertex_shader = vs; e = &stream_info.elements[WINED3D_FFP_POSITION]; - if (e->buffer_object) + if (e->data.buffer_object) { - struct wined3d_buffer *vb = This->stateBlock->state.streams[e->stream_idx].buffer; - e->data = (BYTE *)((ULONG_PTR)e->data + (ULONG_PTR)buffer_get_sysmem(vb, context->gl_info)); + struct wined3d_buffer *vb = state->streams[e->stream_idx].buffer; + e->data.addr = (BYTE *)((ULONG_PTR)e->data.addr + (ULONG_PTR)buffer_get_sysmem(vb, context->gl_info)); } vtxStride = e->stride; - data = e->data + - vtxStride * info->Stride * info->StartVertexOffsetHeight + - vtxStride * info->StartVertexOffsetWidth; + data = e->data.addr + + vtxStride * info->stride * info->start_vertex_offset_height + + vtxStride * info->start_vertex_offset_width; /* Not entirely sure about what happens with transformed vertices */ if (stream_info.position_transformed) FIXME("Transformed position in rectpatch generation\n"); @@ -813,17 +837,17 @@ HRESULT tesselate_rectpatch(struct wined3d_device *This, struct WineD3DRectPatch */ ERR("Vertex stride is not a multiple of sizeof(GLfloat)\n"); } - if(info->Basis != WINED3DBASIS_BEZIER) { - FIXME("Basis is %s, how to handle this?\n", debug_d3dbasis(info->Basis)); - } - if(info->Degree != WINED3DDEGREE_CUBIC) { - FIXME("Degree is %s, how to handle this?\n", debug_d3ddegree(info->Degree)); - } + if (info->basis != WINED3D_BASIS_BEZIER) + FIXME("Basis is %s, how to handle this?\n", debug_d3dbasis(info->basis)); + if (info->degree != WINED3D_DEGREE_CUBIC) + FIXME("Degree is %s, how to handle this?\n", debug_d3ddegree(info->degree)); /* First, get the boundary cube of the input data */ - for(j = 0; j < info->Height; j++) { - for(i = 0; i < info->Width; i++) { - const float *v = (const float *)(data + vtxStride * i + vtxStride * info->Stride * j); + for (j = 0; j < info->height; ++j) + { + for (i = 0; i < info->width; ++i) + { + const float *v = (const float *)(data + vtxStride * i + vtxStride * info->stride * j); if(fabs(v[0]) > max_x) max_x = fabsf(v[0]); if(fabs(v[1]) > max_y) max_y = fabsf(v[1]); if(fabs(v[2]) > max_z) max_z = fabsf(v[2]); @@ -853,8 +877,9 @@ HRESULT tesselate_rectpatch(struct wined3d_device *This, struct WineD3DRectPatch */ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)"); - IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_FILLMODE)); - if(patch->has_normals) { + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_FILLMODE)); + if (patch->has_normals) + { static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 0.0f}; static const GLfloat red[] = {1.0f, 0.0f, 0.0f, 0.0f}; static const GLfloat green[] = {0.0f, 1.0f, 0.0f, 0.0f}; @@ -864,30 +889,30 @@ HRESULT tesselate_rectpatch(struct wined3d_device *This, struct WineD3DRectPatch checkGLcall("glEnable(GL_LIGHTING)"); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, black); checkGLcall("glLightModel for MODEL_AMBIENT"); - IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_AMBIENT)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_AMBIENT)); for (i = 3; i < context->gl_info->limits.lights; ++i) { glDisable(GL_LIGHT0 + i); checkGLcall("glDisable(GL_LIGHT0 + i)"); - IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(i)); + context_invalidate_state(context, STATE_ACTIVELIGHT(i)); } - IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(0)); + context_invalidate_state(context, STATE_ACTIVELIGHT(0)); glLightfv(GL_LIGHT0, GL_DIFFUSE, red); glLightfv(GL_LIGHT0, GL_SPECULAR, black); glLightfv(GL_LIGHT0, GL_AMBIENT, black); glLightfv(GL_LIGHT0, GL_POSITION, red); glEnable(GL_LIGHT0); checkGLcall("Setting up light 1"); - IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(1)); + context_invalidate_state(context, STATE_ACTIVELIGHT(1)); glLightfv(GL_LIGHT1, GL_DIFFUSE, green); glLightfv(GL_LIGHT1, GL_SPECULAR, black); glLightfv(GL_LIGHT1, GL_AMBIENT, black); glLightfv(GL_LIGHT1, GL_POSITION, green); glEnable(GL_LIGHT1); checkGLcall("Setting up light 2"); - IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(2)); + context_invalidate_state(context, STATE_ACTIVELIGHT(2)); glLightfv(GL_LIGHT2, GL_DIFFUSE, blue); glLightfv(GL_LIGHT2, GL_SPECULAR, black); glLightfv(GL_LIGHT2, GL_AMBIENT, black); @@ -895,8 +920,8 @@ HRESULT tesselate_rectpatch(struct wined3d_device *This, struct WineD3DRectPatch glEnable(GL_LIGHT2); checkGLcall("Setting up light 3"); - IWineD3DDeviceImpl_MarkStateDirty(This, STATE_MATERIAL); - IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_COLORVERTEX)); + context_invalidate_state(context, STATE_MATERIAL); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORVERTEX)); glDisable(GL_COLOR_MATERIAL); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black); @@ -941,14 +966,15 @@ HRESULT tesselate_rectpatch(struct wined3d_device *This, struct WineD3DRectPatch feedbuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buffer_size * sizeof(float) * 8); glMap2f(GL_MAP2_VERTEX_3, - 0.0f, 1.0f, vtxStride / sizeof(float), info->Width, - 0.0f, 1.0f, info->Stride * vtxStride / sizeof(float), info->Height, + 0.0f, 1.0f, vtxStride / sizeof(float), info->width, + 0.0f, 1.0f, info->stride * vtxStride / sizeof(float), info->height, (const GLfloat *)data); checkGLcall("glMap2f"); - if(patch->has_texcoords) { + if (patch->has_texcoords) + { glMap2f(GL_MAP2_TEXTURE_COORD_4, - 0.0f, 1.0f, vtxStride / sizeof(float), info->Width, - 0.0f, 1.0f, info->Stride * vtxStride / sizeof(float), info->Height, + 0.0f, 1.0f, vtxStride / sizeof(float), info->width, + 0.0f, 1.0f, info->stride * vtxStride / sizeof(float), info->height, (const GLfloat *)data); checkGLcall("glMap2f"); } @@ -1101,21 +1127,22 @@ HRESULT tesselate_rectpatch(struct wined3d_device *This, struct WineD3DRectPatch } memset(&patch->strided, 0, sizeof(patch->strided)); patch->strided.position.format = WINED3DFMT_R32G32B32_FLOAT; - patch->strided.position.lpData = (BYTE *) patch->mem; - patch->strided.position.dwStride = vtxStride; + patch->strided.position.data = (BYTE *)patch->mem; + patch->strided.position.stride = vtxStride; - if(patch->has_normals) { + if (patch->has_normals) + { patch->strided.normal.format = WINED3DFMT_R32G32B32_FLOAT; - patch->strided.normal.lpData = (BYTE *) patch->mem + 3 * sizeof(float) /* pos */; - patch->strided.normal.dwStride = vtxStride; + patch->strided.normal.data = (BYTE *)patch->mem + 3 * sizeof(float) /* pos */; + patch->strided.normal.stride = vtxStride; } - if(patch->has_texcoords) { - patch->strided.texCoords[0].format = WINED3DFMT_R32G32B32A32_FLOAT; - patch->strided.texCoords[0].lpData = (BYTE *) patch->mem + 3 * sizeof(float) /* pos */; - if(patch->has_normals) { - patch->strided.texCoords[0].lpData += 3 * sizeof(float); - } - patch->strided.texCoords[0].dwStride = vtxStride; + if (patch->has_texcoords) + { + patch->strided.tex_coords[0].format = WINED3DFMT_R32G32B32A32_FLOAT; + patch->strided.tex_coords[0].data = (BYTE *)patch->mem + 3 * sizeof(float) /* pos */; + if (patch->has_normals) + patch->strided.tex_coords[0].data += 3 * sizeof(float); + patch->strided.tex_coords[0].stride = vtxStride; } return WINED3D_OK; diff --git a/reactos/dll/directx/wine/wined3d/gl_compat.c b/reactos/dll/directx/wine/wined3d/gl_compat.c index 57564452f46..7ba21574e42 100644 --- a/reactos/dll/directx/wine/wined3d/gl_compat.c +++ b/reactos/dll/directx/wine/wined3d/gl_compat.c @@ -391,7 +391,7 @@ void add_gl_compat_wrappers(struct wined3d_gl_info *gl_info) * too, which would allow fog coord emulation in a fixed function vertex pipeline replacement. * * Fog vs texture: We apply the fog in the vertex color. An app could set up texturing settings which - * ignore the vertex color, thus effectively disabing our fog. However, in D3D this type of fog is + * ignore the vertex color, thus effectively disabling our fog. However, in D3D this type of fog is * a per-vertex fog too, so the apps shouldn't do that. * * Fog vs lighting: The app could in theory use D3DFOG_NONE table and D3DFOG_NONE vertex fog with diff --git a/reactos/dll/directx/wine/wined3d/glsl_shader.c b/reactos/dll/directx/wine/wined3d/glsl_shader.c index 9b8cd5b4007..27dbfb09571 100644 --- a/reactos/dll/directx/wine/wined3d/glsl_shader.c +++ b/reactos/dll/directx/wine/wined3d/glsl_shader.c @@ -44,20 +44,23 @@ WINE_DECLARE_DEBUG_CHANNEL(d3d); #define WINED3D_GLSL_SAMPLE_LOD 0x4 #define WINED3D_GLSL_SAMPLE_GRAD 0x8 -typedef struct { +struct glsl_dst_param +{ char reg_name[150]; char mask_str[6]; -} glsl_dst_param_t; +}; -typedef struct { +struct glsl_src_param +{ char reg_name[150]; char param_str[200]; -} glsl_src_param_t; +}; -typedef struct { +struct glsl_sample_function +{ const char *name; DWORD coord_mask; -} glsl_sample_function_t; +}; enum heap_node_op { @@ -195,26 +198,9 @@ static void print_glsl_info_log(const struct wined3d_gl_info *gl_info, GLhandleA { int infologLength = 0; char *infoLog; - unsigned int i; - BOOL is_spam; - static const char * const spam[] = - { - "Vertex shader was successfully compiled to run on hardware.\n", /* fglrx */ - "Fragment shader was successfully compiled to run on hardware.\n", /* fglrx, with \n */ - "Fragment shader was successfully compiled to run on hardware.", /* fglrx, no \n */ - "Fragment shader(s) linked, vertex shader(s) linked. \n ", /* fglrx, with \n */ - "Fragment shader(s) linked, vertex shader(s) linked. \n", /* fglrx, with \n */ - "Fragment shader(s) linked, vertex shader(s) linked.", /* fglrx, no \n */ - "Vertex shader(s) linked, no fragment shader(s) defined. \n ", /* fglrx, with \n */ - "Vertex shader(s) linked, no fragment shader(s) defined. \n", /* fglrx, with \n */ - "Vertex shader(s) linked, no fragment shader(s) defined.", /* fglrx, no \n */ - "Fragment shader(s) linked, no vertex shader(s) defined. \n ", /* fglrx, with \n */ - "Fragment shader(s) linked, no vertex shader(s) defined. \n", /* fglrx, with \n */ - "Fragment shader(s) linked, no vertex shader(s) defined.", /* fglrx, no \n */ - }; - - if (!TRACE_ON(d3d_shader) && !FIXME_ON(d3d_shader)) return; + if (!WARN_ON(d3d_shader) && !FIXME_ON(d3d_shader)) + return; GL_EXTCALL(glGetObjectParameterivARB(obj, GL_OBJECT_INFO_LOG_LENGTH_ARB, @@ -226,31 +212,23 @@ static void print_glsl_info_log(const struct wined3d_gl_info *gl_info, GLhandleA { char *ptr, *line; - /* Fglrx doesn't terminate the string properly, but it tells us the proper length. - * So use HEAP_ZERO_MEMORY to avoid uninitialized bytes - */ - infoLog = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, infologLength); + infoLog = HeapAlloc(GetProcessHeap(), 0, infologLength); + /* The info log is supposed to be zero-terminated, but at least some + * versions of fglrx don't terminate the string properly. The reported + * length does include the terminator, so explicitly set it to zero + * here. */ + infoLog[infologLength - 1] = 0; GL_EXTCALL(glGetInfoLogARB(obj, infologLength, NULL, infoLog)); - is_spam = FALSE; - - for (i = 0; i < sizeof(spam) / sizeof(*spam); ++i) - { - if (!strcmp(infoLog, spam[i])) - { - is_spam = TRUE; - break; - } - } ptr = infoLog; - if (is_spam) + if (gl_info->quirks & WINED3D_QUIRK_INFO_LOG_SPAM) { - TRACE("Spam received from GLSL shader #%u:\n", obj); - while ((line = get_info_log_line(&ptr))) TRACE(" %s\n", line); + WARN("Info log received from GLSL shader #%u:\n", obj); + while ((line = get_info_log_line(&ptr))) WARN(" %s\n", line); } else { - FIXME("Error received from GLSL shader #%u:\n", obj); + FIXME("Info log received from GLSL shader #%u:\n", obj); while ((line = get_info_log_line(&ptr))) FIXME(" %s\n", line); } HeapFree(GetProcessHeap(), 0, infoLog); @@ -348,7 +326,7 @@ static void shader_glsl_validate_link(const struct wined3d_gl_info *gl_info, GLh */ /* GL locking is done by the caller */ static void shader_glsl_load_psamplers(const struct wined3d_gl_info *gl_info, - DWORD *tex_unit_map, GLhandleARB programId) + const DWORD *tex_unit_map, GLhandleARB programId) { GLint name_loc; int i; @@ -373,7 +351,7 @@ static void shader_glsl_load_psamplers(const struct wined3d_gl_info *gl_info, /* GL locking is done by the caller */ static void shader_glsl_load_vsamplers(const struct wined3d_gl_info *gl_info, - DWORD *tex_unit_map, GLhandleARB programId) + const DWORD *tex_unit_map, GLhandleARB programId) { GLint name_loc; char sampler_name[20]; @@ -448,11 +426,9 @@ static inline void walk_constant_heap(const struct wined3d_gl_info *gl_info, con } case HEAP_NODE_POP: - { heap_idx >>= 1; --stack_idx; break; - } } } checkGLcall("walk_constant_heap()"); @@ -523,11 +499,9 @@ static inline void walk_constant_heap_clamped(const struct wined3d_gl_info *gl_i } case HEAP_NODE_POP: - { heap_idx >>= 1; --stack_idx; break; - } } } checkGLcall("walk_constant_heap_clamped()"); @@ -539,7 +513,7 @@ static void shader_glsl_load_constantsF(const struct wined3d_shader *shader, con const float *constants, const GLint *constant_locations, const struct constant_heap *heap, unsigned char *stack, UINT version) { - const local_constant *lconst; + const struct wined3d_shader_lconst *lconst; /* 1.X pshaders have the constants clamped to [-1;1] implicitly. */ if (shader->reg_maps.shader_version.major == 1 @@ -555,7 +529,7 @@ static void shader_glsl_load_constantsF(const struct wined3d_shader *shader, con } /* Immediate constants are clamped to [-1;1] at shader creation time if needed */ - LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, local_constant, entry) + LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry) { GLint location = constant_locations[lconst->idx]; /* We found this uniform name in the program - go ahead and send the data */ @@ -588,7 +562,7 @@ static void shader_glsl_load_constantsI(const struct wined3d_shader *shader, con ptr = list_head(&shader->constantsI); while (ptr) { - const struct local_constant *lconst = LIST_ENTRY(ptr, const struct local_constant, entry); + const struct wined3d_shader_lconst *lconst = LIST_ENTRY(ptr, const struct wined3d_shader_lconst, entry); unsigned int idx = lconst->idx; const GLint *values = (const GLint *)lconst->value; @@ -658,7 +632,7 @@ static void shader_glsl_load_constantsB(const struct wined3d_shader *shader, con ptr = list_head(&shader->constantsB); while (ptr) { - const struct local_constant *lconst = LIST_ENTRY(ptr, const struct local_constant, entry); + const struct wined3d_shader_lconst *lconst = LIST_ENTRY(ptr, const struct wined3d_shader_lconst, entry); unsigned int idx = lconst->idx; const GLint *values = (const GLint *)lconst->value; @@ -740,6 +714,7 @@ static void shader_glsl_load_constants(const struct wined3d_context *context, const struct wined3d_gl_info *gl_info = context->gl_info; struct wined3d_device *device = context->swapchain->device; struct wined3d_stateblock *stateBlock = device->stateBlock; + const struct wined3d_state *state = &stateBlock->state; struct shader_glsl_priv *priv = device->shader_priv; float position_fixup[4]; @@ -757,40 +732,40 @@ static void shader_glsl_load_constants(const struct wined3d_context *context, if (useVertexShader) { - const struct wined3d_shader *vshader = stateBlock->state.vertex_shader; + const struct wined3d_shader *vshader = state->vertex_shader; /* Load DirectX 9 float constants/uniforms for vertex shader */ - shader_glsl_load_constantsF(vshader, gl_info, stateBlock->state.vs_consts_f, + shader_glsl_load_constantsF(vshader, gl_info, state->vs_consts_f, prog->vuniformF_locations, &priv->vconst_heap, priv->stack, constant_version); /* Load DirectX 9 integer constants/uniforms for vertex shader */ - shader_glsl_load_constantsI(vshader, gl_info, prog->vuniformI_locations, stateBlock->state.vs_consts_i, + shader_glsl_load_constantsI(vshader, gl_info, prog->vuniformI_locations, state->vs_consts_i, stateBlock->changed.vertexShaderConstantsI & vshader->reg_maps.integer_constants); /* Load DirectX 9 boolean constants/uniforms for vertex shader */ - shader_glsl_load_constantsB(vshader, gl_info, programId, stateBlock->state.vs_consts_b, + shader_glsl_load_constantsB(vshader, gl_info, programId, state->vs_consts_b, stateBlock->changed.vertexShaderConstantsB & vshader->reg_maps.boolean_constants); /* Upload the position fixup params */ - shader_get_position_fixup(context, &stateBlock->state, position_fixup); + shader_get_position_fixup(context, state, position_fixup); GL_EXTCALL(glUniform4fvARB(prog->posFixup_location, 1, position_fixup)); checkGLcall("glUniform4fvARB"); } if (usePixelShader) { - const struct wined3d_shader *pshader = stateBlock->state.pixel_shader; + const struct wined3d_shader *pshader = state->pixel_shader; /* Load DirectX 9 float constants/uniforms for pixel shader */ - shader_glsl_load_constantsF(pshader, gl_info, stateBlock->state.ps_consts_f, + shader_glsl_load_constantsF(pshader, gl_info, state->ps_consts_f, prog->puniformF_locations, &priv->pconst_heap, priv->stack, constant_version); /* Load DirectX 9 integer constants/uniforms for pixel shader */ - shader_glsl_load_constantsI(pshader, gl_info, prog->puniformI_locations, stateBlock->state.ps_consts_i, + shader_glsl_load_constantsI(pshader, gl_info, prog->puniformI_locations, state->ps_consts_i, stateBlock->changed.pixelShaderConstantsI & pshader->reg_maps.integer_constants); /* Load DirectX 9 boolean constants/uniforms for pixel shader */ - shader_glsl_load_constantsB(pshader, gl_info, programId, stateBlock->state.ps_consts_b, + shader_glsl_load_constantsB(pshader, gl_info, programId, state->ps_consts_b, stateBlock->changed.pixelShaderConstantsB & pshader->reg_maps.boolean_constants); /* Upload the environment bump map matrix if needed. The needsbumpmat member specifies the texture stage to load the matrix from. @@ -801,7 +776,7 @@ static void shader_glsl_load_constants(const struct wined3d_context *context, if(prog->bumpenvmat_location[i] == -1) continue; - data = (const float *)&stateBlock->state.texture_states[i][WINED3DTSS_BUMPENVMAT00]; + data = (const float *)&state->texture_states[i][WINED3D_TSS_BUMPENV_MAT00]; GL_EXTCALL(glUniformMatrix2fvARB(prog->bumpenvmat_location[i], 1, 0, data)); checkGLcall("glUniformMatrix2fvARB"); @@ -810,8 +785,8 @@ static void shader_glsl_load_constants(const struct wined3d_context *context, * needsbumpmat check. */ if (prog->luminancescale_location[i] != -1) { - const GLfloat *scale = (const GLfloat *)&stateBlock->state.texture_states[i][WINED3DTSS_BUMPENVLSCALE]; - const GLfloat *offset = (const GLfloat *)&stateBlock->state.texture_states[i][WINED3DTSS_BUMPENVLOFFSET]; + const GLfloat *scale = (const GLfloat *)&state->texture_states[i][WINED3D_TSS_BUMPENV_LSCALE]; + const GLfloat *offset = (const GLfloat *)&state->texture_states[i][WINED3D_TSS_BUMPENV_LOFFSET]; GL_EXTCALL(glUniform1fvARB(prog->luminancescale_location[i], 1, scale)); checkGLcall("glUniform1fvARB"); @@ -820,7 +795,7 @@ static void shader_glsl_load_constants(const struct wined3d_context *context, } } - if (pshader->u.ps.vpos_uniform) + if (prog->ycorrection_location != -1) { float correction_params[4]; @@ -849,7 +824,7 @@ static void shader_glsl_load_constants(const struct wined3d_context *context, } } -static inline void update_heap_entry(struct constant_heap *heap, unsigned int idx, +static void update_heap_entry(const struct constant_heap *heap, unsigned int idx, unsigned int heap_idx, DWORD new_version) { struct constant_entry *entries = heap->entries; @@ -915,15 +890,15 @@ static unsigned int vec4_varyings(DWORD shader_major, const struct wined3d_gl_in /** Generate the variable & register declarations for the GLSL output target */ static void shader_generate_glsl_declarations(const struct wined3d_context *context, - struct wined3d_shader_buffer *buffer, struct wined3d_shader *shader, - const struct wined3d_shader_reg_maps *reg_maps, struct shader_glsl_ctx_priv *ctx_priv) + struct wined3d_shader_buffer *buffer, const struct wined3d_shader *shader, + const struct wined3d_shader_reg_maps *reg_maps, const struct shader_glsl_ctx_priv *ctx_priv) { const struct wined3d_state *state = &shader->device->stateBlock->state; const struct ps_compile_args *ps_args = ctx_priv->cur_ps_args; const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_fb_state *fb = &shader->device->fb; unsigned int i, extra_constants_needed = 0; - const local_constant *lconst; + const struct wined3d_shader_lconst *lconst; DWORD map; /* There are some minor differences between pixel and vertex shaders */ @@ -1040,7 +1015,6 @@ static void shader_generate_glsl_declarations(const struct wined3d_context *cont + 1 < gl_info->limits.glsl_ps_float_constants) { shader_addline(buffer, "uniform vec4 ycorrection;\n"); - shader->u.ps.vpos_uniform = 1; extra_constants_needed++; } else @@ -1155,16 +1129,15 @@ static void shader_generate_glsl_declarations(const struct wined3d_context *cont */ if (pshader && reg_maps->shader_version.major >= 3) { + UINT in_count = min(vec4_varyings(reg_maps->shader_version.major, gl_info), shader->limits.packed_input); + if (use_vs(state)) - { - shader_addline(buffer, "varying vec4 IN[%u];\n", vec4_varyings(reg_maps->shader_version.major, gl_info)); - } else { + shader_addline(buffer, "varying vec4 IN[%u];\n", in_count); + else /* TODO: Write a replacement shader for the fixed function vertex pipeline, so this isn't needed. * For fixed function vertex processing + 3.0 pixel shader we need a separate function in the - * pixel shader that reads the fixed function color into the packed input registers. - */ - shader_addline(buffer, "vec4 IN[%u];\n", vec4_varyings(reg_maps->shader_version.major, gl_info)); - } + * pixel shader that reads the fixed function color into the packed input registers. */ + shader_addline(buffer, "vec4 IN[%u];\n", in_count); } /* Declare output register temporaries */ @@ -1202,7 +1175,7 @@ static void shader_generate_glsl_declarations(const struct wined3d_context *cont */ if (!shader->load_local_constsF) { - LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, local_constant, entry) + LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry) { shader_addline(buffer, "uniform vec4 %cLC%u;\n", prefix, lconst->idx); } @@ -1237,7 +1210,7 @@ static void shader_generate_glsl_declarations(const struct wined3d_context *cont /* Prototypes */ static void shader_glsl_add_src_param(const struct wined3d_shader_instruction *ins, - const struct wined3d_shader_src_param *wined3d_src, DWORD mask, glsl_src_param_t *glsl_src); + const struct wined3d_shader_src_param *wined3d_src, DWORD mask, struct glsl_src_param *glsl_src); /** Used for opcode modifiers - They multiply the result by the specified amount */ static const char * const shift_glsl_tab[] = { @@ -1260,7 +1233,8 @@ static const char * const shift_glsl_tab[] = { }; /* Generate a GLSL parameter that does the input modifier computation and return the input register/mask to use */ -static void shader_glsl_gen_modifier(DWORD src_modifier, const char *in_reg, const char *in_regswizzle, char *out_str) +static void shader_glsl_gen_modifier(enum wined3d_shader_src_modifier src_modifier, + const char *in_reg, const char *in_regswizzle, char *out_str) { out_str[0] = 0; @@ -1318,7 +1292,7 @@ static void shader_glsl_get_register_name(const struct wined3d_shader_register * /* oPos, oFog and oPts in D3D */ static const char * const hwrastout_reg_names[] = {"OUT[10]", "OUT[11].x", "OUT[11].y"}; - struct wined3d_shader *shader = ins->ctx->shader; + const struct wined3d_shader *shader = ins->ctx->shader; const struct wined3d_shader_reg_maps *reg_maps = ins->ctx->reg_maps; const struct wined3d_gl_info *gl_info = ins->ctx->gl_info; char pshader = shader_is_pshader_version(reg_maps->shader_version.type); @@ -1349,7 +1323,7 @@ static void shader_glsl_get_register_name(const struct wined3d_shader_register * if (reg->rel_addr) { - glsl_src_param_t rel_param; + struct glsl_src_param rel_param; shader_glsl_add_src_param(ins, reg->rel_addr, WINED3DSP_WRITEMASK_0, &rel_param); @@ -1405,7 +1379,7 @@ static void shader_glsl_get_register_name(const struct wined3d_shader_register * /* Relative addressing */ if (reg->rel_addr) { - glsl_src_param_t rel_param; + struct glsl_src_param rel_param; shader_glsl_add_src_param(ins, reg->rel_addr, WINED3DSP_WRITEMASK_0, &rel_param); if (reg->idx) sprintf(register_name, "%cC[%s + %u]", prefix, rel_param.param_str, reg->idx); else sprintf(register_name, "%cC[%s]", prefix, rel_param.param_str); @@ -1582,7 +1556,7 @@ static void shader_glsl_get_swizzle(const struct wined3d_shader_src_param *param * Also, return the actual register name and swizzle in case the * caller needs this information as well. */ static void shader_glsl_add_src_param(const struct wined3d_shader_instruction *ins, - const struct wined3d_shader_src_param *wined3d_src, DWORD mask, glsl_src_param_t *glsl_src) + const struct wined3d_shader_src_param *wined3d_src, DWORD mask, struct glsl_src_param *glsl_src) { BOOL is_color = FALSE; char swizzle_str[6]; @@ -1600,7 +1574,7 @@ static void shader_glsl_add_src_param(const struct wined3d_shader_instruction *i * Also, return the actual register name and swizzle in case the * caller needs this information as well. */ static DWORD shader_glsl_add_dst_param(const struct wined3d_shader_instruction *ins, - const struct wined3d_shader_dst_param *wined3d_dst, glsl_dst_param_t *glsl_dst) + const struct wined3d_shader_dst_param *wined3d_dst, struct glsl_dst_param *glsl_dst) { BOOL is_color = FALSE; @@ -1615,7 +1589,7 @@ static DWORD shader_glsl_add_dst_param(const struct wined3d_shader_instruction * static DWORD shader_glsl_append_dst_ext(struct wined3d_shader_buffer *buffer, const struct wined3d_shader_instruction *ins, const struct wined3d_shader_dst_param *dst) { - glsl_dst_param_t glsl_dst; + struct glsl_dst_param glsl_dst; DWORD mask; mask = shader_glsl_add_dst_param(ins, dst, &glsl_dst); @@ -1633,7 +1607,7 @@ static DWORD shader_glsl_append_dst(struct wined3d_shader_buffer *buffer, const /** Process GLSL instruction modifiers */ static void shader_glsl_add_instruction_modifiers(const struct wined3d_shader_instruction *ins) { - glsl_dst_param_t dst_param; + struct glsl_dst_param dst_param; DWORD modifiers; if (!ins->dst_count) return; @@ -1661,25 +1635,26 @@ static void shader_glsl_add_instruction_modifiers(const struct wined3d_shader_in } } -static inline const char *shader_get_comp_op(DWORD op) +static const char *shader_glsl_get_rel_op(enum wined3d_shader_rel_op op) { - switch (op) { - case COMPARISON_GT: return ">"; - case COMPARISON_EQ: return "=="; - case COMPARISON_GE: return ">="; - case COMPARISON_LT: return "<"; - case COMPARISON_NE: return "!="; - case COMPARISON_LE: return "<="; + switch (op) + { + case WINED3D_SHADER_REL_OP_GT: return ">"; + case WINED3D_SHADER_REL_OP_EQ: return "=="; + case WINED3D_SHADER_REL_OP_GE: return ">="; + case WINED3D_SHADER_REL_OP_LT: return "<"; + case WINED3D_SHADER_REL_OP_NE: return "!="; + case WINED3D_SHADER_REL_OP_LE: return "<="; default: - FIXME("Unrecognized comparison value: %u\n", op); + FIXME("Unrecognized operator %#x.\n", op); return "(\?\?)"; } } static void shader_glsl_get_sample_function(const struct wined3d_shader_context *ctx, - DWORD sampler_idx, DWORD flags, glsl_sample_function_t *sample_function) + DWORD sampler_idx, DWORD flags, struct glsl_sample_function *sample_function) { - WINED3DSAMPLER_TEXTURE_TYPE sampler_type = ctx->reg_maps->sampler_type[sampler_idx]; + enum wined3d_sampler_texture_type sampler_type = ctx->reg_maps->sampler_type[sampler_idx]; const struct wined3d_gl_info *gl_info = ctx->gl_info; BOOL shadow = shader_is_pshader_version(ctx->reg_maps->shader_version.type) && (((const struct shader_glsl_ctx_priv *)ctx->backend_data)->cur_ps_args->shadow & (1 << sampler_idx)); @@ -1964,7 +1939,7 @@ static void shader_glsl_color_correction(const struct wined3d_shader_instruction { struct wined3d_shader_dst_param dst; unsigned int mask_size, remaining; - glsl_dst_param_t dst_param; + struct glsl_dst_param dst_param; char arguments[256]; DWORD mask; @@ -2025,9 +2000,8 @@ static void shader_glsl_color_correction(const struct wined3d_shader_instruction } static void PRINTF_ATTR(8, 9) shader_glsl_gen_sample_code(const struct wined3d_shader_instruction *ins, - DWORD sampler, const glsl_sample_function_t *sample_function, DWORD swizzle, - const char *dx, const char *dy, - const char *bias, const char *coord_reg_fmt, ...) + DWORD sampler, const struct glsl_sample_function *sample_function, DWORD swizzle, + const char *dx, const char *dy, const char *bias, const char *coord_reg_fmt, ...) { const char *sampler_base; char dst_swizzle[6]; @@ -2092,8 +2066,8 @@ static void PRINTF_ATTR(8, 9) shader_glsl_gen_sample_code(const struct wined3d_s static void shader_glsl_arith(const struct wined3d_shader_instruction *ins) { struct wined3d_shader_buffer *buffer = ins->ctx->buffer; - glsl_src_param_t src0_param; - glsl_src_param_t src1_param; + struct glsl_src_param src0_param; + struct glsl_src_param src1_param; DWORD write_mask; char op; @@ -2120,7 +2094,7 @@ static void shader_glsl_mov(const struct wined3d_shader_instruction *ins) { const struct wined3d_gl_info *gl_info = ins->ctx->gl_info; struct wined3d_shader_buffer *buffer = ins->ctx->buffer; - glsl_src_param_t src0_param; + struct glsl_src_param src0_param; DWORD write_mask; write_mask = shader_glsl_append_dst(buffer, ins); @@ -2172,8 +2146,8 @@ static void shader_glsl_mov(const struct wined3d_shader_instruction *ins) static void shader_glsl_dot(const struct wined3d_shader_instruction *ins) { struct wined3d_shader_buffer *buffer = ins->ctx->buffer; - glsl_src_param_t src0_param; - glsl_src_param_t src1_param; + struct glsl_src_param src0_param; + struct glsl_src_param src1_param; DWORD dst_write_mask, src_write_mask; unsigned int dst_size = 0; @@ -2203,8 +2177,8 @@ static void shader_glsl_dot(const struct wined3d_shader_instruction *ins) static void shader_glsl_cross(const struct wined3d_shader_instruction *ins) { DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; - glsl_src_param_t src0_param; - glsl_src_param_t src1_param; + struct glsl_src_param src0_param; + struct glsl_src_param src1_param; char dst_mask[6]; shader_glsl_get_write_mask(&ins->dst[0], dst_mask); @@ -2220,8 +2194,8 @@ static void shader_glsl_cross(const struct wined3d_shader_instruction *ins) static void shader_glsl_pow(const struct wined3d_shader_instruction *ins) { struct wined3d_shader_buffer *buffer = ins->ctx->buffer; - glsl_src_param_t src0_param; - glsl_src_param_t src1_param; + struct glsl_src_param src0_param; + struct glsl_src_param src1_param; DWORD dst_write_mask; unsigned int dst_size; @@ -2249,7 +2223,7 @@ static void shader_glsl_pow(const struct wined3d_shader_instruction *ins) static void shader_glsl_log(const struct wined3d_shader_instruction *ins) { struct wined3d_shader_buffer *buffer = ins->ctx->buffer; - glsl_src_param_t src0_param; + struct glsl_src_param src0_param; DWORD dst_write_mask; unsigned int dst_size; @@ -2274,7 +2248,7 @@ static void shader_glsl_log(const struct wined3d_shader_instruction *ins) static void shader_glsl_map2gl(const struct wined3d_shader_instruction *ins) { struct wined3d_shader_buffer *buffer = ins->ctx->buffer; - glsl_src_param_t src_param; + struct glsl_src_param src_param; const char *instruction; DWORD write_mask; unsigned i; @@ -2316,7 +2290,7 @@ static void shader_glsl_map2gl(const struct wined3d_shader_instruction *ins) static void shader_glsl_nrm(const struct wined3d_shader_instruction *ins) { struct wined3d_shader_buffer *buffer = ins->ctx->buffer; - glsl_src_param_t src_param; + struct glsl_src_param src_param; unsigned int mask_size; DWORD write_mask; char dst_mask[6]; @@ -2352,7 +2326,7 @@ static void shader_glsl_nrm(const struct wined3d_shader_instruction *ins) */ static void shader_glsl_expp(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src_param; + struct glsl_src_param src_param; shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src_param); @@ -2386,7 +2360,7 @@ static void shader_glsl_expp(const struct wined3d_shader_instruction *ins) /** Process the RCP (reciprocal or inverse) opcode in GLSL (dst = 1 / src) */ static void shader_glsl_rcp(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src_param; + struct glsl_src_param src_param; DWORD write_mask; unsigned int mask_size; @@ -2409,7 +2383,7 @@ static void shader_glsl_rcp(const struct wined3d_shader_instruction *ins) static void shader_glsl_rsq(const struct wined3d_shader_instruction *ins) { struct wined3d_shader_buffer *buffer = ins->ctx->buffer; - glsl_src_param_t src_param; + struct glsl_src_param src_param; DWORD write_mask; unsigned int mask_size; @@ -2433,8 +2407,8 @@ static void shader_glsl_rsq(const struct wined3d_shader_instruction *ins) /** Process signed comparison opcodes in GLSL. */ static void shader_glsl_compare(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param; - glsl_src_param_t src1_param; + struct glsl_src_param src0_param; + struct glsl_src_param src1_param; DWORD write_mask; unsigned int mask_size; @@ -2484,9 +2458,9 @@ static void shader_glsl_compare(const struct wined3d_shader_instruction *ins) /** Process CMP instruction in GLSL (dst = src0 >= 0.0 ? src1 : src2), per channel */ static void shader_glsl_cmp(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param; - glsl_src_param_t src1_param; - glsl_src_param_t src2_param; + struct glsl_src_param src0_param; + struct glsl_src_param src1_param; + struct glsl_src_param src2_param; DWORD write_mask, cmp_channel = 0; unsigned int i, j; char mask_char[6]; @@ -2562,9 +2536,9 @@ static void shader_glsl_cmp(const struct wined3d_shader_instruction *ins) static void shader_glsl_cnd(const struct wined3d_shader_instruction *ins) { struct wined3d_shader_dst_param dst; - glsl_src_param_t src0_param; - glsl_src_param_t src1_param; - glsl_src_param_t src2_param; + struct glsl_src_param src0_param; + struct glsl_src_param src1_param; + struct glsl_src_param src2_param; DWORD write_mask, cmp_channel = 0; unsigned int i, j; DWORD dst_mask; @@ -2618,9 +2592,9 @@ static void shader_glsl_cnd(const struct wined3d_shader_instruction *ins) /** GLSL code generation for WINED3DSIO_MAD: Multiply the first 2 opcodes, then add the last */ static void shader_glsl_mad(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param; - glsl_src_param_t src1_param; - glsl_src_param_t src2_param; + struct glsl_src_param src0_param; + struct glsl_src_param src1_param; + struct glsl_src_param src2_param; DWORD write_mask; write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins); @@ -2695,9 +2669,9 @@ static void shader_glsl_mnxn(const struct wined3d_shader_instruction *ins) */ static void shader_glsl_lrp(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param; - glsl_src_param_t src1_param; - glsl_src_param_t src2_param; + struct glsl_src_param src0_param; + struct glsl_src_param src1_param; + struct glsl_src_param src2_param; DWORD write_mask; write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins); @@ -2718,9 +2692,9 @@ static void shader_glsl_lrp(const struct wined3d_shader_instruction *ins) */ static void shader_glsl_lit(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param; - glsl_src_param_t src1_param; - glsl_src_param_t src3_param; + struct glsl_src_param src0_param; + struct glsl_src_param src1_param; + struct glsl_src_param src3_param; char dst_mask[6]; shader_glsl_append_dst(ins->ctx->buffer, ins); @@ -2737,6 +2711,7 @@ static void shader_glsl_lit(const struct wined3d_shader_instruction *ins) * if(src.x > 0.0 && src.y > 0.0) dst.z = pow(src.y, power); * else dst.z = 0.0; * dst.w = 1.0; + * (where power = src.w clamped between -128 and 128) * * Obviously that has quite a few conditionals in it which we don't like. So the first step is this: * dst.x = 1.0 ... No further explanation needed @@ -2749,11 +2724,17 @@ static void shader_glsl_lit(const struct wined3d_shader_instruction *ins) * * step(0.0, x) will return 1 if src.x > 0.0, and 0 otherwise. So if y is 0 we get pow(0.0 * 1.0, power), * which sets dst.z to 0. If y > 0, but x = 0.0, we get pow(y * 0.0, power), which results in 0 too. - * if both x and y are > 0, we get pow(y * 1.0, power), as it is supposed to + * if both x and y are > 0, we get pow(y * 1.0, power), as it is supposed to. + * + * Unfortunately pow(0.0 ^ 0.0) returns NaN on most GPUs, but lit with src.y = 0 and src.w = 0 returns + * a non-NaN value in dst.z. What we return doesn't matter, as long as it is not NaN. Return 0, which is + * what all Windows HW drivers and GL_ARB_vertex_program's LIT do. */ shader_addline(ins->ctx->buffer, - "vec4(1.0, max(%s, 0.0), pow(max(0.0, %s) * step(0.0, %s), clamp(%s, -128.0, 128.0)), 1.0)%s);\n", - src0_param.param_str, src1_param.param_str, src0_param.param_str, src3_param.param_str, dst_mask); + "vec4(1.0, max(%s, 0.0), %s == 0.0 ? 0.0 : " + "pow(max(0.0, %s) * step(0.0, %s), clamp(%s, -128.0, 128.0)), 1.0)%s);\n", + src0_param.param_str, src3_param.param_str, src1_param.param_str, + src0_param.param_str, src3_param.param_str, dst_mask); } /** Process the WINED3DSIO_DST instruction in GLSL: @@ -2764,10 +2745,10 @@ static void shader_glsl_lit(const struct wined3d_shader_instruction *ins) */ static void shader_glsl_dst(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0y_param; - glsl_src_param_t src0z_param; - glsl_src_param_t src1y_param; - glsl_src_param_t src1w_param; + struct glsl_src_param src0y_param; + struct glsl_src_param src0z_param; + struct glsl_src_param src1y_param; + struct glsl_src_param src1w_param; char dst_mask[6]; shader_glsl_append_dst(ins->ctx->buffer, ins); @@ -2793,7 +2774,7 @@ static void shader_glsl_dst(const struct wined3d_shader_instruction *ins) */ static void shader_glsl_sincos(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param; + struct glsl_src_param src0_param; DWORD write_mask; write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins); @@ -2824,7 +2805,7 @@ static void shader_glsl_sincos(const struct wined3d_shader_instruction *ins) */ static void shader_glsl_sgn(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param; + struct glsl_src_param src0_param; DWORD write_mask; write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins); @@ -2842,10 +2823,10 @@ static void shader_glsl_sgn(const struct wined3d_shader_instruction *ins) static void shader_glsl_loop(const struct wined3d_shader_instruction *ins) { struct wined3d_shader_loop_state *loop_state = ins->ctx->loop_state; - glsl_src_param_t src1_param; - struct wined3d_shader *shader = ins->ctx->shader; + const struct wined3d_shader *shader = ins->ctx->shader; + const struct wined3d_shader_lconst *constant; + struct glsl_src_param src1_param; const DWORD *control_values = NULL; - const local_constant *constant; shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_ALL, &src1_param); @@ -2856,7 +2837,7 @@ static void shader_glsl_loop(const struct wined3d_shader_instruction *ins) */ if (ins->src[1].reg.type == WINED3DSPR_CONSTINT) { - LIST_FOR_EACH_ENTRY(constant, &shader->constantsI, local_constant, entry) + LIST_FOR_EACH_ENTRY(constant, &shader->constantsI, struct wined3d_shader_lconst, entry) { if (constant->idx == ins->src[1].reg.idx) { @@ -2926,16 +2907,16 @@ static void shader_glsl_end(const struct wined3d_shader_instruction *ins) static void shader_glsl_rep(const struct wined3d_shader_instruction *ins) { - struct wined3d_shader *shader = ins->ctx->shader; + const struct wined3d_shader *shader = ins->ctx->shader; struct wined3d_shader_loop_state *loop_state = ins->ctx->loop_state; - glsl_src_param_t src0_param; + const struct wined3d_shader_lconst *constant; + struct glsl_src_param src0_param; const DWORD *control_values = NULL; - const local_constant *constant; /* Try to hardcode local values to help the GLSL compiler to unroll and optimize the loop */ if (ins->src[0].reg.type == WINED3DSPR_CONSTINT) { - LIST_FOR_EACH_ENTRY(constant, &shader->constantsI, local_constant, entry) + LIST_FOR_EACH_ENTRY(constant, &shader->constantsI, struct wined3d_shader_lconst, entry) { if (constant->idx == ins->src[0].reg.idx) { @@ -2964,7 +2945,7 @@ static void shader_glsl_rep(const struct wined3d_shader_instruction *ins) static void shader_glsl_if(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param; + struct glsl_src_param src0_param; shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param); shader_addline(ins->ctx->buffer, "if (%s) {\n", src0_param.param_str); @@ -2972,14 +2953,14 @@ static void shader_glsl_if(const struct wined3d_shader_instruction *ins) static void shader_glsl_ifc(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param; - glsl_src_param_t src1_param; + struct glsl_src_param src0_param; + struct glsl_src_param src1_param; shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param); shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_0, &src1_param); shader_addline(ins->ctx->buffer, "if (%s %s %s) {\n", - src0_param.param_str, shader_get_comp_op(ins->flags), src1_param.param_str); + src0_param.param_str, shader_glsl_get_rel_op(ins->flags), src1_param.param_str); } static void shader_glsl_else(const struct wined3d_shader_instruction *ins) @@ -2995,14 +2976,14 @@ static void shader_glsl_break(const struct wined3d_shader_instruction *ins) /* FIXME: According to MSDN the compare is done per component. */ static void shader_glsl_breakc(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param; - glsl_src_param_t src1_param; + struct glsl_src_param src0_param; + struct glsl_src_param src1_param; shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param); shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_0, &src1_param); shader_addline(ins->ctx->buffer, "if (%s %s %s) break;\n", - src0_param.param_str, shader_get_comp_op(ins->flags), src1_param.param_str); + src0_param.param_str, shader_glsl_get_rel_op(ins->flags), src1_param.param_str); } static void shader_glsl_label(const struct wined3d_shader_instruction *ins) @@ -3018,7 +2999,7 @@ static void shader_glsl_call(const struct wined3d_shader_instruction *ins) static void shader_glsl_callnz(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src1_param; + struct glsl_src_param src1_param; shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_0, &src1_param); shader_addline(ins->ctx->buffer, "if (%s) subroutine%u();\n", src1_param.param_str, ins->src[0].reg.idx); @@ -3036,11 +3017,11 @@ static void shader_glsl_ret(const struct wined3d_shader_instruction *ins) ********************************************/ static void shader_glsl_tex(const struct wined3d_shader_instruction *ins) { - struct wined3d_shader *shader = ins->ctx->shader; + const struct wined3d_shader *shader = ins->ctx->shader; struct wined3d_device *device = shader->device; DWORD shader_version = WINED3D_SHADER_VERSION(ins->ctx->reg_maps->shader_version.major, ins->ctx->reg_maps->shader_version.minor); - glsl_sample_function_t sample_function; + struct glsl_sample_function sample_function; const struct wined3d_texture *texture; DWORD sample_flags = 0; DWORD sampler_idx; @@ -3057,23 +3038,33 @@ static void shader_glsl_tex(const struct wined3d_shader_instruction *ins) const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data; DWORD flags = (priv->cur_ps_args->tex_transform >> sampler_idx * WINED3D_PSARGS_TEXTRANSFORM_SHIFT) & WINED3D_PSARGS_TEXTRANSFORM_MASK; - WINED3DSAMPLER_TEXTURE_TYPE sampler_type = ins->ctx->reg_maps->sampler_type[sampler_idx]; + enum wined3d_sampler_texture_type sampler_type = ins->ctx->reg_maps->sampler_type[sampler_idx]; /* Projected cube textures don't make a lot of sense, the resulting coordinates stay the same. */ - if (flags & WINED3D_PSARGS_PROJECTED && sampler_type != WINED3DSTT_CUBE) { + if (flags & WINED3D_PSARGS_PROJECTED && sampler_type != WINED3DSTT_CUBE) + { sample_flags |= WINED3D_GLSL_SAMPLE_PROJECTED; - switch (flags & ~WINED3D_PSARGS_PROJECTED) { - case WINED3DTTFF_COUNT1: FIXME("WINED3DTTFF_PROJECTED with WINED3DTTFF_COUNT1?\n"); break; - case WINED3DTTFF_COUNT2: mask = WINED3DSP_WRITEMASK_1; break; - case WINED3DTTFF_COUNT3: mask = WINED3DSP_WRITEMASK_2; break; - case WINED3DTTFF_COUNT4: - case WINED3DTTFF_DISABLE: mask = WINED3DSP_WRITEMASK_3; break; + switch (flags & ~WINED3D_PSARGS_PROJECTED) + { + case WINED3D_TTFF_COUNT1: + FIXME("WINED3D_TTFF_PROJECTED with WINED3D_TTFF_COUNT1?\n"); + break; + case WINED3D_TTFF_COUNT2: + mask = WINED3DSP_WRITEMASK_1; + break; + case WINED3D_TTFF_COUNT3: + mask = WINED3DSP_WRITEMASK_2; + break; + case WINED3D_TTFF_COUNT4: + case WINED3D_TTFF_DISABLE: + mask = WINED3DSP_WRITEMASK_3; + break; } } } else if (shader_version < WINED3D_SHADER_VERSION(2,0)) { - DWORD src_mod = ins->src[0].modifiers; + enum wined3d_shader_src_modifier src_mod = ins->src[0].modifiers; if (src_mod == WINED3DSPSM_DZ) { sample_flags |= WINED3D_GLSL_SAMPLE_PROJECTED; @@ -3108,12 +3099,14 @@ static void shader_glsl_tex(const struct wined3d_shader_instruction *ins) shader_glsl_write_mask_to_str(mask, coord_mask); shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, NULL, NULL, NULL, "T%u%s", sampler_idx, coord_mask); - } else { - glsl_src_param_t coord_param; + } + else + { + struct glsl_src_param coord_param; shader_glsl_add_src_param(ins, &ins->src[0], mask, &coord_param); if (ins->flags & WINED3DSI_TEXLD_BIAS) { - glsl_src_param_t bias; + struct glsl_src_param bias; shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_3, &bias); shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, NULL, NULL, bias.param_str, "%s", coord_param.param_str); @@ -3126,12 +3119,12 @@ static void shader_glsl_tex(const struct wined3d_shader_instruction *ins) static void shader_glsl_texldd(const struct wined3d_shader_instruction *ins) { - struct wined3d_shader *shader = ins->ctx->shader; + const struct wined3d_shader *shader = ins->ctx->shader; struct wined3d_device *device = shader->device; const struct wined3d_gl_info *gl_info = ins->ctx->gl_info; - glsl_sample_function_t sample_function; - glsl_src_param_t coord_param, dx_param, dy_param; + struct glsl_src_param coord_param, dx_param, dy_param; DWORD sample_flags = WINED3D_GLSL_SAMPLE_GRAD; + struct glsl_sample_function sample_function; DWORD sampler_idx; DWORD swizzle = ins->src[1].swizzle; const struct wined3d_texture *texture; @@ -3159,12 +3152,12 @@ static void shader_glsl_texldd(const struct wined3d_shader_instruction *ins) static void shader_glsl_texldl(const struct wined3d_shader_instruction *ins) { - struct wined3d_shader *shader = ins->ctx->shader; + const struct wined3d_shader *shader = ins->ctx->shader; struct wined3d_device *device = shader->device; const struct wined3d_gl_info *gl_info = ins->ctx->gl_info; - glsl_sample_function_t sample_function; - glsl_src_param_t coord_param, lod_param; + struct glsl_src_param coord_param, lod_param; DWORD sample_flags = WINED3D_GLSL_SAMPLE_LOD; + struct glsl_sample_function sample_function; DWORD sampler_idx; DWORD swizzle = ins->src[1].swizzle; const struct wined3d_texture *texture; @@ -3182,8 +3175,9 @@ static void shader_glsl_texldl(const struct wined3d_shader_instruction *ins) if (!gl_info->supported[ARB_SHADER_TEXTURE_LOD] && !gl_info->supported[EXT_GPU_SHADER4] && shader_is_pshader_version(ins->ctx->reg_maps->shader_version.type)) { - /* The GLSL spec claims the Lod sampling functions are only supported in vertex shaders. - * However, they seem to work just fine in fragment shaders as well. */ + /* Plain GLSL only supports Lod sampling functions in vertex shaders. + * However, the NVIDIA drivers allow them in fragment shaders as well, + * even without the appropriate extension. */ WARN("Using %s in fragment shader.\n", sample_function.name); } shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, NULL, NULL, lod_param.param_str, @@ -3203,16 +3197,20 @@ static void shader_glsl_texcoord(const struct wined3d_shader_instruction *ins) shader_glsl_get_write_mask(&ins->dst[0], dst_mask); shader_addline(buffer, "clamp(gl_TexCoord[%u], 0.0, 1.0)%s);\n", ins->dst[0].reg.idx, dst_mask); - } else { + } + else + { + enum wined3d_shader_src_modifier src_mod = ins->src[0].modifiers; DWORD reg = ins->src[0].reg.idx; - DWORD src_mod = ins->src[0].modifiers; char dst_swizzle[6]; shader_glsl_get_swizzle(&ins->src[0], FALSE, write_mask, dst_swizzle); - if (src_mod == WINED3DSPSM_DZ) { - glsl_src_param_t div_param; + if (src_mod == WINED3DSPSM_DZ) + { unsigned int mask_size = shader_glsl_get_write_mask_size(write_mask); + struct glsl_src_param div_param; + shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_2, &div_param); if (mask_size > 1) { @@ -3220,9 +3218,12 @@ static void shader_glsl_texcoord(const struct wined3d_shader_instruction *ins) } else { shader_addline(buffer, "gl_TexCoord[%u]%s / %s);\n", reg, dst_swizzle, div_param.param_str); } - } else if (src_mod == WINED3DSPSM_DW) { - glsl_src_param_t div_param; + } + else if (src_mod == WINED3DSPSM_DW) + { unsigned int mask_size = shader_glsl_get_write_mask_size(write_mask); + struct glsl_src_param div_param; + shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_3, &div_param); if (mask_size > 1) { @@ -3241,10 +3242,10 @@ static void shader_glsl_texcoord(const struct wined3d_shader_instruction *ins) * then perform a 1D texture lookup from stage dstregnum, place into dst. */ static void shader_glsl_texdp3tex(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param; - glsl_sample_function_t sample_function; DWORD sampler_idx = ins->dst[0].reg.idx; DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; + struct glsl_sample_function sample_function; + struct glsl_src_param src0_param; UINT mask_size; shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param); @@ -3284,9 +3285,9 @@ static void shader_glsl_texdp3tex(const struct wined3d_shader_instruction *ins) * Take a 3-component dot product of the TexCoord[dstreg] and src. */ static void shader_glsl_texdp3(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param; DWORD dstreg = ins->dst[0].reg.idx; DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; + struct glsl_src_param src0_param; DWORD dst_mask; unsigned int mask_size; @@ -3305,7 +3306,7 @@ static void shader_glsl_texdp3(const struct wined3d_shader_instruction *ins) * Calculate the depth as dst.x / dst.y */ static void shader_glsl_texdepth(const struct wined3d_shader_instruction *ins) { - glsl_dst_param_t dst_param; + struct glsl_dst_param dst_param; shader_glsl_add_dst_param(ins, &ins->dst[0], &dst_param); @@ -3328,7 +3329,7 @@ static void shader_glsl_texm3x2depth(const struct wined3d_shader_instruction *in { DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; DWORD dstreg = ins->dst[0].reg.idx; - glsl_src_param_t src0_param; + struct glsl_src_param src0_param; shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param); @@ -3343,7 +3344,7 @@ static void shader_glsl_texm3x2pad(const struct wined3d_shader_instruction *ins) DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; DWORD reg = ins->dst[0].reg.idx; struct wined3d_shader_buffer *buffer = ins->ctx->buffer; - glsl_src_param_t src0_param; + struct glsl_src_param src0_param; shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param); shader_addline(buffer, "tmp0.x = dot(T%u.xyz, %s);\n", reg, src0_param.param_str); @@ -3357,7 +3358,7 @@ static void shader_glsl_texm3x3pad(const struct wined3d_shader_instruction *ins) DWORD reg = ins->dst[0].reg.idx; struct wined3d_shader_buffer *buffer = ins->ctx->buffer; struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx; - glsl_src_param_t src0_param; + struct glsl_src_param src0_param; shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param); shader_addline(buffer, "tmp0.%c = dot(T%u.xyz, %s);\n", 'x' + tex_mx->current_row, reg, src0_param.param_str); @@ -3369,8 +3370,8 @@ static void shader_glsl_texm3x2tex(const struct wined3d_shader_instruction *ins) DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; DWORD reg = ins->dst[0].reg.idx; struct wined3d_shader_buffer *buffer = ins->ctx->buffer; - glsl_src_param_t src0_param; - glsl_sample_function_t sample_function; + struct glsl_sample_function sample_function; + struct glsl_src_param src0_param; shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param); shader_addline(buffer, "tmp0.y = dot(T%u.xyz, %s);\n", reg, src0_param.param_str); @@ -3387,9 +3388,9 @@ static void shader_glsl_texm3x3tex(const struct wined3d_shader_instruction *ins) { DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx; - glsl_src_param_t src0_param; + struct glsl_sample_function sample_function; + struct glsl_src_param src0_param; DWORD reg = ins->dst[0].reg.idx; - glsl_sample_function_t sample_function; shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param); shader_addline(ins->ctx->buffer, "tmp0.z = dot(T%u.xyz, %s);\n", reg, src0_param.param_str); @@ -3409,7 +3410,7 @@ static void shader_glsl_texm3x3(const struct wined3d_shader_instruction *ins) { DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx; - glsl_src_param_t src0_param; + struct glsl_src_param src0_param; char dst_mask[6]; DWORD reg = ins->dst[0].reg.idx; @@ -3426,13 +3427,14 @@ static void shader_glsl_texm3x3(const struct wined3d_shader_instruction *ins) * Perform the final texture lookup based on the previous 2 3x3 matrix multiplies */ static void shader_glsl_texm3x3spec(const struct wined3d_shader_instruction *ins) { + struct glsl_src_param src0_param; + struct glsl_src_param src1_param; DWORD reg = ins->dst[0].reg.idx; - glsl_src_param_t src0_param; - glsl_src_param_t src1_param; struct wined3d_shader_buffer *buffer = ins->ctx->buffer; struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx; DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; - glsl_sample_function_t sample_function; + struct glsl_sample_function sample_function; + char coord_mask[6]; shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param); shader_glsl_add_src_param(ins, &ins->src[1], src_mask, &src1_param); @@ -3444,9 +3446,11 @@ static void shader_glsl_texm3x3spec(const struct wined3d_shader_instruction *ins /* Dependent read, not valid with conditional NP2 */ shader_glsl_get_sample_function(ins->ctx, reg, 0, &sample_function); + shader_glsl_write_mask_to_str(sample_function.coord_mask, coord_mask); /* Sample the texture */ - shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, "tmp0.xyz"); + shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, + NULL, NULL, NULL, "tmp0%s", coord_mask); tex_mx->current_row = 0; } @@ -3458,9 +3462,10 @@ static void shader_glsl_texm3x3vspec(const struct wined3d_shader_instruction *in DWORD reg = ins->dst[0].reg.idx; struct wined3d_shader_buffer *buffer = ins->ctx->buffer; struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx; - glsl_src_param_t src0_param; DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; - glsl_sample_function_t sample_function; + struct glsl_sample_function sample_function; + struct glsl_src_param src0_param; + char coord_mask[6]; shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param); @@ -3474,9 +3479,11 @@ static void shader_glsl_texm3x3vspec(const struct wined3d_shader_instruction *in /* Dependent read, not valid with conditional NP2 */ shader_glsl_get_sample_function(ins->ctx, reg, 0, &sample_function); + shader_glsl_write_mask_to_str(sample_function.coord_mask, coord_mask); /* Sample the texture using the calculated coordinates */ - shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, "tmp0.xyz"); + shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, + NULL, NULL, NULL, "tmp0%s", coord_mask); tex_mx->current_row = 0; } @@ -3488,8 +3495,8 @@ static void shader_glsl_texm3x3vspec(const struct wined3d_shader_instruction *in static void shader_glsl_texbem(const struct wined3d_shader_instruction *ins) { const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data; - glsl_sample_function_t sample_function; - glsl_src_param_t coord_param; + struct glsl_sample_function sample_function; + struct glsl_src_param coord_param; DWORD sampler_idx; DWORD mask; DWORD flags; @@ -3505,18 +3512,27 @@ static void shader_glsl_texbem(const struct wined3d_shader_instruction *ins) shader_glsl_write_mask_to_str(mask, coord_mask); - /* with projective textures, texbem only divides the static texture coord, not the displacement, - * so we can't let the GL handle this. - */ - if (flags & WINED3D_PSARGS_PROJECTED) { + /* With projected textures, texbem only divides the static texture coord, + * not the displacement, so we can't let GL handle this. */ + if (flags & WINED3D_PSARGS_PROJECTED) + { DWORD div_mask=0; char coord_div_mask[3]; - switch (flags & ~WINED3D_PSARGS_PROJECTED) { - case WINED3DTTFF_COUNT1: FIXME("WINED3DTTFF_PROJECTED with WINED3DTTFF_COUNT1?\n"); break; - case WINED3DTTFF_COUNT2: div_mask = WINED3DSP_WRITEMASK_1; break; - case WINED3DTTFF_COUNT3: div_mask = WINED3DSP_WRITEMASK_2; break; - case WINED3DTTFF_COUNT4: - case WINED3DTTFF_DISABLE: div_mask = WINED3DSP_WRITEMASK_3; break; + switch (flags & ~WINED3D_PSARGS_PROJECTED) + { + case WINED3D_TTFF_COUNT1: + FIXME("WINED3D_TTFF_PROJECTED with WINED3D_TTFF_COUNT1?\n"); + break; + case WINED3D_TTFF_COUNT2: + div_mask = WINED3DSP_WRITEMASK_1; + break; + case WINED3D_TTFF_COUNT3: + div_mask = WINED3DSP_WRITEMASK_2; + break; + case WINED3D_TTFF_COUNT4: + case WINED3D_TTFF_DISABLE: + div_mask = WINED3DSP_WRITEMASK_3; + break; } shader_glsl_write_mask_to_str(div_mask, coord_div_mask); shader_addline(ins->ctx->buffer, "T%u%s /= T%u%s;\n", sampler_idx, coord_mask, sampler_idx, coord_div_mask); @@ -3530,8 +3546,8 @@ static void shader_glsl_texbem(const struct wined3d_shader_instruction *ins) if (ins->handler_idx == WINED3DSIH_TEXBEML) { - glsl_src_param_t luminance_param; - glsl_dst_param_t dst_param; + struct glsl_src_param luminance_param; + struct glsl_dst_param dst_param; shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_2, &luminance_param); shader_glsl_add_dst_param(ins, &ins->dst[0], &dst_param); @@ -3544,7 +3560,7 @@ static void shader_glsl_texbem(const struct wined3d_shader_instruction *ins) static void shader_glsl_bem(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param, src1_param; + struct glsl_src_param src0_param, src1_param; DWORD sampler_idx = ins->dst[0].reg.idx; shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src0_param); @@ -3559,9 +3575,9 @@ static void shader_glsl_bem(const struct wined3d_shader_instruction *ins) * Sample 2D texture at dst using the alpha & red (wx) components of src as texture coordinates */ static void shader_glsl_texreg2ar(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param; + struct glsl_sample_function sample_function; + struct glsl_src_param src0_param; DWORD sampler_idx = ins->dst[0].reg.idx; - glsl_sample_function_t sample_function; shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_ALL, &src0_param); @@ -3574,9 +3590,9 @@ static void shader_glsl_texreg2ar(const struct wined3d_shader_instruction *ins) * Sample 2D texture at dst using the green & blue (yz) components of src as texture coordinates */ static void shader_glsl_texreg2gb(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param; + struct glsl_sample_function sample_function; + struct glsl_src_param src0_param; DWORD sampler_idx = ins->dst[0].reg.idx; - glsl_sample_function_t sample_function; shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_ALL, &src0_param); @@ -3589,9 +3605,9 @@ static void shader_glsl_texreg2gb(const struct wined3d_shader_instruction *ins) * Sample texture at dst using the rgb (xyz) components of src as texture coordinates */ static void shader_glsl_texreg2rgb(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param; + struct glsl_sample_function sample_function; + struct glsl_src_param src0_param; DWORD sampler_idx = ins->dst[0].reg.idx; - glsl_sample_function_t sample_function; /* Dependent read, not valid with conditional NP2 */ shader_glsl_get_sample_function(ins->ctx, sampler_idx, 0, &sample_function); @@ -3605,7 +3621,7 @@ static void shader_glsl_texreg2rgb(const struct wined3d_shader_instruction *ins) * If any of the first 3 components are < 0, discard this pixel */ static void shader_glsl_texkill(const struct wined3d_shader_instruction *ins) { - glsl_dst_param_t dst_param; + struct glsl_dst_param dst_param; /* The argument is a destination parameter, and no writemasks are allowed */ shader_glsl_add_dst_param(ins, &ins->dst[0], &dst_param); @@ -3626,9 +3642,9 @@ static void shader_glsl_texkill(const struct wined3d_shader_instruction *ins) * dst = dot2(src0, src1) + src2 */ static void shader_glsl_dp2add(const struct wined3d_shader_instruction *ins) { - glsl_src_param_t src0_param; - glsl_src_param_t src1_param; - glsl_src_param_t src2_param; + struct glsl_src_param src0_param; + struct glsl_src_param src1_param; + struct glsl_src_param src2_param; DWORD write_mask; unsigned int mask_size; @@ -3717,9 +3733,9 @@ static void add_glsl_program_entry(struct shader_glsl_priv *priv, struct glsl_sh } } -static struct glsl_shader_prog_link *get_glsl_program_entry(struct shader_glsl_priv *priv, +static struct glsl_shader_prog_link *get_glsl_program_entry(const struct shader_glsl_priv *priv, const struct wined3d_shader *vshader, const struct wined3d_shader *pshader, - struct vs_compile_args *vs_args, struct ps_compile_args *ps_args) + const struct vs_compile_args *vs_args, const struct ps_compile_args *ps_args) { struct wine_rb_entry *entry; struct glsl_program_key key; @@ -3918,8 +3934,9 @@ static GLhandleARB generate_param_reorder_function(struct wined3d_shader_buffer } else { + UINT in_count = min(vec4_varyings(ps_major, gl_info), ps->limits.packed_input); /* This one is tricky: a 3.0 pixel shader reads from a 3.0 vertex shader */ - shader_addline(buffer, "varying vec4 IN[%u];\n", vec4_varyings(3, gl_info)); + shader_addline(buffer, "varying vec4 IN[%u];\n", in_count); shader_addline(buffer, "void order_ps_input(in vec4 OUT[%u]) {\n", MAX_REG_OUTPUT); /* First, sort out position and point size. Those are not passed to the pixel shader */ @@ -3959,12 +3976,12 @@ static GLhandleARB generate_param_reorder_function(struct wined3d_shader_buffer static void hardcode_local_constants(const struct wined3d_shader *shader, const struct wined3d_gl_info *gl_info, GLhandleARB programId, char prefix) { - const local_constant *lconst; + const struct wined3d_shader_lconst *lconst; GLint tmp_loc; const float *value; char glsl_name[8]; - LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, local_constant, entry) + LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry) { value = (const float *)lconst->value; snprintf(glsl_name, sizeof(glsl_name), "%cLC%u", prefix, lconst->idx); @@ -3976,7 +3993,7 @@ static void hardcode_local_constants(const struct wined3d_shader *shader, /* GL locking is done by the caller */ static GLuint shader_glsl_generate_pshader(const struct wined3d_context *context, - struct wined3d_shader_buffer *buffer, struct wined3d_shader *shader, + struct wined3d_shader_buffer *buffer, const struct wined3d_shader *shader, const struct ps_compile_args *args, struct ps_np2fixup_info *np2fixup_info) { const struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps; @@ -3993,7 +4010,7 @@ static GLuint shader_glsl_generate_pshader(const struct wined3d_context *context shader_addline(buffer, "#version 120\n"); - if (gl_info->supported[ARB_SHADER_TEXTURE_LOD] && reg_maps->usestexldd) + if (gl_info->supported[ARB_SHADER_TEXTURE_LOD]) { shader_addline(buffer, "#extension GL_ARB_shader_texture_lod : enable\n"); } @@ -4077,7 +4094,7 @@ static GLuint shader_glsl_generate_pshader(const struct wined3d_context *context /* GL locking is done by the caller */ static GLuint shader_glsl_generate_vshader(const struct wined3d_context *context, - struct wined3d_shader_buffer *buffer, struct wined3d_shader *shader, + struct wined3d_shader_buffer *buffer, const struct wined3d_shader *shader, const struct vs_compile_args *args) { const struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps; @@ -4918,41 +4935,27 @@ static void shader_glsl_free(struct wined3d_device *device) device->shader_priv = NULL; } -static BOOL shader_glsl_dirty_const(void) -{ - /* TODO: GL_EXT_bindable_uniform can be used to share constants across shaders */ - return FALSE; -} +static void shader_glsl_context_destroyed(void *shader_priv, const struct wined3d_context *context) {} static void shader_glsl_get_caps(const struct wined3d_gl_info *gl_info, struct shader_caps *caps) { - /* NVIDIA GeForce 6 / 7 or ATI R4xx / R5xx cards with GLSL support - * support SM3, but older NVIDIA / ATI models with GLSL support only - * support SM2. In case of NVIDIA we can detect SM3 support based on the - * version of NV_vertex_program / NV_fragment_program. For other cards we - * try to detect SM3 based on the maximum number of native fragment - * program instructions. PS2.0 requires at least 96 instructions, 2.0a/b - * goes up to 512. Assume that if the number of instructions is 512 or - * less we have to do with SM2 hardware. NOTE: SM3 requires 512 or more - * instructions but ATI and NVIDIA offer more than that (1024 vs 4096) on - * their most basic SM3 hardware. - * - * ARB_shader_texture_lod is a requirement for SM3 (texldd). Ideally we'd - * make this a hard requirement, but the extension is still somewhat new, - * and relatively few SM3 shaders actually depend on it. For the moment - * just use it to enable SM3 (20110423). */ - if ((gl_info->supported[NV_VERTEX_PROGRAM3] && gl_info->supported[NV_FRAGMENT_PROGRAM2]) - || gl_info->limits.arb_ps_instructions > 512 - || gl_info->supported[ARB_SHADER_TEXTURE_LOD] - || gl_info->supported[EXT_GPU_SHADER4]) + if (gl_info->supported[EXT_GPU_SHADER4] && gl_info->supported[ARB_GEOMETRY_SHADER4] + && gl_info->glsl_version >= MAKEDWORD_VERSION(1, 50)) { - caps->VertexShaderVersion = WINED3DVS_VERSION(3,0); - caps->PixelShaderVersion = WINED3DPS_VERSION(3,0); + caps->VertexShaderVersion = 4; + caps->PixelShaderVersion = 4; + } + /* ARB_shader_texture_lod or EXT_gpu_shader4 is required for the SM3 + * texldd and texldl instructions. */ + else if (gl_info->supported[ARB_SHADER_TEXTURE_LOD] || gl_info->supported[EXT_GPU_SHADER4]) + { + caps->VertexShaderVersion = 3; + caps->PixelShaderVersion = 3; } else { - caps->VertexShaderVersion = WINED3DVS_VERSION(2,0); - caps->PixelShaderVersion = WINED3DPS_VERSION(2,0); + caps->VertexShaderVersion = 2; + caps->PixelShaderVersion = 2; } caps->MaxVertexShaderConst = gl_info->limits.glsl_vs_float_constants; @@ -4974,10 +4977,10 @@ static void shader_glsl_get_caps(const struct wined3d_gl_info *gl_info, struct s caps->VSClipping = TRUE; - TRACE_(d3d_caps)("Hardware vertex shader version %u.%u enabled (GLSL).\n", - (caps->VertexShaderVersion >> 8) & 0xff, caps->VertexShaderVersion & 0xff); - TRACE_(d3d_caps)("Hardware pixel shader version %u.%u enabled (GLSL).\n", - (caps->PixelShaderVersion >> 8) & 0xff, caps->PixelShaderVersion & 0xff); + TRACE_(d3d_caps)("Hardware vertex shader version %u enabled (GLSL).\n", + caps->VertexShaderVersion); + TRACE_(d3d_caps)("Hardware pixel shader version %u enabled (GLSL).\n", + caps->PixelShaderVersion); } static BOOL shader_glsl_color_fixup_supported(struct color_fixup_desc fixup) @@ -5030,10 +5033,12 @@ static const SHADER_HANDLER shader_glsl_instruction_handler_table[WINED3DSIH_TAB /* WINED3DSIH_ENDIF */ shader_glsl_end, /* WINED3DSIH_ENDLOOP */ shader_glsl_end, /* WINED3DSIH_ENDREP */ shader_glsl_end, + /* WINED3DSIH_EQ */ NULL, /* WINED3DSIH_EXP */ shader_glsl_map2gl, /* WINED3DSIH_EXPP */ shader_glsl_expp, /* WINED3DSIH_FRC */ shader_glsl_map2gl, /* WINED3DSIH_FTOI */ NULL, + /* WINED3DSIH_GE */ NULL, /* WINED3DSIH_IADD */ NULL, /* WINED3DSIH_IEQ */ NULL, /* WINED3DSIH_IF */ shader_glsl_if, @@ -5068,6 +5073,7 @@ static const SHADER_HANDLER shader_glsl_instruction_handler_table[WINED3DSIH_TAB /* WINED3DSIH_RCP */ shader_glsl_rcp, /* WINED3DSIH_REP */ shader_glsl_rep, /* WINED3DSIH_RET */ shader_glsl_ret, + /* WINED3DSIH_ROUND_NI */ NULL, /* WINED3DSIH_RSQ */ shader_glsl_rsq, /* WINED3DSIH_SAMPLE */ NULL, /* WINED3DSIH_SAMPLE_GRAD */ NULL, @@ -5101,7 +5107,10 @@ static const SHADER_HANDLER shader_glsl_instruction_handler_table[WINED3DSIH_TAB /* WINED3DSIH_TEXREG2AR */ shader_glsl_texreg2ar, /* WINED3DSIH_TEXREG2GB */ shader_glsl_texreg2gb, /* WINED3DSIH_TEXREG2RGB */ shader_glsl_texreg2rgb, + /* WINED3DSIH_UDIV */ NULL, + /* WINED3DSIH_USHR */ NULL, /* WINED3DSIH_UTOF */ NULL, + /* WINED3DSIH_XOR */ NULL, }; static void shader_glsl_handle_instruction(const struct wined3d_shader_instruction *ins) { @@ -5134,7 +5143,7 @@ const struct wined3d_shader_backend_ops glsl_shader_backend = shader_glsl_destroy, shader_glsl_alloc, shader_glsl_free, - shader_glsl_dirty_const, + shader_glsl_context_destroyed, shader_glsl_get_caps, shader_glsl_color_fixup_supported, }; diff --git a/reactos/dll/directx/wine/wined3d/nvidia_texture_shader.c b/reactos/dll/directx/wine/wined3d/nvidia_texture_shader.c index f20fc7ac6a7..dc3f8b9afa9 100644 --- a/reactos/dll/directx/wine/wined3d/nvidia_texture_shader.c +++ b/reactos/dll/directx/wine/wined3d/nvidia_texture_shader.c @@ -34,8 +34,9 @@ static void nvts_activate_dimensions(const struct wined3d_state *state, DWORD st { BOOL bumpmap = FALSE; - if (stage > 0 && (state->texture_states[stage - 1][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAPLUMINANCE - || state->texture_states[stage - 1][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAP)) + if (stage > 0 + && (state->texture_states[stage - 1][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_BUMPENVMAP_LUMINANCE + || state->texture_states[stage - 1][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_BUMPENVMAP)) { bumpmap = TRUE; context->texShaderBumpMap |= (1 << stage); @@ -70,11 +71,12 @@ static void nvts_activate_dimensions(const struct wined3d_state *state, DWORD st } } -typedef struct { +struct tex_op_args +{ GLenum input[3]; GLenum mapping[3]; GLenum component_usage[3]; -} tex_op_args; +}; static GLenum d3dta_to_combiner_input(DWORD d3dta, DWORD stage, INT texture_idx) { switch (d3dta) { @@ -99,7 +101,7 @@ static GLenum d3dta_to_combiner_input(DWORD d3dta, DWORD stage, INT texture_idx) return GL_SPARE1_NV; case WINED3DTA_CONSTANT: - /* TODO: Support per stage constants (WINED3DTSS_CONSTANT, NV_register_combiners2) */ + /* TODO: Support per stage constants (WINED3D_TSS_CONSTANT, NV_register_combiners2) */ FIXME("WINED3DTA_CONSTANT, not properly supported.\n"); return GL_CONSTANT_COLOR1_NV; @@ -132,9 +134,9 @@ static void get_src_and_opr_nvrc(DWORD stage, DWORD arg, BOOL is_alpha, GLenum* } void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state, BOOL is_alpha, - int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx, DWORD dst) + int stage, enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx, DWORD dst) { - tex_op_args tex_op_args = {{0}, {0}, {0}}; + struct tex_op_args tex_op_args = {{0}, {0}, {0}}; GLenum portion = is_alpha ? GL_ALPHA : GL_RGB; GLenum target = GL_COMBINER0_NV + stage; GLenum output; @@ -147,7 +149,7 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d if (is_invalid_op(state, stage, op, arg1, arg2, arg3)) { arg1 = WINED3DTA_CURRENT; - op = WINED3DTOP_SELECTARG1; + op = WINED3D_TOP_SELECT_ARG1; } get_src_and_opr_nvrc(stage, arg1, is_alpha, &tex_op_args.input[0], @@ -165,11 +167,12 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d } /* This is called by a state handler which has the gl lock held and a context for the thread */ - switch(op) + switch (op) { - case WINED3DTOP_DISABLE: + case WINED3D_TOP_DISABLE: /* Only for alpha */ - if (!is_alpha) ERR("Shouldn't be called for WINED3DTSS_COLOROP (WINED3DTOP_DISABLE)\n"); + if (!is_alpha) + ERR("Shouldn't be called for WINED3D_TSS_COLOR_OP (WINED3DTOP_DISABLE).\n"); /* Input, prev_alpha*1 */ GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA)); @@ -181,16 +184,15 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE)); break; - case WINED3DTOP_SELECTARG1: - case WINED3DTOP_SELECTARG2: + case WINED3D_TOP_SELECT_ARG1: + case WINED3D_TOP_SELECT_ARG2: /* Input, arg*1 */ - if (op == WINED3DTOP_SELECTARG1) { + if (op == WINED3D_TOP_SELECT_ARG1) GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV, tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0])); - } else { + else GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV, tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1])); - } GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV, GL_ZERO, GL_UNSIGNED_INVERT_NV, portion)); @@ -199,9 +201,9 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE)); break; - case WINED3DTOP_MODULATE: - case WINED3DTOP_MODULATE2X: - case WINED3DTOP_MODULATE4X: + case WINED3D_TOP_MODULATE: + case WINED3D_TOP_MODULATE_2X: + case WINED3D_TOP_MODULATE_4X: /* Input, arg1*arg2 */ GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV, tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0])); @@ -209,21 +211,20 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1])); /* Output */ - if (op == WINED3DTOP_MODULATE) { + if (op == WINED3D_TOP_MODULATE) GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE)); - } else if (op == WINED3DTOP_MODULATE2X) { + else if (op == WINED3D_TOP_MODULATE_2X) GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV, GL_DISCARD_NV, GL_SCALE_BY_TWO_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE)); - } else if (op == WINED3DTOP_MODULATE4X) { + else if (op == WINED3D_TOP_MODULATE_4X) GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV, GL_DISCARD_NV, GL_SCALE_BY_FOUR_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE)); - } break; - case WINED3DTOP_ADD: - case WINED3DTOP_ADDSIGNED: - case WINED3DTOP_ADDSIGNED2X: + case WINED3D_TOP_ADD: + case WINED3D_TOP_ADD_SIGNED: + case WINED3D_TOP_ADD_SIGNED_2X: /* Input, arg1*1+arg2*1 */ GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV, tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0])); @@ -235,19 +236,18 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d GL_ZERO, GL_UNSIGNED_INVERT_NV, portion)); /* Output */ - if (op == WINED3DTOP_ADD) { + if (op == WINED3D_TOP_ADD) GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV, output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE)); - } else if (op == WINED3DTOP_ADDSIGNED) { + else if (op == WINED3D_TOP_ADD_SIGNED) GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV, output, GL_NONE, GL_BIAS_BY_NEGATIVE_ONE_HALF_NV, GL_FALSE, GL_FALSE, GL_FALSE)); - } else if (op == WINED3DTOP_ADDSIGNED2X) { + else if (op == WINED3D_TOP_ADD_SIGNED_2X) GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV, output, GL_SCALE_BY_TWO_NV, GL_BIAS_BY_NEGATIVE_ONE_HALF_NV, GL_FALSE, GL_FALSE, GL_FALSE)); - } break; - case WINED3DTOP_SUBTRACT: + case WINED3D_TOP_SUBTRACT: /* Input, arg1*1+-arg2*1 */ GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV, tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0])); @@ -263,7 +263,7 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE)); break; - case WINED3DTOP_ADDSMOOTH: + case WINED3D_TOP_ADD_SMOOTH: /* Input, arg1*1+(1-arg1)*arg2 */ GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV, tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0])); @@ -279,24 +279,30 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE)); break; - case WINED3DTOP_BLENDDIFFUSEALPHA: - case WINED3DTOP_BLENDTEXTUREALPHA: - case WINED3DTOP_BLENDFACTORALPHA: - case WINED3DTOP_BLENDTEXTUREALPHAPM: - case WINED3DTOP_BLENDCURRENTALPHA: + case WINED3D_TOP_BLEND_DIFFUSE_ALPHA: + case WINED3D_TOP_BLEND_TEXTURE_ALPHA: + case WINED3D_TOP_BLEND_FACTOR_ALPHA: + case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM: + case WINED3D_TOP_BLEND_CURRENT_ALPHA: { GLenum alpha_src = GL_PRIMARY_COLOR_NV; - if (op == WINED3DTOP_BLENDDIFFUSEALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_DIFFUSE, stage, texture_idx); - else if (op == WINED3DTOP_BLENDTEXTUREALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx); - else if (op == WINED3DTOP_BLENDFACTORALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_TFACTOR, stage, texture_idx); - else if (op == WINED3DTOP_BLENDTEXTUREALPHAPM) alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx); - else if (op == WINED3DTOP_BLENDCURRENTALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_CURRENT, stage, texture_idx); - else FIXME("Unhandled WINED3DTOP %s, shouldn't happen\n", debug_d3dtop(op)); + if (op == WINED3D_TOP_BLEND_DIFFUSE_ALPHA) + alpha_src = d3dta_to_combiner_input(WINED3DTA_DIFFUSE, stage, texture_idx); + else if (op == WINED3D_TOP_BLEND_TEXTURE_ALPHA) + alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx); + else if (op == WINED3D_TOP_BLEND_FACTOR_ALPHA) + alpha_src = d3dta_to_combiner_input(WINED3DTA_TFACTOR, stage, texture_idx); + else if (op == WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM) + alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx); + else if (op == WINED3D_TOP_BLEND_CURRENT_ALPHA) + alpha_src = d3dta_to_combiner_input(WINED3DTA_CURRENT, stage, texture_idx); + else + FIXME("Unhandled texture op %s, shouldn't happen.\n", debug_d3dtop(op)); /* Input, arg1*alpha_src+arg2*(1-alpha_src) */ GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV, tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0])); - if (op == WINED3DTOP_BLENDTEXTUREALPHAPM) + if (op == WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM) { GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV, GL_ZERO, GL_UNSIGNED_INVERT_NV, portion)); @@ -315,9 +321,10 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d break; } - case WINED3DTOP_MODULATEALPHA_ADDCOLOR: + case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR: /* Input, arg1_alpha*arg2_rgb+arg1_rgb*1 */ - if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATEALPHA_ADDCOLOR)\n"); + if (is_alpha) + ERR("Only supported for WINED3D_TSS_COLOR_OP (WINED3DTOP_MODULATEALPHA_ADDCOLOR).\n"); GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV, tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA)); GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV, @@ -332,9 +339,10 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE)); break; - case WINED3DTOP_MODULATECOLOR_ADDALPHA: + case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA: /* Input, arg1_rgb*arg2_rgb+arg1_alpha*1 */ - if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATECOLOR_ADDALPHA)\n"); + if (is_alpha) + ERR("Only supported for WINED3D_TSS_COLOR_OP (WINED3DTOP_MODULATECOLOR_ADDALPHA).\n"); GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV, tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0])); GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV, @@ -349,9 +357,10 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE)); break; - case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR: + case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR: /* Input, (1-arg1_alpha)*arg2_rgb+arg1_rgb*1 */ - if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATEINVALPHA_ADDCOLOR)\n"); + if (is_alpha) + ERR("Only supported for WINED3D_TSS_COLOR_OP (WINED3DTOP_MODULATEINVALPHA_ADDCOLOR).\n"); GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV, tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), GL_ALPHA)); GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV, @@ -366,9 +375,10 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE)); break; - case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA: + case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA: /* Input, (1-arg1_rgb)*arg2_rgb+arg1_alpha*1 */ - if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATEINVCOLOR_ADDALPHA)\n"); + if (is_alpha) + ERR("Only supported for WINED3D_TSS_COLOR_OP (WINED3DTOP_MODULATEINVCOLOR_ADDALPHA).\n"); GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV, tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), tex_op_args.component_usage[0])); GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV, @@ -383,7 +393,7 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE)); break; - case WINED3DTOP_DOTPRODUCT3: + case WINED3D_TOP_DOTPRODUCT3: /* Input, arg1 . arg2 */ /* FIXME: DX7 uses a different calculation? */ GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV, @@ -396,7 +406,7 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d GL_DISCARD_NV, GL_NONE, GL_NONE, GL_TRUE, GL_FALSE, GL_FALSE)); break; - case WINED3DTOP_MULTIPLYADD: + case WINED3D_TOP_MULTIPLY_ADD: /* Input, arg3*1+arg1*arg2 */ GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV, tex_op_args.input[2], tex_op_args.mapping[2], tex_op_args.component_usage[2])); @@ -412,7 +422,7 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE)); break; - case WINED3DTOP_LERP: + case WINED3D_TOP_LERP: /* Input, arg3*arg1+(1-arg3)*arg2 */ GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV, tex_op_args.input[2], tex_op_args.mapping[2], tex_op_args.component_usage[2])); @@ -428,8 +438,8 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE)); break; - case WINED3DTOP_BUMPENVMAPLUMINANCE: - case WINED3DTOP_BUMPENVMAP: + case WINED3D_TOP_BUMPENVMAP_LUMINANCE: + case WINED3D_TOP_BUMPENVMAP: if (gl_info->supported[NV_TEXTURE_SHADER]) { /* The bump map stage itself isn't exciting, just read the texture. But tell the next stage to @@ -448,7 +458,7 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d } default: - FIXME("Unhandled WINED3DTOP: stage %d, is_alpha %d, op %s (%#x), arg1 %#x, arg2 %#x, arg3 %#x, texture_idx %d\n", + FIXME("Unhandled texture op: stage %d, is_alpha %d, op %s (%#x), arg1 %#x, arg2 %#x, arg3 %#x, texture_idx %d.\n", stage, is_alpha, debug_d3dtop(op), op, arg1, arg2, arg3, texture_idx); } @@ -456,13 +466,13 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d } -static void nvrc_colorop(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void nvrc_colorop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); - BOOL tex_used = stateblock->device->fixed_function_usage_map & (1 << stage); - DWORD mapped_stage = stateblock->device->texUnitMap[stage]; + const struct wined3d_device *device = context->swapchain->device; + BOOL tex_used = device->fixed_function_usage_map & (1 << stage); + DWORD mapped_stage = device->texUnitMap[stage]; const struct wined3d_gl_info *gl_info = context->gl_info; - const struct wined3d_state *state = &stateblock->state; TRACE("Setting color op for stage %u.\n", stage); @@ -478,8 +488,7 @@ static void nvrc_colorop(DWORD state_id, struct wined3d_stateblock *stateblock, FIXME("Attempt to enable unsupported stage!\n"); return; } - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); - checkGLcall("glActiveTextureARB"); + context_active_texture(context, gl_info, mapped_stage); } if (state->lowest_disabled_stage > 0) @@ -540,53 +549,52 @@ static void nvrc_colorop(DWORD state_id, struct wined3d_stateblock *stateblock, /* Set the texture combiners */ set_tex_op_nvrc(gl_info, state, FALSE, stage, - state->texture_states[stage][WINED3DTSS_COLOROP], - state->texture_states[stage][WINED3DTSS_COLORARG1], - state->texture_states[stage][WINED3DTSS_COLORARG2], - state->texture_states[stage][WINED3DTSS_COLORARG0], + state->texture_states[stage][WINED3D_TSS_COLOR_OP], + state->texture_states[stage][WINED3D_TSS_COLOR_ARG1], + state->texture_states[stage][WINED3D_TSS_COLOR_ARG2], + state->texture_states[stage][WINED3D_TSS_COLOR_ARG0], mapped_stage, - state->texture_states[stage][WINED3DTSS_RESULTARG]); + state->texture_states[stage][WINED3D_TSS_RESULT_ARG]); /* In register combiners bump mapping is done in the stage AFTER the one that has the bump map operation set, * thus the texture shader may have to be updated */ if (gl_info->supported[NV_TEXTURE_SHADER2]) { - BOOL usesBump = (state->texture_states[stage][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAPLUMINANCE - || state->texture_states[stage][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAP); + BOOL usesBump = (state->texture_states[stage][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_BUMPENVMAP_LUMINANCE + || state->texture_states[stage][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_BUMPENVMAP); BOOL usedBump = !!(context->texShaderBumpMap & 1 << (stage + 1)); if (usesBump != usedBump) { - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage + 1)); - checkGLcall("glActiveTextureARB"); + context_active_texture(context, gl_info, mapped_stage + 1); nvts_activate_dimensions(state, stage + 1, context); - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); - checkGLcall("glActiveTextureARB"); + context_active_texture(context, gl_info, mapped_stage); } } } -static void nvts_texdim(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void nvts_texdim(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { DWORD sampler = state_id - STATE_SAMPLER(0); - DWORD mapped_stage = stateblock->device->texUnitMap[sampler]; - const struct wined3d_state *state = &stateblock->state; + DWORD mapped_stage = context->swapchain->device->texUnitMap[sampler]; /* No need to enable / disable anything here for unused samplers. The tex_colorop * handler takes care. Also no action is needed with pixel shaders, or if tex_colorop - * will take care of this business - */ - if (mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= context->gl_info->limits.textures) return; - if (sampler >= state->lowest_disabled_stage) return; - if (isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP))) return; + * will take care of this business. */ + if (mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= context->gl_info->limits.textures) + return; + if (sampler >= state->lowest_disabled_stage) + return; + if (isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3D_TSS_COLOR_OP))) + return; nvts_activate_dimensions(state, sampler, context); } -static void nvts_bumpenvmat(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void nvts_bumpenvmat(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); - DWORD mapped_stage = stateblock->device->texUnitMap[stage + 1]; + DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); + DWORD mapped_stage = context->swapchain->device->texUnitMap[stage + 1]; const struct wined3d_gl_info *gl_info = context->gl_info; float mat[2][2]; @@ -598,25 +606,25 @@ static void nvts_bumpenvmat(DWORD state, struct wined3d_stateblock *stateblock, */ if (mapped_stage < gl_info->limits.textures) { - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); - checkGLcall("GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage))"); + context_active_texture(context, gl_info, mapped_stage); - /* We can't just pass a pointer to the stateblock to GL due to the + /* We can't just pass a pointer to the state to GL due to the * different matrix format (column major vs row major). */ - mat[0][0] = *((float *)&stateblock->state.texture_states[stage][WINED3DTSS_BUMPENVMAT00]); - mat[1][0] = *((float *)&stateblock->state.texture_states[stage][WINED3DTSS_BUMPENVMAT01]); - mat[0][1] = *((float *)&stateblock->state.texture_states[stage][WINED3DTSS_BUMPENVMAT10]); - mat[1][1] = *((float *)&stateblock->state.texture_states[stage][WINED3DTSS_BUMPENVMAT11]); + mat[0][0] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT00]); + mat[1][0] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT01]); + mat[0][1] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT10]); + mat[1][1] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT11]); glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, (float *)mat); checkGLcall("glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, mat)"); } } -static void nvrc_texfactor(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void nvrc_texfactor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { const struct wined3d_gl_info *gl_info = context->gl_info; float col[4]; - D3DCOLORTOGLFLOAT4(stateblock->state.render_states[WINED3DRS_TEXTUREFACTOR], col); + + D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_TEXTUREFACTOR], col); GL_EXTCALL(glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, &col[0])); } @@ -719,121 +727,122 @@ static BOOL nvts_color_fixup_supported(struct color_fixup_desc fixup) return FALSE; } -static const struct StateEntryTemplate nvrc_fragmentstate_template[] = { - { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), NULL }, NV_TEXTURE_SHADER2 }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, +static const struct StateEntryTemplate nvrc_fragmentstate_template[] = +{ + { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, { STATE_PIXELSHADER, { STATE_PIXELSHADER, apply_pixelshader }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_SRGBWRITEENABLE), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_TEXTUREFACTOR), { STATE_RENDER(WINED3DRS_TEXTUREFACTOR), nvrc_texfactor }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FOGCOLOR), { STATE_RENDER(WINED3DRS_FOGCOLOR), state_fogcolor }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FOGDENSITY), { STATE_RENDER(WINED3DRS_FOGDENSITY), state_fogdensity }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FOGENABLE), { STATE_RENDER(WINED3DRS_FOGENABLE), state_fog_fragpart }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FOGTABLEMODE), { STATE_RENDER(WINED3DRS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FOGVERTEXMODE), { STATE_RENDER(WINED3DRS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FOGSTART), { STATE_RENDER(WINED3DRS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FOGEND), { STATE_RENDER(WINED3DRS_FOGSTART), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), nvrc_texfactor }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGCOLOR), { STATE_RENDER(WINED3D_RS_FOGCOLOR), state_fogcolor }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGDENSITY), { STATE_RENDER(WINED3D_RS_FOGDENSITY), state_fogdensity }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), state_fog_fragpart }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGTABLEMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGVERTEXMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGSTART), { STATE_RENDER(WINED3D_RS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGEND), { STATE_RENDER(WINED3D_RS_FOGSTART), NULL }, WINED3D_GL_EXT_NONE }, { STATE_SAMPLER(0), { STATE_SAMPLER(0), nvts_texdim }, NV_TEXTURE_SHADER2 }, { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler_texdim }, WINED3D_GL_EXT_NONE }, { STATE_SAMPLER(1), { STATE_SAMPLER(1), nvts_texdim }, NV_TEXTURE_SHADER2 }, diff --git a/reactos/dll/directx/wine/wined3d/palette.c b/reactos/dll/directx/wine/wined3d/palette.c index 1fcc6ba1c9a..780c6a9e1f6 100644 --- a/reactos/dll/directx/wine/wined3d/palette.c +++ b/reactos/dll/directx/wine/wined3d/palette.c @@ -133,7 +133,7 @@ HRESULT CDECL wined3d_palette_set_entries(struct wined3d_palette *palette, /* If the palette is attached to the render target, update all render targets */ LIST_FOR_EACH_ENTRY(resource, &palette->device->resources, struct wined3d_resource, resource_list_entry) { - if (resource->resourceType == WINED3DRTYPE_SURFACE) + if (resource->type == WINED3D_RTYPE_SURFACE) { struct wined3d_surface *surface = surface_from_resource(resource); if (surface->palette == palette) diff --git a/reactos/dll/directx/wine/wined3d/query.c b/reactos/dll/directx/wine/wined3d/query.c index ca4426f5cc7..8298058dd4f 100644 --- a/reactos/dll/directx/wine/wined3d/query.c +++ b/reactos/dll/directx/wine/wined3d/query.c @@ -1,6 +1,4 @@ /* - * IWineD3DQuery implementation - * * Copyright 2005 Oliver Stieber * Copyright 2007-2008 Stefan Dösinger for CodeWeavers * Copyright 2009-2010 Henri Verbeet for CodeWeavers. @@ -37,8 +35,8 @@ void wined3d_event_query_destroy(struct wined3d_event_query *query) HeapFree(GetProcessHeap(), 0, query); } -static enum wined3d_event_query_result wined3d_event_query_test(struct wined3d_event_query *query, - struct wined3d_device *device) +static enum wined3d_event_query_result wined3d_event_query_test(const struct wined3d_event_query *query, + const struct wined3d_device *device) { struct wined3d_context *context; const struct wined3d_gl_info *gl_info; @@ -112,8 +110,8 @@ static enum wined3d_event_query_result wined3d_event_query_test(struct wined3d_e return ret; } -enum wined3d_event_query_result wined3d_event_query_finish(struct wined3d_event_query *query, - struct wined3d_device *device) +enum wined3d_event_query_result wined3d_event_query_finish(const struct wined3d_event_query *query, + const struct wined3d_device *device) { struct wined3d_context *context; const struct wined3d_gl_info *gl_info; @@ -181,7 +179,7 @@ enum wined3d_event_query_result wined3d_event_query_finish(struct wined3d_event_ return ret; } -void wined3d_event_query_issue(struct wined3d_event_query *query, struct wined3d_device *device) +void wined3d_event_query_issue(struct wined3d_event_query *query, const struct wined3d_device *device) { const struct wined3d_gl_info *gl_info; struct wined3d_context *context; @@ -253,12 +251,12 @@ ULONG CDECL wined3d_query_decref(struct wined3d_query *query) * deleting the query will obviously leak it, but that's still better * than potentially deleting a different query with the same id in this * context, and (still) leaking the actual query. */ - if (query->type == WINED3DQUERYTYPE_EVENT) + if (query->type == WINED3D_QUERY_TYPE_EVENT) { struct wined3d_event_query *event_query = query->extendedData; if (event_query) wined3d_event_query_destroy(event_query); } - else if (query->type == WINED3DQUERYTYPE_OCCLUSION) + else if (query->type == WINED3D_QUERY_TYPE_OCCLUSION) { struct wined3d_occlusion_query *oq = query->extendedData; @@ -414,7 +412,7 @@ static HRESULT wined3d_event_query_ops_get_data(struct wined3d_query *query, return S_OK; } -WINED3DQUERYTYPE CDECL wined3d_query_get_type(const struct wined3d_query *query) +enum wined3d_query_type CDECL wined3d_query_get_type(const struct wined3d_query *query) { TRACE("query %p.\n", query); @@ -549,13 +547,13 @@ static const struct wined3d_query_ops occlusion_query_ops = wined3d_occlusion_query_ops_issue, }; -static HRESULT query_init(struct wined3d_query *query, struct wined3d_device *device, WINED3DQUERYTYPE type) +static HRESULT query_init(struct wined3d_query *query, struct wined3d_device *device, enum wined3d_query_type type) { const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; switch (type) { - case WINED3DQUERYTYPE_OCCLUSION: + case WINED3D_QUERY_TYPE_OCCLUSION: TRACE("Occlusion query.\n"); if (!gl_info->supported[ARB_OCCLUSION_QUERY]) { @@ -573,7 +571,7 @@ static HRESULT query_init(struct wined3d_query *query, struct wined3d_device *de ((struct wined3d_occlusion_query *)query->extendedData)->context = NULL; break; - case WINED3DQUERYTYPE_EVENT: + case WINED3D_QUERY_TYPE_EVENT: TRACE("Event query.\n"); if (!wined3d_event_query_supported(gl_info)) { @@ -593,18 +591,18 @@ static HRESULT query_init(struct wined3d_query *query, struct wined3d_device *de } break; - case WINED3DQUERYTYPE_VCACHE: - case WINED3DQUERYTYPE_RESOURCEMANAGER: - case WINED3DQUERYTYPE_VERTEXSTATS: - case WINED3DQUERYTYPE_TIMESTAMP: - case WINED3DQUERYTYPE_TIMESTAMPDISJOINT: - case WINED3DQUERYTYPE_TIMESTAMPFREQ: - case WINED3DQUERYTYPE_PIPELINETIMINGS: - case WINED3DQUERYTYPE_INTERFACETIMINGS: - case WINED3DQUERYTYPE_VERTEXTIMINGS: - case WINED3DQUERYTYPE_PIXELTIMINGS: - case WINED3DQUERYTYPE_BANDWIDTHTIMINGS: - case WINED3DQUERYTYPE_CACHEUTILIZATION: + case WINED3D_QUERY_TYPE_VCACHE: + case WINED3D_QUERY_TYPE_RESOURCE_MANAGER: + case WINED3D_QUERY_TYPE_VERTEX_STATS: + case WINED3D_QUERY_TYPE_TIMESTAMP: + case WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT: + case WINED3D_QUERY_TYPE_TIMESTAMP_FREQ: + case WINED3D_QUERY_TYPE_PIPELINE_TIMINGS: + case WINED3D_QUERY_TYPE_INTERFACE_TIMINGS: + case WINED3D_QUERY_TYPE_VERTEX_TIMINGS: + case WINED3D_QUERY_TYPE_PIXEL_TIMINGS: + case WINED3D_QUERY_TYPE_BANDWIDTH_TIMINGS: + case WINED3D_QUERY_TYPE_CACHE_UTILIZATION: default: FIXME("Unhandled query type %#x.\n", type); return WINED3DERR_NOTAVAILABLE; @@ -619,7 +617,7 @@ static HRESULT query_init(struct wined3d_query *query, struct wined3d_device *de } HRESULT CDECL wined3d_query_create(struct wined3d_device *device, - WINED3DQUERYTYPE type, struct wined3d_query **query) + enum wined3d_query_type type, struct wined3d_query **query) { struct wined3d_query *object; HRESULT hr; diff --git a/reactos/dll/directx/wine/wined3d/resource.c b/reactos/dll/directx/wine/wined3d/resource.c index 4060bc67861..da631d63ea3 100644 --- a/reactos/dll/directx/wine/wined3d/resource.c +++ b/reactos/dll/directx/wine/wined3d/resource.c @@ -1,6 +1,4 @@ /* - * IWineD3DResource Implementation - * * Copyright 2002-2004 Jason Edmeades * Copyright 2003-2004 Raphael Junqueira * Copyright 2004 Christian Costa @@ -43,20 +41,20 @@ struct private_data DWORD size; }; -static DWORD resource_access_from_pool(WINED3DPOOL pool) +static DWORD resource_access_from_pool(enum wined3d_pool pool) { switch (pool) { - case WINED3DPOOL_DEFAULT: + case WINED3D_POOL_DEFAULT: return WINED3D_RESOURCE_ACCESS_GPU; - case WINED3DPOOL_MANAGED: + case WINED3D_POOL_MANAGED: return WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_CPU; - case WINED3DPOOL_SYSTEMMEM: + case WINED3D_POOL_SYSTEM_MEM: return WINED3D_RESOURCE_ACCESS_CPU; - case WINED3DPOOL_SCRATCH: + case WINED3D_POOL_SCRATCH: return WINED3D_RESOURCE_ACCESS_SCRATCH; default: @@ -79,15 +77,15 @@ static void resource_check_usage(DWORD usage) } HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *device, - WINED3DRESOURCETYPE resource_type, const struct wined3d_format *format, - WINED3DMULTISAMPLE_TYPE multisample_type, UINT multisample_quality, - DWORD usage, WINED3DPOOL pool, UINT width, UINT height, UINT depth, UINT size, + enum wined3d_resource_type type, const struct wined3d_format *format, + enum wined3d_multisample_type multisample_type, UINT multisample_quality, + DWORD usage, enum wined3d_pool pool, UINT width, UINT height, UINT depth, UINT size, void *parent, const struct wined3d_parent_ops *parent_ops, const struct wined3d_resource_ops *resource_ops) { resource->ref = 1; resource->device = device; - resource->resourceType = resource_type; + resource->type = type; resource->format = format; resource->multisample_type = multisample_type; resource->multisample_quality = multisample_quality; @@ -125,7 +123,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device * + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1)); /* Check that we have enough video ram left */ - if (pool == WINED3DPOOL_DEFAULT) + if (pool == WINED3D_POOL_DEFAULT) { if (size > wined3d_device_get_available_texture_mem(device)) { @@ -133,7 +131,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device * HeapFree(GetProcessHeap(), 0, resource->heapMemory); return WINED3DERR_OUTOFVIDEOMEMORY; } - WineD3DAdapterChangeGLRam(device, size); + adapter_adjust_memory(device->adapter, size); } device_resource_add(device, resource); @@ -149,16 +147,16 @@ void resource_cleanup(struct wined3d_resource *resource) TRACE("Cleaning up resource %p.\n", resource); - if (resource->pool == WINED3DPOOL_DEFAULT) + if (resource->pool == WINED3D_POOL_DEFAULT) { TRACE("Decrementing device memory pool by %u.\n", resource->size); - WineD3DAdapterChangeGLRam(resource->device, 0 - resource->size); + adapter_adjust_memory(resource->device->adapter, 0 - resource->size); } LIST_FOR_EACH_SAFE(e1, e2, &resource->privateData) { data = LIST_ENTRY(e1, struct private_data, entry); - hr = resource_free_private_data(resource, &data->tag); + hr = wined3d_resource_free_private_data(resource, &data->tag); if (FAILED(hr)) ERR("Failed to free private data when destroying resource %p, hr = %#x.\n", resource, hr); } @@ -174,7 +172,7 @@ void resource_cleanup(struct wined3d_resource *resource) void resource_unload(struct wined3d_resource *resource) { context_resource_unloaded(resource->device, - resource, resource->resourceType); + resource, resource->type); } static struct private_data *resource_find_private_data(const struct wined3d_resource *resource, REFGUID tag) @@ -195,7 +193,7 @@ static struct private_data *resource_find_private_data(const struct wined3d_reso return NULL; } -HRESULT resource_set_private_data(struct wined3d_resource *resource, REFGUID guid, +HRESULT CDECL wined3d_resource_set_private_data(struct wined3d_resource *resource, REFGUID guid, const void *data, DWORD data_size, DWORD flags) { struct private_data *d; @@ -203,7 +201,7 @@ HRESULT resource_set_private_data(struct wined3d_resource *resource, REFGUID gui TRACE("resource %p, riid %s, data %p, data_size %u, flags %#x.\n", resource, debugstr_guid(guid), data, data_size, flags); - resource_free_private_data(resource, guid); + wined3d_resource_free_private_data(resource, guid); d = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*d)); if (!d) return E_OUTOFMEMORY; @@ -239,7 +237,8 @@ HRESULT resource_set_private_data(struct wined3d_resource *resource, REFGUID gui return WINED3D_OK; } -HRESULT resource_get_private_data(const struct wined3d_resource *resource, REFGUID guid, void *data, DWORD *data_size) +HRESULT CDECL wined3d_resource_get_private_data(const struct wined3d_resource *resource, REFGUID guid, + void *data, DWORD *data_size) { const struct private_data *d; @@ -273,7 +272,7 @@ HRESULT resource_get_private_data(const struct wined3d_resource *resource, REFGU return WINED3D_OK; } -HRESULT resource_free_private_data(struct wined3d_resource *resource, REFGUID guid) +HRESULT CDECL wined3d_resource_free_private_data(struct wined3d_resource *resource, REFGUID guid) { struct private_data *data; @@ -319,7 +318,7 @@ void * CDECL wined3d_resource_get_parent(const struct wined3d_resource *resource void CDECL wined3d_resource_get_desc(const struct wined3d_resource *resource, struct wined3d_resource_desc *desc) { - desc->resource_type = resource->resourceType; + desc->resource_type = resource->type; desc->format = resource->format->id; desc->multisample_type = resource->multisample_type; desc->multisample_quality = resource->multisample_quality; diff --git a/reactos/dll/directx/wine/wined3d/shader.c b/reactos/dll/directx/wine/wined3d/shader.c index 79a27595f02..50233e9406b 100644 --- a/reactos/dll/directx/wine/wined3d/shader.c +++ b/reactos/dll/directx/wine/wined3d/shader.c @@ -64,10 +64,12 @@ static const char * const shader_opcode_names[] = /* WINED3DSIH_ENDIF */ "endif", /* WINED3DSIH_ENDLOOP */ "endloop", /* WINED3DSIH_ENDREP */ "endrep", + /* WINED3DSIH_EQ */ "eq", /* WINED3DSIH_EXP */ "exp", /* WINED3DSIH_EXPP */ "expp", /* WINED3DSIH_FRC */ "frc", /* WINED3DSIH_FTOI */ "ftoi", + /* WINED3DSIH_GE */ "ge", /* WINED3DSIH_IADD */ "iadd", /* WINED3DSIH_IEQ */ "ieq", /* WINED3DSIH_IF */ "if", @@ -102,6 +104,7 @@ static const char * const shader_opcode_names[] = /* WINED3DSIH_RCP */ "rcp", /* WINED3DSIH_REP */ "rep", /* WINED3DSIH_RET */ "ret", + /* WINED3DSIH_ROUND_NI */ "round_ni", /* WINED3DSIH_RSQ */ "rsq", /* WINED3DSIH_SAMPLE */ "sample", /* WINED3DSIH_SAMPLE_GRAD */ "sample_d", @@ -135,7 +138,10 @@ static const char * const shader_opcode_names[] = /* WINED3DSIH_TEXREG2AR */ "texreg2ar", /* WINED3DSIH_TEXREG2GB */ "texreg2gb", /* WINED3DSIH_TEXREG2RGB */ "texreg2rgb", + /* WINED3DSIH_UDIV */ "udiv", + /* WINED3DSIH_USHR */ "ushr", /* WINED3DSIH_UTOF */ "utof", + /* WINED3DSIH_XOR */ "xor", }; static const char * const semantic_names[] = @@ -311,7 +317,7 @@ static void shader_init(struct wined3d_shader *shader, struct wined3d_device *de /* Convert floating point offset relative to a register file to an absolute * offset for float constants. */ -static unsigned int shader_get_float_offset(WINED3DSHADER_PARAM_REGISTER_TYPE register_type, UINT register_idx) +static unsigned int shader_get_float_offset(enum wined3d_shader_register_type register_type, UINT register_idx) { switch (register_type) { @@ -327,13 +333,13 @@ static unsigned int shader_get_float_offset(WINED3DSHADER_PARAM_REGISTER_TYPE re static void shader_delete_constant_list(struct list *clist) { - struct local_constant *constant; + struct wined3d_shader_lconst *constant; struct list *ptr; ptr = list_head(clist); while (ptr) { - constant = LIST_ENTRY(ptr, struct local_constant, entry); + constant = LIST_ENTRY(ptr, struct wined3d_shader_lconst, entry); ptr = list_next(clist, ptr); HeapFree(GetProcessHeap(), 0, constant); } @@ -530,7 +536,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st struct wined3d_shader_src_param rel_addr; struct wined3d_shader_dst_param dst; - local_constant *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant)); + struct wined3d_shader_lconst *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst)); if (!lconst) return E_OUTOFMEMORY; fe->shader_read_dst_param(fe_data, &ptr, &dst, &rel_addr); @@ -560,7 +566,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st struct wined3d_shader_src_param rel_addr; struct wined3d_shader_dst_param dst; - local_constant *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant)); + struct wined3d_shader_lconst *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst)); if (!lconst) return E_OUTOFMEMORY; fe->shader_read_dst_param(fe_data, &ptr, &dst, &rel_addr); @@ -577,7 +583,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st struct wined3d_shader_src_param rel_addr; struct wined3d_shader_dst_param dst; - local_constant *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant)); + struct wined3d_shader_lconst *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst)); if (!lconst) return E_OUTOFMEMORY; fe->shader_read_dst_param(fe_data, &ptr, &dst, &rel_addr); @@ -589,33 +595,6 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st list_add_head(&shader->constantsB, &lconst->entry); reg_maps->local_bool_consts |= (1 << dst.reg.idx); } - /* If there's a loop in the shader. */ - else if (ins.handler_idx == WINED3DSIH_LOOP - || ins.handler_idx == WINED3DSIH_REP) - { - struct wined3d_shader_src_param src, rel_addr; - - fe->shader_read_src_param(fe_data, &ptr, &src, &rel_addr); - - /* Rep and Loop always use an integer constant for the control parameters. */ - if (ins.handler_idx == WINED3DSIH_REP) - { - reg_maps->integer_constants |= 1 << src.reg.idx; - } - else - { - fe->shader_read_src_param(fe_data, &ptr, &src, &rel_addr); - reg_maps->integer_constants |= 1 << src.reg.idx; - } - - cur_loop_depth++; - if (cur_loop_depth > max_loop_depth) max_loop_depth = cur_loop_depth; - } - else if (ins.handler_idx == WINED3DSIH_ENDLOOP - || ins.handler_idx == WINED3DSIH_ENDREP) - { - cur_loop_depth--; - } /* For subroutine prototypes. */ else if (ins.handler_idx == WINED3DSIH_LABEL) { @@ -789,6 +768,16 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st else if (ins.handler_idx == WINED3DSIH_IFC) reg_maps->usesifc = 1; else if (ins.handler_idx == WINED3DSIH_CALL) reg_maps->usescall = 1; else if (ins.handler_idx == WINED3DSIH_POW) reg_maps->usespow = 1; + else if (ins.handler_idx == WINED3DSIH_LOOP + || ins.handler_idx == WINED3DSIH_REP) + { + ++cur_loop_depth; + if (cur_loop_depth > max_loop_depth) + max_loop_depth = cur_loop_depth; + } + else if (ins.handler_idx == WINED3DSIH_ENDLOOP + || ins.handler_idx == WINED3DSIH_ENDREP) + --cur_loop_depth; limit = ins.src_count + (ins.predicate ? 1 : 0); for (i = 0; i < limit; ++i) @@ -1099,7 +1088,7 @@ void shader_dump_dst_param(const struct wined3d_shader_dst_param *param, void shader_dump_src_param(const struct wined3d_shader_src_param *param, const struct wined3d_shader_version *shader_version) { - DWORD src_modifier = param->modifiers; + enum wined3d_shader_src_modifier src_modifier = param->modifiers; DWORD swizzle = param->swizzle; if (src_modifier == WINED3DSPSM_NEG @@ -1164,7 +1153,7 @@ void shader_dump_src_param(const struct wined3d_shader_src_param *param, /* Shared code in order to generate the bulk of the shader string. * NOTE: A description of how to parse tokens can be found on MSDN. */ -void shader_generate_main(struct wined3d_shader *shader, struct wined3d_shader_buffer *buffer, +void shader_generate_main(const struct wined3d_shader *shader, struct wined3d_shader_buffer *buffer, const struct wined3d_shader_reg_maps *reg_maps, const DWORD *byte_code, void *backend_ctx) { struct wined3d_device *device = shader->device; @@ -1439,12 +1428,12 @@ static void shader_trace_init(const struct wined3d_shader_frontend *fe, void *fe { switch (ins.flags) { - case COMPARISON_GT: TRACE("_gt"); break; - case COMPARISON_EQ: TRACE("_eq"); break; - case COMPARISON_GE: TRACE("_ge"); break; - case COMPARISON_LT: TRACE("_lt"); break; - case COMPARISON_NE: TRACE("_ne"); break; - case COMPARISON_LE: TRACE("_le"); break; + case WINED3D_SHADER_REL_OP_GT: TRACE("_gt"); break; + case WINED3D_SHADER_REL_OP_EQ: TRACE("_eq"); break; + case WINED3D_SHADER_REL_OP_GE: TRACE("_ge"); break; + case WINED3D_SHADER_REL_OP_LT: TRACE("_lt"); break; + case WINED3D_SHADER_REL_OP_NE: TRACE("_ne"); break; + case WINED3D_SHADER_REL_OP_LE: TRACE("_le"); break; default: TRACE("_(%u)", ins.flags); } } @@ -1502,7 +1491,7 @@ static void shader_none_load_np2fixup_constants(void *shader_priv, static void shader_none_destroy(struct wined3d_shader *shader) {} static HRESULT shader_none_alloc(struct wined3d_device *device) {return WINED3D_OK;} static void shader_none_free(struct wined3d_device *device) {} -static BOOL shader_none_dirty_const(void) {return FALSE;} +static void shader_none_context_destroyed(void *shader_priv, const struct wined3d_context *context) {} static void shader_none_get_caps(const struct wined3d_gl_info *gl_info, struct shader_caps *caps) { @@ -1547,17 +1536,19 @@ const struct wined3d_shader_backend_ops none_shader_backend = shader_none_destroy, shader_none_alloc, shader_none_free, - shader_none_dirty_const, + shader_none_context_destroyed, shader_none_get_caps, shader_none_color_fixup_supported, }; static HRESULT shader_set_function(struct wined3d_shader *shader, const DWORD *byte_code, - const struct wined3d_shader_signature *output_signature, DWORD float_const_count) + const struct wined3d_shader_signature *output_signature, DWORD float_const_count, + enum wined3d_shader_type type, unsigned int max_version) { struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps; const struct wined3d_shader_frontend *fe; HRESULT hr; + unsigned int backend_version; TRACE("shader %p, byte_code %p, output_signature %p, float_const_count %u.\n", shader, byte_code, output_signature, float_const_count); @@ -1591,6 +1582,35 @@ static HRESULT shader_set_function(struct wined3d_shader *shader, const DWORD *b byte_code, float_const_count); if (FAILED(hr)) return hr; + if (reg_maps->shader_version.type != type) + { + WARN("Wrong shader type %d.\n", reg_maps->shader_version.type); + return WINED3DERR_INVALIDCALL; + } + if (reg_maps->shader_version.major > max_version) + { + WARN("Shader version %d not supported by this D3D API version.\n", reg_maps->shader_version.major); + return WINED3DERR_INVALIDCALL; + } + switch (type) + { + case WINED3D_SHADER_TYPE_VERTEX: + backend_version = shader->device->vshader_version; + break; + case WINED3D_SHADER_TYPE_PIXEL: + backend_version = shader->device->pshader_version; + break; + default: + FIXME("No backend version-checking for this shader type\n"); + backend_version = 0; + } + if (reg_maps->shader_version.major > backend_version) + { + WARN("Shader version %d.%d not supported by your GPU with the current shader backend.\n", + reg_maps->shader_version.major, reg_maps->shader_version.minor); + return WINED3DERR_INVALIDCALL; + } + shader->function = HeapAlloc(GetProcessHeap(), 0, shader->functionLength); if (!shader->function) return E_OUTOFMEMORY; @@ -1674,7 +1694,7 @@ HRESULT CDECL wined3d_shader_set_local_constants_float(struct wined3d_shader *sh for (i = start_idx; i < end_idx; ++i) { - struct local_constant *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant)); + struct wined3d_shader_lconst *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst)); if (!lconst) return E_OUTOFMEMORY; @@ -1689,10 +1709,10 @@ HRESULT CDECL wined3d_shader_set_local_constants_float(struct wined3d_shader *sh void find_vs_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader, struct vs_compile_args *args) { - args->fog_src = state->render_states[WINED3DRS_FOGTABLEMODE] - == WINED3DFOG_NONE ? VS_FOG_COORD : VS_FOG_Z; - args->clip_enabled = state->render_states[WINED3DRS_CLIPPING] - && state->render_states[WINED3DRS_CLIPPLANEENABLE]; + args->fog_src = state->render_states[WINED3D_RS_FOGTABLEMODE] + == WINED3D_FOG_NONE ? VS_FOG_COORD : VS_FOG_Z; + args->clip_enabled = state->render_states[WINED3D_RS_CLIPPING] + && state->render_states[WINED3D_RS_CLIPPLANEENABLE]; args->swizzle_map = shader->device->strided_streams.swizzle_map; } @@ -1706,7 +1726,7 @@ static BOOL match_usage(BYTE usage1, BYTE usage_idx1, BYTE usage2, BYTE usage_id return FALSE; } -BOOL vshader_get_input(struct wined3d_shader *shader, +BOOL vshader_get_input(const struct wined3d_shader *shader, BYTE usage_req, BYTE usage_idx_req, unsigned int *regnum) { WORD map = shader->reg_maps.input_registers; @@ -1802,7 +1822,7 @@ static void vertexshader_set_limits(struct wined3d_shader *shader) static HRESULT vertexshader_init(struct wined3d_shader *shader, struct wined3d_device *device, const DWORD *byte_code, const struct wined3d_shader_signature *output_signature, - void *parent, const struct wined3d_parent_ops *parent_ops) + void *parent, const struct wined3d_parent_ops *parent_ops, unsigned int max_version) { struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps; unsigned int i; @@ -1812,7 +1832,8 @@ static HRESULT vertexshader_init(struct wined3d_shader *shader, struct wined3d_d if (!byte_code) return WINED3DERR_INVALIDCALL; shader_init(shader, device, parent, parent_ops); - hr = shader_set_function(shader, byte_code, output_signature, device->d3d_vshader_constantF); + hr = shader_set_function(shader, byte_code, output_signature, device->d3d_vshader_constantF, + WINED3D_SHADER_TYPE_VERTEX, max_version); if (FAILED(hr)) { WARN("Failed to set function, hr %#x.\n", hr); @@ -1851,12 +1872,13 @@ static HRESULT vertexshader_init(struct wined3d_shader *shader, struct wined3d_d static HRESULT geometryshader_init(struct wined3d_shader *shader, struct wined3d_device *device, const DWORD *byte_code, const struct wined3d_shader_signature *output_signature, - void *parent, const struct wined3d_parent_ops *parent_ops) + void *parent, const struct wined3d_parent_ops *parent_ops, unsigned int max_version) { HRESULT hr; shader_init(shader, device, parent, parent_ops); - hr = shader_set_function(shader, byte_code, output_signature, 0); + hr = shader_set_function(shader, byte_code, output_signature, 0, + WINED3D_SHADER_TYPE_GEOMETRY, max_version); if (FAILED(hr)) { WARN("Failed to set function, hr %#x.\n", hr); @@ -1877,9 +1899,9 @@ void find_ps_compile_args(const struct wined3d_state *state, UINT i; memset(args, 0, sizeof(*args)); /* FIXME: Make sure all bits are set. */ - if (state->render_states[WINED3DRS_SRGBWRITEENABLE]) + if (state->render_states[WINED3D_RS_SRGBWRITEENABLE]) { - struct wined3d_surface *rt = device->fb.render_targets[0]; + const struct wined3d_surface *rt = state->fb->render_targets[0]; if (rt->resource.format->flags & WINED3DFMT_FLAG_SRGB_WRITE) args->srgb_correction = 1; } @@ -1888,11 +1910,48 @@ void find_ps_compile_args(const struct wined3d_state *state, { for (i = 0; i < 4; ++i) { - DWORD flags = state->texture_states[i][WINED3DTSS_TEXTURETRANSFORMFLAGS]; - DWORD tex_transform = flags & ~WINED3DTTFF_PROJECTED; - if (flags & WINED3DTTFF_PROJECTED) - tex_transform |= WINED3D_PSARGS_PROJECTED; - args->tex_transform |= tex_transform << i * WINED3D_PSARGS_TEXTRANSFORM_SHIFT; + DWORD flags = state->texture_states[i][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS]; + + if (flags & WINED3D_TTFF_PROJECTED) + { + enum wined3d_sampler_texture_type sampler_type = shader->reg_maps.sampler_type[i]; + DWORD tex_transform = flags & ~WINED3D_TTFF_PROJECTED; + DWORD max_valid = WINED3D_TTFF_COUNT4; + + if (!state->vertex_shader) + { + unsigned int j; + unsigned int index = state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX]; + for (j = 0; j < state->vertex_declaration->element_count; ++j) + { + struct wined3d_vertex_declaration_element *element = + &state->vertex_declaration->elements[j]; + + if (element->usage == WINED3DDECLUSAGE_TEXCOORD + && element->usage_idx == index) + { + max_valid = element->format->component_count; + break; + } + } + } + + if (!tex_transform || tex_transform > max_valid) + { + WARN("Fixing up projected texture transform flags from %#x to %#x.\n", + tex_transform, max_valid); + tex_transform = max_valid; + } + + if ((sampler_type == WINED3DSTT_1D && tex_transform > WINED3D_TTFF_COUNT1) + || (sampler_type == WINED3DSTT_2D && tex_transform > WINED3D_TTFF_COUNT2) + || (sampler_type == WINED3DSTT_VOLUME && tex_transform > WINED3D_TTFF_COUNT3)) + tex_transform |= WINED3D_PSARGS_PROJECTED; + else + WARN("Application requested projected texture with unsuitable texture coordinates.\n"); + + args->tex_transform |= tex_transform << i * WINED3D_PSARGS_TEXTRANSFORM_SHIFT; + } } } @@ -1935,29 +1994,29 @@ void find_ps_compile_args(const struct wined3d_state *state, else { args->vp_mode = vertexshader; - if (state->render_states[WINED3DRS_FOGENABLE]) + if (state->render_states[WINED3D_RS_FOGENABLE]) { - switch (state->render_states[WINED3DRS_FOGTABLEMODE]) + switch (state->render_states[WINED3D_RS_FOGTABLEMODE]) { - case WINED3DFOG_NONE: + case WINED3D_FOG_NONE: if (device->strided_streams.position_transformed || use_vs(state)) { args->fog = FOG_LINEAR; break; } - switch (state->render_states[WINED3DRS_FOGVERTEXMODE]) + switch (state->render_states[WINED3D_RS_FOGVERTEXMODE]) { - case WINED3DFOG_NONE: /* Fall through. */ - case WINED3DFOG_LINEAR: args->fog = FOG_LINEAR; break; - case WINED3DFOG_EXP: args->fog = FOG_EXP; break; - case WINED3DFOG_EXP2: args->fog = FOG_EXP2; break; + case WINED3D_FOG_NONE: /* Fall through. */ + case WINED3D_FOG_LINEAR: args->fog = FOG_LINEAR; break; + case WINED3D_FOG_EXP: args->fog = FOG_EXP; break; + case WINED3D_FOG_EXP2: args->fog = FOG_EXP2; break; } break; - case WINED3DFOG_LINEAR: args->fog = FOG_LINEAR; break; - case WINED3DFOG_EXP: args->fog = FOG_EXP; break; - case WINED3DFOG_EXP2: args->fog = FOG_EXP2; break; + case WINED3D_FOG_LINEAR: args->fog = FOG_LINEAR; break; + case WINED3D_FOG_EXP: args->fog = FOG_EXP; break; + case WINED3D_FOG_EXP2: args->fog = FOG_EXP2; break; } } else @@ -2057,7 +2116,7 @@ static void pixelshader_set_limits(struct wined3d_shader *shader) static HRESULT pixelshader_init(struct wined3d_shader *shader, struct wined3d_device *device, const DWORD *byte_code, const struct wined3d_shader_signature *output_signature, - void *parent, const struct wined3d_parent_ops *parent_ops) + void *parent, const struct wined3d_parent_ops *parent_ops, unsigned int max_version) { const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; unsigned int i, highest_reg_used = 0, num_regs_used = 0; @@ -2066,7 +2125,8 @@ static HRESULT pixelshader_init(struct wined3d_shader *shader, struct wined3d_de if (!byte_code) return WINED3DERR_INVALIDCALL; shader_init(shader, device, parent, parent_ops); - hr = shader_set_function(shader, byte_code, output_signature, device->d3d_pshader_constantF); + hr = shader_set_function(shader, byte_code, output_signature, device->d3d_pshader_constantF, + WINED3D_SHADER_TYPE_PIXEL, max_version); if (FAILED(hr)) { WARN("Failed to set function, hr %#x.\n", hr); @@ -2123,7 +2183,7 @@ static HRESULT pixelshader_init(struct wined3d_shader *shader, struct wined3d_de void pixelshader_update_samplers(struct wined3d_shader_reg_maps *reg_maps, struct wined3d_texture * const *textures) { - WINED3DSAMPLER_TEXTURE_TYPE *sampler_type = reg_maps->sampler_type; + enum wined3d_sampler_texture_type *sampler_type = reg_maps->sampler_type; unsigned int i; if (reg_maps->shader_version.major != 1) return; @@ -2167,7 +2227,7 @@ void pixelshader_update_samplers(struct wined3d_shader_reg_maps *reg_maps, struc HRESULT CDECL wined3d_shader_create_gs(struct wined3d_device *device, const DWORD *byte_code, const struct wined3d_shader_signature *output_signature, void *parent, - const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader) + const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader, unsigned int max_version) { struct wined3d_shader *object; HRESULT hr; @@ -2182,7 +2242,7 @@ HRESULT CDECL wined3d_shader_create_gs(struct wined3d_device *device, const DWOR return E_OUTOFMEMORY; } - hr = geometryshader_init(object, device, byte_code, output_signature, parent, parent_ops); + hr = geometryshader_init(object, device, byte_code, output_signature, parent, parent_ops, max_version); if (FAILED(hr)) { WARN("Failed to initialize geometry shader, hr %#x.\n", hr); @@ -2198,7 +2258,7 @@ HRESULT CDECL wined3d_shader_create_gs(struct wined3d_device *device, const DWOR HRESULT CDECL wined3d_shader_create_ps(struct wined3d_device *device, const DWORD *byte_code, const struct wined3d_shader_signature *output_signature, void *parent, - const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader) + const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader, unsigned int max_version) { struct wined3d_shader *object; HRESULT hr; @@ -2216,7 +2276,7 @@ HRESULT CDECL wined3d_shader_create_ps(struct wined3d_device *device, const DWOR return E_OUTOFMEMORY; } - hr = pixelshader_init(object, device, byte_code, output_signature, parent, parent_ops); + hr = pixelshader_init(object, device, byte_code, output_signature, parent, parent_ops, max_version); if (FAILED(hr)) { WARN("Failed to initialize pixel shader, hr %#x.\n", hr); @@ -2232,7 +2292,7 @@ HRESULT CDECL wined3d_shader_create_ps(struct wined3d_device *device, const DWOR HRESULT CDECL wined3d_shader_create_vs(struct wined3d_device *device, const DWORD *byte_code, const struct wined3d_shader_signature *output_signature, void *parent, - const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader) + const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader, unsigned int max_version) { struct wined3d_shader *object; HRESULT hr; @@ -2250,7 +2310,7 @@ HRESULT CDECL wined3d_shader_create_vs(struct wined3d_device *device, const DWOR return E_OUTOFMEMORY; } - hr = vertexshader_init(object, device, byte_code, output_signature, parent, parent_ops); + hr = vertexshader_init(object, device, byte_code, output_signature, parent, parent_ops, max_version); if (FAILED(hr)) { WARN("Failed to initialize vertex shader, hr %#x.\n", hr); diff --git a/reactos/dll/directx/wine/wined3d/shader_sm4.c b/reactos/dll/directx/wine/wined3d/shader_sm4.c index d0b36c6715c..25bb72a4275 100644 --- a/reactos/dll/directx/wine/wined3d/shader_sm4.c +++ b/reactos/dll/directx/wine/wined3d/shader_sm4.c @@ -57,15 +57,19 @@ enum wined3d_sm4_opcode WINED3D_SM4_OP_BREAK = 0x02, WINED3D_SM4_OP_BREAKC = 0x03, WINED3D_SM4_OP_CUT = 0x09, + WINED3D_SM4_OP_DERIV_RTX = 0x0b, + WINED3D_SM4_OP_DERIV_RTY = 0x0c, WINED3D_SM4_OP_DIV = 0x0e, WINED3D_SM4_OP_DP3 = 0x10, WINED3D_SM4_OP_DP4 = 0x11, WINED3D_SM4_OP_EMIT = 0x13, WINED3D_SM4_OP_ENDIF = 0x15, WINED3D_SM4_OP_ENDLOOP = 0x16, + WINED3D_SM4_OP_EQ = 0x18, WINED3D_SM4_OP_EXP = 0x19, WINED3D_SM4_OP_FRC = 0x1a, WINED3D_SM4_OP_FTOI = 0x1b, + WINED3D_SM4_OP_GE = 0x1d, WINED3D_SM4_OP_IADD = 0x1e, WINED3D_SM4_OP_IF = 0x1f, WINED3D_SM4_OP_IEQ = 0x20, @@ -83,13 +87,17 @@ enum wined3d_sm4_opcode WINED3D_SM4_OP_MOVC = 0x37, WINED3D_SM4_OP_MUL = 0x38, WINED3D_SM4_OP_RET = 0x3e, + WINED3D_SM4_OP_ROUND_NI = 0x41, WINED3D_SM4_OP_RSQ = 0x44, WINED3D_SM4_OP_SAMPLE = 0x45, WINED3D_SM4_OP_SAMPLE_LOD = 0x48, WINED3D_SM4_OP_SAMPLE_GRAD = 0x49, WINED3D_SM4_OP_SQRT = 0x4b, WINED3D_SM4_OP_SINCOS = 0x4d, + WINED3D_SM4_OP_UDIV = 0x4e, + WINED3D_SM4_OP_USHR = 0x55, WINED3D_SM4_OP_UTOF = 0x56, + WINED3D_SM4_OP_XOR = 0x57, }; enum wined3d_sm4_register_type @@ -127,7 +135,7 @@ struct wined3d_sm4_opcode_info struct sysval_map { enum wined3d_sysval_semantic sysval; - WINED3DSHADER_PARAM_REGISTER_TYPE register_type; + enum wined3d_shader_register_type register_type; UINT register_idx; }; @@ -138,15 +146,19 @@ static const struct wined3d_sm4_opcode_info opcode_table[] = {WINED3D_SM4_OP_BREAK, WINED3DSIH_BREAK, 0, 0}, {WINED3D_SM4_OP_BREAKC, WINED3DSIH_BREAKP, 0, 1}, {WINED3D_SM4_OP_CUT, WINED3DSIH_CUT, 0, 0}, + {WINED3D_SM4_OP_DERIV_RTX, WINED3DSIH_DSX, 1, 1}, + {WINED3D_SM4_OP_DERIV_RTY, WINED3DSIH_DSY, 1, 1}, {WINED3D_SM4_OP_DIV, WINED3DSIH_DIV, 1, 2}, {WINED3D_SM4_OP_DP3, WINED3DSIH_DP3, 1, 2}, {WINED3D_SM4_OP_DP4, WINED3DSIH_DP4, 1, 2}, {WINED3D_SM4_OP_EMIT, WINED3DSIH_EMIT, 0, 0}, {WINED3D_SM4_OP_ENDIF, WINED3DSIH_ENDIF, 0, 0}, {WINED3D_SM4_OP_ENDLOOP, WINED3DSIH_ENDLOOP, 0, 0}, + {WINED3D_SM4_OP_EQ, WINED3DSIH_EQ, 1, 2}, {WINED3D_SM4_OP_EXP, WINED3DSIH_EXP, 1, 1}, {WINED3D_SM4_OP_FRC, WINED3DSIH_FRC, 1, 1}, {WINED3D_SM4_OP_FTOI, WINED3DSIH_FTOI, 1, 1}, + {WINED3D_SM4_OP_GE, WINED3DSIH_GE, 1, 2}, {WINED3D_SM4_OP_IADD, WINED3DSIH_IADD, 1, 2}, {WINED3D_SM4_OP_IF, WINED3DSIH_IF, 0, 1}, {WINED3D_SM4_OP_IEQ, WINED3DSIH_IEQ, 1, 2}, @@ -164,16 +176,20 @@ static const struct wined3d_sm4_opcode_info opcode_table[] = {WINED3D_SM4_OP_MOVC, WINED3DSIH_MOVC, 1, 3}, {WINED3D_SM4_OP_MUL, WINED3DSIH_MUL, 1, 2}, {WINED3D_SM4_OP_RET, WINED3DSIH_RET, 0, 0}, + {WINED3D_SM4_OP_ROUND_NI, WINED3DSIH_ROUND_NI, 1, 1}, {WINED3D_SM4_OP_RSQ, WINED3DSIH_RSQ, 1, 1}, {WINED3D_SM4_OP_SAMPLE, WINED3DSIH_SAMPLE, 1, 3}, {WINED3D_SM4_OP_SAMPLE_LOD, WINED3DSIH_SAMPLE_LOD, 1, 4}, {WINED3D_SM4_OP_SAMPLE_GRAD,WINED3DSIH_SAMPLE_GRAD, 1, 5}, {WINED3D_SM4_OP_SQRT, WINED3DSIH_SQRT, 1, 1}, {WINED3D_SM4_OP_SINCOS, WINED3DSIH_SINCOS, 2, 1}, + {WINED3D_SM4_OP_UDIV, WINED3DSIH_UDIV, 2, 2}, + {WINED3D_SM4_OP_USHR, WINED3DSIH_USHR, 1, 2}, {WINED3D_SM4_OP_UTOF, WINED3DSIH_UTOF, 1, 1}, + {WINED3D_SM4_OP_XOR, WINED3DSIH_XOR, 1, 2}, }; -static const WINED3DSHADER_PARAM_REGISTER_TYPE register_type_table[] = +static const enum wined3d_shader_register_type register_type_table[] = { /* WINED3D_SM4_RT_TEMP */ WINED3DSPR_TEMP, /* WINED3D_SM4_RT_INPUT */ WINED3DSPR_INPUT, @@ -230,7 +246,7 @@ static void map_sysval(enum wined3d_sysval_semantic sysval, struct wined3d_shade } } -static void map_register(struct wined3d_sm4_data *priv, struct wined3d_shader_register *reg) +static void map_register(const struct wined3d_sm4_data *priv, struct wined3d_shader_register *reg) { switch (priv->shader_version.type) { diff --git a/reactos/dll/directx/wine/wined3d/state.c b/reactos/dll/directx/wine/wined3d/state.c index a43cc383ca1..6c92e6ea1ab 100644 --- a/reactos/dll/directx/wine/wined3d/state.c +++ b/reactos/dll/directx/wine/wined3d/state.c @@ -37,54 +37,51 @@ WINE_DECLARE_DEBUG_CHANNEL(d3d_shader); /* GL locking for state handlers is done by the caller. */ -static void state_blendop(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context); - -static void state_undefined(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_undefined(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { ERR("Undefined state.\n"); } -static void state_nop(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_nop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - TRACE("%s: nop in current pipe config.\n", debug_d3dstate(state)); + TRACE("%s: nop in current pipe config.\n", debug_d3dstate(state_id)); } -static void state_fillmode(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_fillmode(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - WINED3DFILLMODE Value = stateblock->state.render_states[WINED3DRS_FILLMODE]; + enum wined3d_fill_mode mode = state->render_states[WINED3D_RS_FILLMODE]; - switch(Value) { - case WINED3DFILL_POINT: + switch (mode) + { + case WINED3D_FILL_POINT: glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_POINT)"); break; - case WINED3DFILL_WIREFRAME: + case WINED3D_FILL_WIREFRAME: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)"); break; - case WINED3DFILL_SOLID: + case WINED3D_FILL_SOLID: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)"); break; default: - FIXME("Unrecognized WINED3DRS_FILLMODE value %d\n", Value); + FIXME("Unrecognized fill mode %#x.\n", mode); } } -static void state_lighting(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_lighting(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - /* Lighting is not enabled if transformed vertices are drawn - * but lighting does not affect the stream sources, so it is not grouped for performance reasons. - * This state reads the decoded vertex declaration, so if it is dirty don't do anything. The - * vertex declaration applying function calls this function for updating - */ - - if(isStateDirty(context, STATE_VDECL)) { + /* Lighting is not enabled if transformed vertices are drawn, but lighting + * does not affect the stream sources, so it is not grouped for + * performance reasons. This state reads the decoded vertex declaration, + * so if it is dirty don't do anything. The vertex declaration applying + * function calls this function for updating. */ + if (isStateDirty(context, STATE_VDECL)) return; - } - if (stateblock->state.render_states[WINED3DRS_LIGHTING] - && !stateblock->device->strided_streams.position_transformed) + if (state->render_states[WINED3D_RS_LIGHTING] + && !context->swapchain->device->strided_streams.position_transformed) { glEnable(GL_LIGHTING); checkGLcall("glEnable GL_LIGHTING"); @@ -94,10 +91,10 @@ static void state_lighting(DWORD state, struct wined3d_stateblock *stateblock, s } } -static void state_zenable(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_zenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { /* No z test without depth stencil buffers */ - if (!stateblock->device->fb.depth_stencil) + if (!state->fb->depth_stencil) { TRACE("No Z buffer - disabling depth test\n"); glDisable(GL_DEPTH_TEST); /* This also disables z writing in gl */ @@ -105,79 +102,79 @@ static void state_zenable(DWORD state, struct wined3d_stateblock *stateblock, st return; } - switch (stateblock->state.render_states[WINED3DRS_ZENABLE]) + switch (state->render_states[WINED3D_RS_ZENABLE]) { - case WINED3DZB_FALSE: + case WINED3D_ZB_FALSE: glDisable(GL_DEPTH_TEST); checkGLcall("glDisable GL_DEPTH_TEST"); break; - case WINED3DZB_TRUE: + case WINED3D_ZB_TRUE: glEnable(GL_DEPTH_TEST); checkGLcall("glEnable GL_DEPTH_TEST"); break; - case WINED3DZB_USEW: + case WINED3D_ZB_USEW: glEnable(GL_DEPTH_TEST); checkGLcall("glEnable GL_DEPTH_TEST"); FIXME("W buffer is not well handled\n"); break; default: - FIXME("Unrecognized D3DZBUFFERTYPE value %#x.\n", - stateblock->state.render_states[WINED3DRS_ZENABLE]); + FIXME("Unrecognized depth buffer type %#x.\n", + state->render_states[WINED3D_RS_ZENABLE]); } } -static void state_cullmode(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_cullmode(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { /* glFrontFace() is set in context.c at context init and on an * offscreen / onscreen rendering switch. */ - switch (stateblock->state.render_states[WINED3DRS_CULLMODE]) + switch (state->render_states[WINED3D_RS_CULLMODE]) { - case WINED3DCULL_NONE: + case WINED3D_CULL_NONE: glDisable(GL_CULL_FACE); checkGLcall("glDisable GL_CULL_FACE"); break; - case WINED3DCULL_CW: + case WINED3D_CULL_CW: glEnable(GL_CULL_FACE); checkGLcall("glEnable GL_CULL_FACE"); glCullFace(GL_FRONT); checkGLcall("glCullFace(GL_FRONT)"); break; - case WINED3DCULL_CCW: + case WINED3D_CULL_CCW: glEnable(GL_CULL_FACE); checkGLcall("glEnable GL_CULL_FACE"); glCullFace(GL_BACK); checkGLcall("glCullFace(GL_BACK)"); break; default: - FIXME("Unrecognized/Unhandled WINED3DCULL value %#x.\n", - stateblock->state.render_states[WINED3DRS_CULLMODE]); + FIXME("Unrecognized cull mode %#x.\n", + state->render_states[WINED3D_RS_CULLMODE]); } } -static void state_shademode(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_shademode(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - switch (stateblock->state.render_states[WINED3DRS_SHADEMODE]) + switch (state->render_states[WINED3D_RS_SHADEMODE]) { - case WINED3DSHADE_FLAT: + case WINED3D_SHADE_FLAT: glShadeModel(GL_FLAT); checkGLcall("glShadeModel(GL_FLAT)"); break; - case WINED3DSHADE_GOURAUD: + case WINED3D_SHADE_GOURAUD: glShadeModel(GL_SMOOTH); checkGLcall("glShadeModel(GL_SMOOTH)"); break; - case WINED3DSHADE_PHONG: - FIXME("WINED3DSHADE_PHONG isn't supported\n"); + case WINED3D_SHADE_PHONG: + FIXME("WINED3D_SHADE_PHONG isn't supported.\n"); break; default: - FIXME("Unrecognized/Unhandled WINED3DSHADEMODE value %#x.\n", - stateblock->state.render_states[WINED3DRS_SHADEMODE]); + FIXME("Unrecognized shade mode %#x.\n", + state->render_states[WINED3D_RS_SHADEMODE]); } } -static void state_ditherenable(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_ditherenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_DITHERENABLE]) + if (state->render_states[WINED3D_RS_DITHERENABLE]) { glEnable(GL_DITHER); checkGLcall("glEnable GL_DITHER"); @@ -189,11 +186,11 @@ static void state_ditherenable(DWORD state, struct wined3d_stateblock *statebloc } } -static void state_zwritenable(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_zwritenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { /* TODO: Test if in d3d z writing is enabled even if ZENABLE is off. * If yes, this has to be merged with ZENABLE and ZFUNC. */ - if (stateblock->state.render_states[WINED3DRS_ZWRITEENABLE]) + if (state->render_states[WINED3D_RS_ZWRITEENABLE]) { glDepthMask(1); checkGLcall("glDepthMask(1)"); @@ -205,9 +202,35 @@ static void state_zwritenable(DWORD state, struct wined3d_stateblock *stateblock } } -static void state_zfunc(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static GLenum gl_compare_func(enum wined3d_cmp_func f) { - GLenum depth_func = CompareFunc(stateblock->state.render_states[WINED3DRS_ZFUNC]); + switch (f) + { + case WINED3D_CMP_NEVER: + return GL_NEVER; + case WINED3D_CMP_LESS: + return GL_LESS; + case WINED3D_CMP_EQUAL: + return GL_EQUAL; + case WINED3D_CMP_LESSEQUAL: + return GL_LEQUAL; + case WINED3D_CMP_GREATER: + return GL_GREATER; + case WINED3D_CMP_NOTEQUAL: + return GL_NOTEQUAL; + case WINED3D_CMP_GREATEREQUAL: + return GL_GEQUAL; + case WINED3D_CMP_ALWAYS: + return GL_ALWAYS; + default: + FIXME("Unrecognized compare function %#x.\n", f); + return GL_NONE; + } +} + +static void state_zfunc(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) +{ + GLenum depth_func = gl_compare_func(state->render_states[WINED3D_RS_ZFUNC]); if (!depth_func) return; @@ -230,51 +253,106 @@ static void state_zfunc(DWORD state, struct wined3d_stateblock *stateblock, stru checkGLcall("glDepthFunc"); } -static void state_ambient(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_ambient(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { float col[4]; - D3DCOLORTOGLFLOAT4(stateblock->state.render_states[WINED3DRS_AMBIENT], col); + D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_AMBIENT], col); TRACE("Setting ambient to (%f,%f,%f,%f)\n", col[0], col[1], col[2], col[3]); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, col); checkGLcall("glLightModel for MODEL_AMBIENT"); } -static GLenum gl_blend_factor(WINED3DBLEND factor, const struct wined3d_format *dst_format) +static void state_blendop_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) +{ + WARN("Unsupported in local OpenGL implementation: glBlendEquation\n"); +} + +static GLenum gl_blend_op(enum wined3d_blend_op op) +{ + switch (op) + { + case WINED3D_BLEND_OP_ADD: + return GL_FUNC_ADD_EXT; + case WINED3D_BLEND_OP_SUBTRACT: + return GL_FUNC_SUBTRACT_EXT; + case WINED3D_BLEND_OP_REVSUBTRACT: + return GL_FUNC_REVERSE_SUBTRACT_EXT; + case WINED3D_BLEND_OP_MIN: + return GL_MIN_EXT; + case WINED3D_BLEND_OP_MAX: + return GL_MAX_EXT; + default: + FIXME("Unhandled blend op %#x.\n", op); + return GL_NONE; + } +} + +static void state_blendop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) +{ + const struct wined3d_gl_info *gl_info = context->gl_info; + GLenum blend_equation_alpha = GL_FUNC_ADD_EXT; + GLenum blend_equation = GL_FUNC_ADD_EXT; + + /* BLENDOPALPHA requires GL_EXT_blend_equation_separate, so make sure it is around */ + if (state->render_states[WINED3D_RS_BLENDOPALPHA] + && !gl_info->supported[EXT_BLEND_EQUATION_SEPARATE]) + { + WARN("Unsupported in local OpenGL implementation: glBlendEquationSeparateEXT\n"); + return; + } + + blend_equation = gl_blend_op(state->render_states[WINED3D_RS_BLENDOP]); + blend_equation_alpha = gl_blend_op(state->render_states[WINED3D_RS_BLENDOPALPHA]); + TRACE("blend_equation %#x, blend_equation_alpha %#x.\n", blend_equation, blend_equation_alpha); + + if (state->render_states[WINED3D_RS_SEPARATEALPHABLENDENABLE]) + { + GL_EXTCALL(glBlendEquationSeparateEXT(blend_equation, blend_equation_alpha)); + checkGLcall("glBlendEquationSeparateEXT"); + } + else + { + GL_EXTCALL(glBlendEquationEXT(blend_equation)); + checkGLcall("glBlendEquation"); + } +} + +static GLenum gl_blend_factor(enum wined3d_blend factor, const struct wined3d_format *dst_format) { switch (factor) { - case WINED3DBLEND_ZERO: + case WINED3D_BLEND_ZERO: return GL_ZERO; - case WINED3DBLEND_ONE: + case WINED3D_BLEND_ONE: return GL_ONE; - case WINED3DBLEND_SRCCOLOR: + case WINED3D_BLEND_SRCCOLOR: return GL_SRC_COLOR; - case WINED3DBLEND_INVSRCCOLOR: + case WINED3D_BLEND_INVSRCCOLOR: return GL_ONE_MINUS_SRC_COLOR; - case WINED3DBLEND_SRCALPHA: + case WINED3D_BLEND_SRCALPHA: return GL_SRC_ALPHA; - case WINED3DBLEND_INVSRCALPHA: + case WINED3D_BLEND_INVSRCALPHA: return GL_ONE_MINUS_SRC_ALPHA; - case WINED3DBLEND_DESTCOLOR: + case WINED3D_BLEND_DESTCOLOR: return GL_DST_COLOR; - case WINED3DBLEND_INVDESTCOLOR: + case WINED3D_BLEND_INVDESTCOLOR: return GL_ONE_MINUS_DST_COLOR; /* To compensate for the lack of format switching with backbuffer * offscreen rendering, and with onscreen rendering, we modify the * alpha test parameters for (INV)DESTALPHA if the render target * doesn't support alpha blending. A nonexistent alpha channel - * returns 1.0, so WINED3DBLEND_DESTALPHA becomes GL_ONE, and - * WINED3DBLEND_INVDESTALPHA becomes GL_ZERO. */ - case WINED3DBLEND_DESTALPHA: + * returns 1.0, so WINED3D_BLEND_DESTALPHA becomes GL_ONE, and + * WINED3D_BLEND_INVDESTALPHA becomes GL_ZERO. */ + case WINED3D_BLEND_DESTALPHA: return dst_format->alpha_mask ? GL_DST_ALPHA : GL_ONE; - case WINED3DBLEND_INVDESTALPHA: + case WINED3D_BLEND_INVDESTALPHA: return dst_format->alpha_mask ? GL_ONE_MINUS_DST_ALPHA : GL_ZERO; - case WINED3DBLEND_SRCALPHASAT: + case WINED3D_BLEND_SRCALPHASAT: return GL_SRC_ALPHA_SATURATE; - case WINED3DBLEND_BLENDFACTOR: + case WINED3D_BLEND_BLENDFACTOR: return GL_CONSTANT_COLOR_EXT; - case WINED3DBLEND_INVBLENDFACTOR: + case WINED3D_BLEND_INVBLENDFACTOR: return GL_ONE_MINUS_CONSTANT_COLOR_EXT; default: FIXME("Unhandled blend factor %#x.\n", factor); @@ -282,18 +360,18 @@ static GLenum gl_blend_factor(WINED3DBLEND factor, const struct wined3d_format * } } -static void state_blend(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_blend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - struct wined3d_surface *target = stateblock->device->fb.render_targets[0]; + const struct wined3d_surface *target = state->fb->render_targets[0]; const struct wined3d_gl_info *gl_info = context->gl_info; GLenum srcBlend, dstBlend; - WINED3DBLEND d3d_blend; + enum wined3d_blend d3d_blend; /* According to the red book, GL_LINE_SMOOTH needs GL_BLEND with specific * blending parameters to work. */ - if (stateblock->state.render_states[WINED3DRS_ALPHABLENDENABLE] - || stateblock->state.render_states[WINED3DRS_EDGEANTIALIAS] - || stateblock->state.render_states[WINED3DRS_ANTIALIASEDLINEENABLE]) + if (state->render_states[WINED3D_RS_ALPHABLENDENABLE] + || state->render_states[WINED3D_RS_EDGEANTIALIAS] + || state->render_states[WINED3D_RS_ANTIALIASEDLINEENABLE]) { /* Disable blending in all cases even without pixelshaders. * With blending on we could face a big performance penalty. @@ -315,16 +393,16 @@ static void state_blend(DWORD state, struct wined3d_stateblock *stateblock, stru return; }; - /* WINED3DBLEND_BOTHSRCALPHA and WINED3DBLEND_BOTHINVSRCALPHA are legacy + /* WINED3D_BLEND_BOTHSRCALPHA and WINED3D_BLEND_BOTHINVSRCALPHA are legacy * source blending values which are still valid up to d3d9. They should * not occur as dest blend values. */ - d3d_blend = stateblock->state.render_states[WINED3DRS_SRCBLEND]; - if (d3d_blend == WINED3DBLEND_BOTHSRCALPHA) + d3d_blend = state->render_states[WINED3D_RS_SRCBLEND]; + if (d3d_blend == WINED3D_BLEND_BOTHSRCALPHA) { srcBlend = GL_SRC_ALPHA; dstBlend = GL_ONE_MINUS_SRC_ALPHA; } - else if (d3d_blend == WINED3DBLEND_BOTHINVSRCALPHA) + else if (d3d_blend == WINED3D_BLEND_BOTHINVSRCALPHA) { srcBlend = GL_ONE_MINUS_SRC_ALPHA; dstBlend = GL_SRC_ALPHA; @@ -332,20 +410,20 @@ static void state_blend(DWORD state, struct wined3d_stateblock *stateblock, stru else { srcBlend = gl_blend_factor(d3d_blend, target->resource.format); - dstBlend = gl_blend_factor(stateblock->state.render_states[WINED3DRS_DESTBLEND], + dstBlend = gl_blend_factor(state->render_states[WINED3D_RS_DESTBLEND], target->resource.format); } - if (stateblock->state.render_states[WINED3DRS_EDGEANTIALIAS] - || stateblock->state.render_states[WINED3DRS_ANTIALIASEDLINEENABLE]) + if (state->render_states[WINED3D_RS_EDGEANTIALIAS] + || state->render_states[WINED3D_RS_ANTIALIASEDLINEENABLE]) { glEnable(GL_LINE_SMOOTH); checkGLcall("glEnable(GL_LINE_SMOOTH)"); if(srcBlend != GL_SRC_ALPHA) { - WARN("WINED3DRS_EDGEANTIALIAS enabled, but unexpected src blending param\n"); + WARN("WINED3D_RS_EDGEANTIALIAS enabled, but unexpected src blending param\n"); } if(dstBlend != GL_ONE_MINUS_SRC_ALPHA && dstBlend != GL_ONE) { - WARN("WINED3DRS_EDGEANTIALIAS enabled, but unexpected dst blending param\n"); + WARN("WINED3D_RS_EDGEANTIALIAS enabled, but unexpected dst blending param\n"); } } else { glDisable(GL_LINE_SMOOTH); @@ -353,11 +431,10 @@ static void state_blend(DWORD state, struct wined3d_stateblock *stateblock, stru } /* Re-apply BLENDOP(ALPHA) because of a possible SEPARATEALPHABLENDENABLE change */ - if(!isStateDirty(context, STATE_RENDER(WINED3DRS_BLENDOP))) { - state_blendop(STATE_RENDER(WINED3DRS_BLENDOPALPHA), stateblock, context); - } + if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_BLENDOP))) + state_blendop(context, state, STATE_RENDER(WINED3D_RS_BLENDOPALPHA)); - if (stateblock->state.render_states[WINED3DRS_SEPARATEALPHABLENDENABLE]) + if (state->render_states[WINED3D_RS_SEPARATEALPHABLENDENABLE]) { GLenum srcBlendAlpha, dstBlendAlpha; @@ -368,16 +445,16 @@ static void state_blend(DWORD state, struct wined3d_stateblock *stateblock, stru return; } - /* WINED3DBLEND_BOTHSRCALPHA and WINED3DBLEND_BOTHINVSRCALPHA are legacy + /* WINED3D_BLEND_BOTHSRCALPHA and WINED3D_BLEND_BOTHINVSRCALPHA are legacy * source blending values which are still valid up to d3d9. They should * not occur as dest blend values. */ - d3d_blend = stateblock->state.render_states[WINED3DRS_SRCBLENDALPHA]; - if (d3d_blend == WINED3DBLEND_BOTHSRCALPHA) + d3d_blend = state->render_states[WINED3D_RS_SRCBLENDALPHA]; + if (d3d_blend == WINED3D_BLEND_BOTHSRCALPHA) { srcBlendAlpha = GL_SRC_ALPHA; dstBlendAlpha = GL_ONE_MINUS_SRC_ALPHA; } - else if (d3d_blend == WINED3DBLEND_BOTHINVSRCALPHA) + else if (d3d_blend == WINED3D_BLEND_BOTHINVSRCALPHA) { srcBlendAlpha = GL_ONE_MINUS_SRC_ALPHA; dstBlendAlpha = GL_SRC_ALPHA; @@ -385,7 +462,7 @@ static void state_blend(DWORD state, struct wined3d_stateblock *stateblock, stru else { srcBlendAlpha = gl_blend_factor(d3d_blend, target->resource.format); - dstBlendAlpha = gl_blend_factor(stateblock->state.render_states[WINED3DRS_DESTBLENDALPHA], + dstBlendAlpha = gl_blend_factor(state->render_states[WINED3D_RS_DESTBLENDALPHA], target->resource.format); } @@ -397,45 +474,46 @@ static void state_blend(DWORD state, struct wined3d_stateblock *stateblock, stru checkGLcall("glBlendFunc"); } - /* colorkey fixup for stage 0 alphaop depends on WINED3DRS_ALPHABLENDENABLE state, - so it may need updating */ - if (stateblock->state.render_states[WINED3DRS_COLORKEYENABLE]) - stateblock_apply_state(STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), stateblock, context); + /* Colorkey fixup for stage 0 alphaop depends on + * WINED3D_RS_ALPHABLENDENABLE state, so it may need updating. */ + if (state->render_states[WINED3D_RS_COLORKEYENABLE]) + context_apply_state(context, state, STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP)); } -static void state_blendfactor_w(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_blendfactor_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { WARN("Unsupported in local OpenGL implementation: glBlendColorEXT\n"); } -static void state_blendfactor(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_blendfactor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { const struct wined3d_gl_info *gl_info = context->gl_info; float col[4]; - TRACE("Setting blend factor to %#x.\n", stateblock->state.render_states[WINED3DRS_BLENDFACTOR]); - D3DCOLORTOGLFLOAT4(stateblock->state.render_states[WINED3DRS_BLENDFACTOR], col); + TRACE("Setting blend factor to %#x.\n", state->render_states[WINED3D_RS_BLENDFACTOR]); + + D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_BLENDFACTOR], col); GL_EXTCALL(glBlendColorEXT (col[0],col[1],col[2],col[3])); checkGLcall("glBlendColor"); } -static void state_alpha(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_alpha(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { int glParm = 0; float ref; BOOL enable_ckey = FALSE; - TRACE("state %#x, stateblock %p, context %p\n", state, stateblock, context); + TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id); /* Find out if the texture on the first stage has a ckey set * The alpha state func reads the texture settings, even though alpha and texture are not grouped * together. This is to avoid making a huge alpha+texture+texture stage+ckey block due to the hardly - * used WINED3DRS_COLORKEYENABLE state(which is d3d <= 3 only). The texture function will call alpha + * used WINED3D_RS_COLORKEYENABLE state(which is d3d <= 3 only). The texture function will call alpha * in case it finds some texture+colorkeyenable combination which needs extra care. */ - if (stateblock->state.textures[0]) + if (state->textures[0]) { - struct wined3d_texture *texture = stateblock->state.textures[0]; + struct wined3d_texture *texture = state->textures[0]; GLenum texture_dimensions = texture->target; if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB) @@ -453,11 +531,11 @@ static void state_alpha(DWORD state, struct wined3d_stateblock *stateblock, stru } if (enable_ckey || context->last_was_ckey) - stateblock_apply_state(STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), stateblock, context); + context_apply_state(context, state, STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP)); context->last_was_ckey = enable_ckey; - if (stateblock->state.render_states[WINED3DRS_ALPHATESTENABLE] - || (stateblock->state.render_states[WINED3DRS_COLORKEYENABLE] && enable_ckey)) + if (state->render_states[WINED3D_RS_ALPHATESTENABLE] + || (state->render_states[WINED3D_RS_COLORKEYENABLE] && enable_ckey)) { glEnable(GL_ALPHA_TEST); checkGLcall("glEnable GL_ALPHA_TEST"); @@ -470,13 +548,15 @@ static void state_alpha(DWORD state, struct wined3d_stateblock *stateblock, stru return; } - if (stateblock->state.render_states[WINED3DRS_COLORKEYENABLE] && enable_ckey) + if (state->render_states[WINED3D_RS_COLORKEYENABLE] && enable_ckey) { glParm = GL_NOTEQUAL; ref = 0.0f; - } else { - ref = ((float)stateblock->state.render_states[WINED3DRS_ALPHAREF]) / 255.0f; - glParm = CompareFunc(stateblock->state.render_states[WINED3DRS_ALPHAFUNC]); + } + else + { + ref = ((float)state->render_states[WINED3D_RS_ALPHAREF]) / 255.0f; + glParm = gl_compare_func(state->render_states[WINED3D_RS_ALPHAFUNC]); } if(glParm) { glAlphaFunc(glParm, ref); @@ -484,29 +564,54 @@ static void state_alpha(DWORD state, struct wined3d_stateblock *stateblock, stru } } -static void state_clipping(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void shaderconstant(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) +{ + const struct wined3d_device *device = context->swapchain->device; + + /* Vertex and pixel shader states will call a shader upload, don't do + * anything as long one of them has an update pending. */ + if (isStateDirty(context, STATE_VDECL) + || isStateDirty(context, STATE_PIXELSHADER)) + return; + + device->shader_backend->shader_load_constants(context, use_ps(state), use_vs(state)); +} + +static void state_clipping(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - const struct wined3d_gl_info *gl_info = context->gl_info; - const struct wined3d_state *state = &stateblock->state; DWORD enable = 0xFFFFFFFF; DWORD disable = 0x00000000; - if (!stateblock->device->vs_clipping && use_vs(state)) + if (use_vs(state)) { - /* The spec says that opengl clipping planes are disabled when using shaders. Direct3D planes aren't, - * so that is an issue. The MacOS ATI driver keeps clipping planes activated with shaders in some - * conditions I got sick of tracking down. The shader state handler disables all clip planes because - * of that - don't do anything here and keep them disabled - */ - if (state->render_states[WINED3DRS_CLIPPLANEENABLE]) + const struct wined3d_device *device = context->swapchain->device; + + if (!device->vs_clipping) { - static BOOL warned = FALSE; - if(!warned) { - FIXME("Clipping not supported with vertex shaders\n"); - warned = TRUE; + /* The spec says that opengl clipping planes are disabled when using shaders. Direct3D planes aren't, + * so that is an issue. The MacOS ATI driver keeps clipping planes activated with shaders in some + * conditions I got sick of tracking down. The shader state handler disables all clip planes because + * of that - don't do anything here and keep them disabled + */ + if (state->render_states[WINED3D_RS_CLIPPLANEENABLE]) + { + static BOOL warned = FALSE; + if(!warned) { + FIXME("Clipping not supported with vertex shaders\n"); + warned = TRUE; + } } + return; + } + + /* glEnable(GL_CLIP_PLANEx) doesn't apply to vertex shaders. The enabled / disabled planes are + * hardcoded into the shader. Update the shader to update the enabled clipplanes */ + if (!isStateDirty(context, context->state_table[STATE_VSHADER].representative)) + { + device->shader_backend->shader_select(context, use_ps(state), TRUE); + if (!isStateDirty(context, STATE_VERTEXSHADERCONSTANT)) + shaderconstant(context, state, STATE_VERTEXSHADERCONSTANT); } - return; } /* TODO: Keep track of previously enabled clipplanes to avoid unnecessary resetting @@ -516,27 +621,15 @@ static void state_clipping(DWORD state_id, struct wined3d_stateblock *stateblock /* If enabling / disabling all * TODO: Is this correct? Doesn't D3DRS_CLIPPING disable clipping on the viewport frustrum? */ - if (state->render_states[WINED3DRS_CLIPPING]) + if (state->render_states[WINED3D_RS_CLIPPING]) + { + enable = state->render_states[WINED3D_RS_CLIPPLANEENABLE]; + disable = ~state->render_states[WINED3D_RS_CLIPPLANEENABLE]; + } + else { - enable = state->render_states[WINED3DRS_CLIPPLANEENABLE]; - disable = ~state->render_states[WINED3DRS_CLIPPLANEENABLE]; - if (gl_info->supported[ARB_DEPTH_CLAMP]) - { - glDisable(GL_DEPTH_CLAMP); - checkGLcall("glDisable(GL_DEPTH_CLAMP)"); - } - } else { disable = 0xffffffff; enable = 0x00; - if (gl_info->supported[ARB_DEPTH_CLAMP]) - { - glEnable(GL_DEPTH_CLAMP); - checkGLcall("glEnable(GL_DEPTH_CLAMP)"); - } - else - { - FIXME("Clipping disabled, but ARB_depth_clamp isn't supported.\n"); - } } if (enable & WINED3DCLIPPLANE0) { glEnable(GL_CLIP_PLANE0); checkGLcall("glEnable(clip plane 0)"); } @@ -552,75 +645,9 @@ static void state_clipping(DWORD state_id, struct wined3d_stateblock *stateblock if (disable & WINED3DCLIPPLANE3) { glDisable(GL_CLIP_PLANE3); checkGLcall("glDisable(clip plane 3)"); } if (disable & WINED3DCLIPPLANE4) { glDisable(GL_CLIP_PLANE4); checkGLcall("glDisable(clip plane 4)"); } if (disable & WINED3DCLIPPLANE5) { glDisable(GL_CLIP_PLANE5); checkGLcall("glDisable(clip plane 5)"); } - - /** update clipping status */ - if (enable) - { - stateblock->state.clip_status.ClipUnion = 0; - stateblock->state.clip_status.ClipIntersection = 0xFFFFFFFF; - } - else - { - stateblock->state.clip_status.ClipUnion = 0; - stateblock->state.clip_status.ClipIntersection = 0; - } } -static void state_blendop_w(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) -{ - WARN("Unsupported in local OpenGL implementation: glBlendEquation\n"); -} - -static GLenum gl_blend_op(WINED3DBLENDOP op) -{ - switch (op) - { - case WINED3DBLENDOP_ADD: - return GL_FUNC_ADD_EXT; - case WINED3DBLENDOP_SUBTRACT: - return GL_FUNC_SUBTRACT_EXT; - case WINED3DBLENDOP_REVSUBTRACT: - return GL_FUNC_REVERSE_SUBTRACT_EXT; - case WINED3DBLENDOP_MIN: - return GL_MIN_EXT; - case WINED3DBLENDOP_MAX: - return GL_MAX_EXT; - default: - FIXME("Unhandled blend op %#x.\n", op); - return GL_NONE; - } -} - -static void state_blendop(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) -{ - const struct wined3d_gl_info *gl_info = context->gl_info; - int blendEquation = GL_FUNC_ADD_EXT; - int blendEquationAlpha = GL_FUNC_ADD_EXT; - - /* BLENDOPALPHA requires GL_EXT_blend_equation_separate, so make sure it is around */ - if (stateblock->state.render_states[WINED3DRS_BLENDOPALPHA] - && !gl_info->supported[EXT_BLEND_EQUATION_SEPARATE]) - { - WARN("Unsupported in local OpenGL implementation: glBlendEquationSeparateEXT\n"); - return; - } - - blendEquation = gl_blend_op(stateblock->state.render_states[WINED3DRS_BLENDOP]); - blendEquationAlpha = gl_blend_op(stateblock->state.render_states[WINED3DRS_BLENDOPALPHA]); - - if (stateblock->state.render_states[WINED3DRS_SEPARATEALPHABLENDENABLE]) - { - TRACE("glBlendEquationSeparateEXT(%x, %x)\n", blendEquation, blendEquationAlpha); - GL_EXTCALL(glBlendEquationSeparateEXT(blendEquation, blendEquationAlpha)); - checkGLcall("glBlendEquationSeparateEXT"); - } else { - TRACE("glBlendEquation(%x)\n", blendEquation); - GL_EXTCALL(glBlendEquationEXT(blendEquation)); - checkGLcall("glBlendEquation"); - } -} - -static void state_specularenable(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_specularenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { const struct wined3d_gl_info *gl_info = context->gl_info; /* Originally this used glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR) @@ -650,16 +677,16 @@ static void state_specularenable(DWORD state, struct wined3d_stateblock *statebl * * That's pretty much fine as it is, except for variable B, which needs to take * either GL_SPARE0_PLUS_SECONDARY_COLOR_NV or GL_SPARE0_NV, depending on - * whether WINED3DRS_SPECULARENABLE is enabled or not. + * whether WINED3D_RS_SPECULARENABLE is enabled or not. */ TRACE("Setting specular enable state and materials\n"); - if (stateblock->state.render_states[WINED3DRS_SPECULARENABLE]) + if (state->render_states[WINED3D_RS_SPECULARENABLE]) { - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float *)&stateblock->state.material.Specular); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float *)&state->material.specular); checkGLcall("glMaterialfv"); - if (stateblock->state.material.Power > gl_info->limits.shininess) + if (state->material.power > gl_info->limits.shininess) { /* glMaterialf man page says that the material says that GL_SHININESS must be between 0.0 * and 128.0, although in d3d neither -1 nor 129 produce an error. GL_NV_max_light_exponent @@ -667,12 +694,12 @@ static void state_specularenable(DWORD state, struct wined3d_stateblock *statebl * value reported by the extension, otherwise 128. For values > gl_info->limits.shininess clamp * them, it should be safe to do so without major visual distortions. */ - WARN("Material power = %f, limit %f\n", stateblock->state.material.Power, gl_info->limits.shininess); + WARN("Material power = %.8e, limit %.8e\n", state->material.power, gl_info->limits.shininess); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, gl_info->limits.shininess); } else { - glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, stateblock->state.material.Power); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, state->material.power); } checkGLcall("glMaterialf(GL_SHININESS)"); @@ -716,46 +743,43 @@ static void state_specularenable(DWORD state, struct wined3d_stateblock *statebl } } - TRACE("(%p) : Diffuse {%.8e, %.8e, %.8e, %.8e}\n", stateblock->device, - stateblock->state.material.Diffuse.r, stateblock->state.material.Diffuse.g, - stateblock->state.material.Diffuse.b, stateblock->state.material.Diffuse.a); - TRACE("(%p) : Ambient {%.8e, %.8e, %.8e, %.8e}\n", stateblock->device, - stateblock->state.material.Ambient.r, stateblock->state.material.Ambient.g, - stateblock->state.material.Ambient.b, stateblock->state.material.Ambient.a); - TRACE("(%p) : Specular {%.8e, %.8e, %.8e, %.8e}\n", stateblock->device, - stateblock->state.material.Specular.r, stateblock->state.material.Specular.g, - stateblock->state.material.Specular.b, stateblock->state.material.Specular.a); - TRACE("(%p) : Emissive {%.8e, %.8e, %.8e, %.8e}\n", stateblock->device, - stateblock->state.material.Emissive.r, stateblock->state.material.Emissive.g, - stateblock->state.material.Emissive.b, stateblock->state.material.Emissive.a); + TRACE("diffuse {%.8e, %.8e, %.8e, %.8e}\n", + state->material.diffuse.r, state->material.diffuse.g, + state->material.diffuse.b, state->material.diffuse.a); + TRACE("ambient {%.8e, %.8e, %.8e, %.8e}\n", + state->material.ambient.r, state->material.ambient.g, + state->material.ambient.b, state->material.ambient.a); + TRACE("specular {%.8e, %.8e, %.8e, %.8e}\n", + state->material.specular.r, state->material.specular.g, + state->material.specular.b, state->material.specular.a); + TRACE("emissive {%.8e, %.8e, %.8e, %.8e}\n", + state->material.emissive.r, state->material.emissive.g, + state->material.emissive.b, state->material.emissive.a); - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&stateblock->state.material.Ambient); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.ambient); checkGLcall("glMaterialfv(GL_AMBIENT)"); - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&stateblock->state.material.Diffuse); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.diffuse); checkGLcall("glMaterialfv(GL_DIFFUSE)"); - glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float *)&stateblock->state.material.Emissive); + glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float *)&state->material.emissive); checkGLcall("glMaterialfv(GL_EMISSION)"); } -static void state_texfactor(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_texfactor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { const struct wined3d_gl_info *gl_info = context->gl_info; unsigned int i; /* Note the texture color applies to all textures whereas - * GL_TEXTURE_ENV_COLOR applies to active only - */ + * GL_TEXTURE_ENV_COLOR applies to active only. */ float col[4]; - D3DCOLORTOGLFLOAT4(stateblock->state.render_states[WINED3DRS_TEXTUREFACTOR], col); + D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_TEXTUREFACTOR], col); /* And now the default texture color as well */ for (i = 0; i < gl_info->limits.texture_stages; ++i) { - /* Note the WINED3DRS value applies to all textures, but GL has one - * per texture, so apply it now ready to be used! - */ - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i)); - checkGLcall("glActiveTextureARB"); + /* Note the WINED3D_RS value applies to all textures, but GL has one + * per texture, so apply it now ready to be used! */ + context_active_texture(context, gl_info, i); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &col[0]); checkGLcall("glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);"); @@ -777,7 +801,33 @@ static void renderstate_stencil_twosided(struct wined3d_context *context, GLint checkGLcall("glStencilOp(...)"); } -static void state_stencil(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static GLenum gl_stencil_op(enum wined3d_stencil_op op) +{ + switch (op) + { + case WINED3D_STENCIL_OP_KEEP: + return GL_KEEP; + case WINED3D_STENCIL_OP_ZERO: + return GL_ZERO; + case WINED3D_STENCIL_OP_REPLACE: + return GL_REPLACE; + case WINED3D_STENCIL_OP_INCR_SAT: + return GL_INCR; + case WINED3D_STENCIL_OP_DECR_SAT: + return GL_DECR; + case WINED3D_STENCIL_OP_INVERT: + return GL_INVERT; + case WINED3D_STENCIL_OP_INCR: + return GL_INCR_WRAP_EXT; + case WINED3D_STENCIL_OP_DECR: + return GL_DECR_WRAP_EXT; + default: + FIXME("Unrecognized stencil op %#x.\n", op); + return GL_KEEP; + } +} + +static void state_stencil(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { const struct wined3d_gl_info *gl_info = context->gl_info; DWORD onesided_enable = FALSE; @@ -794,27 +844,27 @@ static void state_stencil(DWORD state, struct wined3d_stateblock *stateblock, st GLint stencilPass_ccw = GL_KEEP; /* No stencil test without a stencil buffer. */ - if (!stateblock->device->fb.depth_stencil) + if (!state->fb->depth_stencil) { glDisable(GL_STENCIL_TEST); checkGLcall("glDisable GL_STENCIL_TEST"); return; } - onesided_enable = stateblock->state.render_states[WINED3DRS_STENCILENABLE]; - twosided_enable = stateblock->state.render_states[WINED3DRS_TWOSIDEDSTENCILMODE]; - if (!(func = CompareFunc(stateblock->state.render_states[WINED3DRS_STENCILFUNC]))) + onesided_enable = state->render_states[WINED3D_RS_STENCILENABLE]; + twosided_enable = state->render_states[WINED3D_RS_TWOSIDEDSTENCILMODE]; + if (!(func = gl_compare_func(state->render_states[WINED3D_RS_STENCILFUNC]))) func = GL_ALWAYS; - if (!(func_ccw = CompareFunc(stateblock->state.render_states[WINED3DRS_CCW_STENCILFUNC]))) + if (!(func_ccw = gl_compare_func(state->render_states[WINED3D_RS_CCW_STENCILFUNC]))) func_ccw = GL_ALWAYS; - ref = stateblock->state.render_states[WINED3DRS_STENCILREF]; - mask = stateblock->state.render_states[WINED3DRS_STENCILMASK]; - stencilFail = StencilOp(stateblock->state.render_states[WINED3DRS_STENCILFAIL]); - depthFail = StencilOp(stateblock->state.render_states[WINED3DRS_STENCILZFAIL]); - stencilPass = StencilOp(stateblock->state.render_states[WINED3DRS_STENCILPASS]); - stencilFail_ccw = StencilOp(stateblock->state.render_states[WINED3DRS_CCW_STENCILFAIL]); - depthFail_ccw = StencilOp(stateblock->state.render_states[WINED3DRS_CCW_STENCILZFAIL]); - stencilPass_ccw = StencilOp(stateblock->state.render_states[WINED3DRS_CCW_STENCILPASS]); + ref = state->render_states[WINED3D_RS_STENCILREF]; + mask = state->render_states[WINED3D_RS_STENCILMASK]; + stencilFail = gl_stencil_op(state->render_states[WINED3D_RS_STENCILFAIL]); + depthFail = gl_stencil_op(state->render_states[WINED3D_RS_STENCILZFAIL]); + stencilPass = gl_stencil_op(state->render_states[WINED3D_RS_STENCILPASS]); + stencilFail_ccw = gl_stencil_op(state->render_states[WINED3D_RS_CCW_STENCILFAIL]); + depthFail_ccw = gl_stencil_op(state->render_states[WINED3D_RS_CCW_STENCILZFAIL]); + stencilPass_ccw = gl_stencil_op(state->render_states[WINED3D_RS_CCW_STENCILPASS]); TRACE("(onesided %d, twosided %d, ref %x, mask %x, " "GL_FRONT: func: %x, fail %x, zfail %x, zpass %x " @@ -875,9 +925,9 @@ static void state_stencil(DWORD state, struct wined3d_stateblock *stateblock, st } } -static void state_stencilwrite2s(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_stencilwrite2s(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - DWORD mask = stateblock->device->fb.depth_stencil ? stateblock->state.render_states[WINED3DRS_STENCILWRITEMASK] : 0; + DWORD mask = state->fb->depth_stencil ? state->render_states[WINED3D_RS_STENCILWRITEMASK] : 0; const struct wined3d_gl_info *gl_info = context->gl_info; GL_EXTCALL(glActiveStencilFaceEXT(GL_BACK)); @@ -889,23 +939,25 @@ static void state_stencilwrite2s(DWORD state, struct wined3d_stateblock *statebl glStencilMask(mask); } -static void state_stencilwrite(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_stencilwrite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - DWORD mask = stateblock->device->fb.depth_stencil ? stateblock->state.render_states[WINED3DRS_STENCILWRITEMASK] : 0; + DWORD mask = state->fb->depth_stencil ? state->render_states[WINED3D_RS_STENCILWRITEMASK] : 0; glStencilMask(mask); checkGLcall("glStencilMask"); } -static void state_fog_vertexpart(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_fog_vertexpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - TRACE("state %#x, stateblock %p, context %p\n", state, stateblock, context); + const struct wined3d_gl_info *gl_info = context->gl_info; + TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id); - if (!stateblock->state.render_states[WINED3DRS_FOGENABLE]) return; + if (!state->render_states[WINED3D_RS_FOGENABLE]) + return; /* Table fog on: Never use fog coords, and use per-fragment fog */ - if (stateblock->state.render_states[WINED3DRS_FOGTABLEMODE] != WINED3DFOG_NONE) + if (state->render_states[WINED3D_RS_FOGTABLEMODE] != WINED3D_FOG_NONE) { glHint(GL_FOG_HINT, GL_NICEST); if(context->fog_coord) { @@ -913,13 +965,20 @@ static void state_fog_vertexpart(DWORD state, struct wined3d_stateblock *statebl checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)"); context->fog_coord = FALSE; } + + /* Range fog is only used with per-vertex fog in d3d */ + if (gl_info->supported[NV_FOG_DISTANCE]) + { + glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV); + checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV)"); + } return; } /* Otherwise use per-vertex fog in any case */ glHint(GL_FOG_HINT, GL_FASTEST); - if (stateblock->state.render_states[WINED3DRS_FOGVERTEXMODE] == WINED3DFOG_NONE || context->last_was_rhw) + if (state->render_states[WINED3D_RS_FOGVERTEXMODE] == WINED3D_FOG_NONE || context->last_was_rhw) { /* No fog at all, or transformed vertices: Use fog coord */ if(!context->fog_coord) { @@ -927,17 +986,37 @@ static void state_fog_vertexpart(DWORD state, struct wined3d_stateblock *statebl checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT)"); context->fog_coord = TRUE; } - } else { + } + else + { /* Otherwise, use the fragment depth */ if(context->fog_coord) { glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT); checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)"); context->fog_coord = FALSE; } + + if (state->render_states[WINED3D_RS_RANGEFOGENABLE]) + { + if (gl_info->supported[NV_FOG_DISTANCE]) + { + glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV); + checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV)"); + } + else + { + WARN("Range fog enabled, but not supported by this GL implementation.\n"); + } + } + else if (gl_info->supported[NV_FOG_DISTANCE]) + { + glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV); + checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV)"); + } } } -void state_fogstartend(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +void state_fogstartend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { float fogstart, fogend; union { @@ -957,13 +1036,13 @@ void state_fogstartend(DWORD state, struct wined3d_stateblock *stateblock, struc break; case FOGSOURCE_FFP: - tmpvalue.d = stateblock->state.render_states[WINED3DRS_FOGSTART]; + tmpvalue.d = state->render_states[WINED3D_RS_FOGSTART]; fogstart = tmpvalue.f; - tmpvalue.d = stateblock->state.render_states[WINED3DRS_FOGEND]; + tmpvalue.d = state->render_states[WINED3D_RS_FOGEND]; fogend = tmpvalue.f; /* In GL, fogstart == fogend disables fog, in D3D everything's fogged.*/ if(fogstart == fogend) { - fogstart = -INFINITY; + fogstart = -1.0f / 0.0f; fogend = 0.0f; } break; @@ -986,14 +1065,13 @@ void state_fogstartend(DWORD state, struct wined3d_stateblock *stateblock, struc TRACE("Fog End == %f\n", fogend); } -void state_fog_fragpart(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +void state_fog_fragpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - const struct wined3d_state *state = &stateblock->state; enum fogsource new_source; - TRACE("state_id %#x, stateblock %p, context %p\n", state_id, stateblock, context); + TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id); - if (!state->render_states[WINED3DRS_FOGENABLE]) + if (!state->render_states[WINED3D_RS_FOGENABLE]) { /* No fog? Disable it, and we're done :-) */ glDisableWINE(GL_FOG); @@ -1047,7 +1125,7 @@ void state_fog_fragpart(DWORD state_id, struct wined3d_stateblock *stateblock, s /* DX 7 sdk: "If both render states(vertex and table fog) are set to valid modes, * the system will apply only pixel(=table) fog effects." */ - if (state->render_states[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) + if (state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE) { if (use_vs(state)) { @@ -1057,11 +1135,12 @@ void state_fog_fragpart(DWORD state_id, struct wined3d_stateblock *stateblock, s } else { - switch (state->render_states[WINED3DRS_FOGVERTEXMODE]) + switch (state->render_states[WINED3D_RS_FOGVERTEXMODE]) { /* If processed vertices are used, fall through to the NONE case */ - case WINED3DFOG_EXP: - if(!context->last_was_rhw) { + case WINED3D_FOG_EXP: + if (!context->last_was_rhw) + { glFogi(GL_FOG_MODE, GL_EXP); checkGLcall("glFogi(GL_FOG_MODE, GL_EXP)"); new_source = FOGSOURCE_FFP; @@ -1069,8 +1148,9 @@ void state_fog_fragpart(DWORD state_id, struct wined3d_stateblock *stateblock, s } /* drop through */ - case WINED3DFOG_EXP2: - if(!context->last_was_rhw) { + case WINED3D_FOG_EXP2: + if (!context->last_was_rhw) + { glFogi(GL_FOG_MODE, GL_EXP2); checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2)"); new_source = FOGSOURCE_FFP; @@ -1078,8 +1158,9 @@ void state_fog_fragpart(DWORD state_id, struct wined3d_stateblock *stateblock, s } /* drop through */ - case WINED3DFOG_LINEAR: - if(!context->last_was_rhw) { + case WINED3D_FOG_LINEAR: + if (!context->last_was_rhw) + { glFogi(GL_FOG_MODE, GL_LINEAR); checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)"); new_source = FOGSOURCE_FFP; @@ -1087,7 +1168,7 @@ void state_fog_fragpart(DWORD state_id, struct wined3d_stateblock *stateblock, s } /* drop through */ - case WINED3DFOG_NONE: + case WINED3D_FOG_NONE: /* Both are none? According to msdn the alpha channel of the specular * color contains a fog factor. Set it in drawStridedSlow. * Same happens with Vertexfog on transformed vertices @@ -1098,87 +1179,71 @@ void state_fog_fragpart(DWORD state_id, struct wined3d_stateblock *stateblock, s break; default: - FIXME("Unexpected WINED3DRS_FOGVERTEXMODE %#x.\n", - state->render_states[WINED3DRS_FOGVERTEXMODE]); + FIXME("Unexpected WINED3D_RS_FOGVERTEXMODE %#x.\n", + state->render_states[WINED3D_RS_FOGVERTEXMODE]); new_source = FOGSOURCE_FFP; /* Make the compiler happy */ } } } else { new_source = FOGSOURCE_FFP; - switch (state->render_states[WINED3DRS_FOGTABLEMODE]) + switch (state->render_states[WINED3D_RS_FOGTABLEMODE]) { - case WINED3DFOG_EXP: + case WINED3D_FOG_EXP: glFogi(GL_FOG_MODE, GL_EXP); checkGLcall("glFogi(GL_FOG_MODE, GL_EXP)"); break; - case WINED3DFOG_EXP2: + case WINED3D_FOG_EXP2: glFogi(GL_FOG_MODE, GL_EXP2); checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2)"); break; - case WINED3DFOG_LINEAR: + case WINED3D_FOG_LINEAR: glFogi(GL_FOG_MODE, GL_LINEAR); checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)"); break; - case WINED3DFOG_NONE: /* Won't happen */ + case WINED3D_FOG_NONE: /* Won't happen */ default: - FIXME("Unexpected WINED3DRS_FOGTABLEMODE %#x.\n", - state->render_states[WINED3DRS_FOGTABLEMODE]); + FIXME("Unexpected WINED3D_RS_FOGTABLEMODE %#x.\n", + state->render_states[WINED3D_RS_FOGTABLEMODE]); } } glEnableWINE(GL_FOG); checkGLcall("glEnable GL_FOG"); - if(new_source != context->fog_source) { - context->fog_source = new_source; - state_fogstartend(STATE_RENDER(WINED3DRS_FOGSTART), stateblock, context); - } -} - -static void state_rangefog_w(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) -{ - if (stateblock->state.render_states[WINED3DRS_RANGEFOGENABLE]) - WARN("Range fog enabled, but not supported by this opengl implementation\n"); -} - -static void state_rangefog(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) -{ - if (stateblock->state.render_states[WINED3DRS_RANGEFOGENABLE]) + if (new_source != context->fog_source) { - glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV); - checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV)"); - } else { - glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV); - checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV)"); + context->fog_source = new_source; + state_fogstartend(context, state, STATE_RENDER(WINED3D_RS_FOGSTART)); } } -void state_fogcolor(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +void state_fogcolor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { float col[4]; - D3DCOLORTOGLFLOAT4(stateblock->state.render_states[WINED3DRS_FOGCOLOR], col); + + D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_FOGCOLOR], col); glFogfv(GL_FOG_COLOR, &col[0]); checkGLcall("glFog GL_FOG_COLOR"); } -void state_fogdensity(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +void state_fogdensity(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { union { DWORD d; float f; } tmpvalue; - tmpvalue.d = stateblock->state.render_states[WINED3DRS_FOGDENSITY]; + + tmpvalue.d = state->render_states[WINED3D_RS_FOGDENSITY]; glFogfv(GL_FOG_DENSITY, &tmpvalue.f); checkGLcall("glFogf(GL_FOG_DENSITY, (float) Value)"); } -static void state_colormat(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_colormat(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - const struct wined3d_state *state = &stateblock->state; - struct wined3d_device *device = stateblock->device; + const struct wined3d_device *device = context->swapchain->device; GLenum Parm = 0; /* Depends on the decoded vertex declaration to read the existence of diffuse data. @@ -1191,55 +1256,55 @@ static void state_colormat(DWORD state_id, struct wined3d_stateblock *stateblock context->num_untracked_materials = 0; if ((device->strided_streams.use_map & (1 << WINED3D_FFP_DIFFUSE)) - && state->render_states[WINED3DRS_COLORVERTEX]) + && state->render_states[WINED3D_RS_COLORVERTEX]) { TRACE("diff %d, amb %d, emis %d, spec %d\n", - state->render_states[WINED3DRS_DIFFUSEMATERIALSOURCE], - state->render_states[WINED3DRS_AMBIENTMATERIALSOURCE], - state->render_states[WINED3DRS_EMISSIVEMATERIALSOURCE], - state->render_states[WINED3DRS_SPECULARMATERIALSOURCE]); + state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE], + state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE], + state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE], + state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE]); - if (state->render_states[WINED3DRS_DIFFUSEMATERIALSOURCE] == WINED3DMCS_COLOR1) + if (state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE] == WINED3D_MCS_COLOR1) { - if (state->render_states[WINED3DRS_AMBIENTMATERIALSOURCE] == WINED3DMCS_COLOR1) + if (state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE] == WINED3D_MCS_COLOR1) Parm = GL_AMBIENT_AND_DIFFUSE; else Parm = GL_DIFFUSE; - if (state->render_states[WINED3DRS_EMISSIVEMATERIALSOURCE] == WINED3DMCS_COLOR1) + if (state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] == WINED3D_MCS_COLOR1) { context->untracked_materials[context->num_untracked_materials] = GL_EMISSION; context->num_untracked_materials++; } - if (state->render_states[WINED3DRS_SPECULARMATERIALSOURCE] == WINED3DMCS_COLOR1) + if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1) { context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR; context->num_untracked_materials++; } } - else if (state->render_states[WINED3DRS_AMBIENTMATERIALSOURCE] == WINED3DMCS_COLOR1) + else if (state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE] == WINED3D_MCS_COLOR1) { Parm = GL_AMBIENT; - if (state->render_states[WINED3DRS_EMISSIVEMATERIALSOURCE] == WINED3DMCS_COLOR1) + if (state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] == WINED3D_MCS_COLOR1) { context->untracked_materials[context->num_untracked_materials] = GL_EMISSION; context->num_untracked_materials++; } - if (state->render_states[WINED3DRS_SPECULARMATERIALSOURCE] == WINED3DMCS_COLOR1) + if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1) { context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR; context->num_untracked_materials++; } } - else if (state->render_states[WINED3DRS_EMISSIVEMATERIALSOURCE] == WINED3DMCS_COLOR1) + else if (state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] == WINED3D_MCS_COLOR1) { Parm = GL_EMISSION; - if (state->render_states[WINED3DRS_SPECULARMATERIALSOURCE] == WINED3DMCS_COLOR1) + if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1) { context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR; context->num_untracked_materials++; } } - else if (state->render_states[WINED3DRS_SPECULARMATERIALSOURCE] == WINED3DMCS_COLOR1) + else if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1) { Parm = GL_SPECULAR; } @@ -1262,33 +1327,35 @@ static void state_colormat(DWORD state_id, struct wined3d_stateblock *stateblock * tracking with glColorMaterial, so apply those here. */ switch (context->tracking_parm) { case GL_AMBIENT_AND_DIFFUSE: - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.Ambient); - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.Diffuse); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.ambient); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.diffuse); checkGLcall("glMaterialfv"); break; case GL_DIFFUSE: - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.Diffuse); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.diffuse); checkGLcall("glMaterialfv"); break; case GL_AMBIENT: - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.Ambient); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.ambient); checkGLcall("glMaterialfv"); break; case GL_EMISSION: - glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float *)&state->material.Emissive); + glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float *)&state->material.emissive); checkGLcall("glMaterialfv"); break; case GL_SPECULAR: /* Only change material color if specular is enabled, otherwise it is set to black */ - if (state->render_states[WINED3DRS_SPECULARENABLE]) + if (state->render_states[WINED3D_RS_SPECULARENABLE]) { - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float *)&state->material.Specular); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float *)&state->material.specular); checkGLcall("glMaterialfv"); - } else { + } + else + { static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 0.0f}; glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &black[0]); checkGLcall("glMaterialfv"); @@ -1299,68 +1366,74 @@ static void state_colormat(DWORD state_id, struct wined3d_stateblock *stateblock context->tracking_parm = Parm; } -static void state_linepattern(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_linepattern(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - union { - DWORD d; - WINED3DLINEPATTERN lp; + union + { + DWORD d; + struct wined3d_line_pattern lp; } tmppattern; - tmppattern.d = stateblock->state.render_states[WINED3DRS_LINEPATTERN]; + tmppattern.d = state->render_states[WINED3D_RS_LINEPATTERN]; - TRACE("Line pattern: repeat %d bits %x\n", tmppattern.lp.wRepeatFactor, tmppattern.lp.wLinePattern); + TRACE("Line pattern: repeat %d bits %x.\n", tmppattern.lp.repeat_factor, tmppattern.lp.line_pattern); - if (tmppattern.lp.wRepeatFactor) { - glLineStipple(tmppattern.lp.wRepeatFactor, tmppattern.lp.wLinePattern); + if (tmppattern.lp.repeat_factor) + { + glLineStipple(tmppattern.lp.repeat_factor, tmppattern.lp.line_pattern); checkGLcall("glLineStipple(repeat, linepattern)"); glEnable(GL_LINE_STIPPLE); checkGLcall("glEnable(GL_LINE_STIPPLE);"); - } else { + } + else + { glDisable(GL_LINE_STIPPLE); checkGLcall("glDisable(GL_LINE_STIPPLE);"); } } -static void state_normalize(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_normalize(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if(isStateDirty(context, STATE_VDECL)) { + if (isStateDirty(context, STATE_VDECL)) return; - } + /* Without vertex normals, we set the current normal to 0/0/0 to remove the diffuse factor * from the opengl lighting equation, as d3d does. Normalization of 0/0/0 can lead to a division * by zero and is not properly defined in opengl, so avoid it */ - if (stateblock->state.render_states[WINED3DRS_NORMALIZENORMALS] - && (stateblock->device->strided_streams.use_map & (1 << WINED3D_FFP_NORMAL))) + if (state->render_states[WINED3D_RS_NORMALIZENORMALS] + && (context->swapchain->device->strided_streams.use_map & (1 << WINED3D_FFP_NORMAL))) { glEnable(GL_NORMALIZE); checkGLcall("glEnable(GL_NORMALIZE);"); - } else { + } + else + { glDisable(GL_NORMALIZE); checkGLcall("glDisable(GL_NORMALIZE);"); } } -static void state_psizemin_w(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_psizemin_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { union { DWORD d; float f; } tmpvalue; - tmpvalue.d = stateblock->state.render_states[WINED3DRS_POINTSIZE_MIN]; + tmpvalue.d = state->render_states[WINED3D_RS_POINTSIZE_MIN]; if (tmpvalue.f != 1.0f) { - FIXME("WINED3DRS_POINTSIZE_MIN not supported on this opengl, value is %f\n", tmpvalue.f); + FIXME("WINED3D_RS_POINTSIZE_MIN not supported on this opengl, value is %f\n", tmpvalue.f); } - tmpvalue.d = stateblock->state.render_states[WINED3DRS_POINTSIZE_MAX]; + tmpvalue.d = state->render_states[WINED3D_RS_POINTSIZE_MAX]; if (tmpvalue.f != 64.0f) { - FIXME("WINED3DRS_POINTSIZE_MAX not supported on this opengl, value is %f\n", tmpvalue.f); + FIXME("WINED3D_RS_POINTSIZE_MAX not supported on this opengl, value is %f\n", tmpvalue.f); } } -static void state_psizemin_ext(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_psizemin_ext(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { const struct wined3d_gl_info *gl_info = context->gl_info; union @@ -1369,8 +1442,8 @@ static void state_psizemin_ext(DWORD state, struct wined3d_stateblock *statebloc float f; } min, max; - min.d = stateblock->state.render_states[WINED3DRS_POINTSIZE_MIN]; - max.d = stateblock->state.render_states[WINED3DRS_POINTSIZE_MAX]; + min.d = state->render_states[WINED3D_RS_POINTSIZE_MIN]; + max.d = state->render_states[WINED3D_RS_POINTSIZE_MAX]; /* Max point size trumps min point size */ if(min.f > max.f) { @@ -1383,7 +1456,7 @@ static void state_psizemin_ext(DWORD state, struct wined3d_stateblock *statebloc checkGLcall("glPointParameterfEXT(...)"); } -static void state_psizemin_arb(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_psizemin_arb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { const struct wined3d_gl_info *gl_info = context->gl_info; union @@ -1392,8 +1465,8 @@ static void state_psizemin_arb(DWORD state, struct wined3d_stateblock *statebloc float f; } min, max; - min.d = stateblock->state.render_states[WINED3DRS_POINTSIZE_MIN]; - max.d = stateblock->state.render_states[WINED3DRS_POINTSIZE_MAX]; + min.d = state->render_states[WINED3D_RS_POINTSIZE_MIN]; + max.d = state->render_states[WINED3D_RS_POINTSIZE_MAX]; /* Max point size trumps min point size */ if(min.f > max.f) { @@ -1406,7 +1479,7 @@ static void state_psizemin_arb(DWORD state, struct wined3d_stateblock *statebloc checkGLcall("glPointParameterfARB(...)"); } -static void state_pscale(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_pscale(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { const struct wined3d_gl_info *gl_info = context->gl_info; /* TODO: Group this with the viewport */ @@ -1423,15 +1496,15 @@ static void state_pscale(DWORD state, struct wined3d_stateblock *stateblock, str float f; } pointSize, A, B, C; - pointSize.d = stateblock->state.render_states[WINED3DRS_POINTSIZE]; - A.d = stateblock->state.render_states[WINED3DRS_POINTSCALE_A]; - B.d = stateblock->state.render_states[WINED3DRS_POINTSCALE_B]; - C.d = stateblock->state.render_states[WINED3DRS_POINTSCALE_C]; + pointSize.d = state->render_states[WINED3D_RS_POINTSIZE]; + A.d = state->render_states[WINED3D_RS_POINTSCALE_A]; + B.d = state->render_states[WINED3D_RS_POINTSCALE_B]; + C.d = state->render_states[WINED3D_RS_POINTSCALE_C]; - if (stateblock->state.render_states[WINED3DRS_POINTSCALEENABLE]) + if (state->render_states[WINED3D_RS_POINTSCALEENABLE]) { + DWORD h = state->viewport.height; GLfloat scaleFactor; - DWORD h = stateblock->state.viewport.Height; if (pointSize.f < gl_info->limits.pointsize_min) { @@ -1476,7 +1549,7 @@ static void state_pscale(DWORD state, struct wined3d_stateblock *stateblock, str GL_EXTCALL(glPointParameterfvEXT)(GL_DISTANCE_ATTENUATION_EXT, att); checkGLcall("glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, ...)"); } - else if(stateblock->state.render_states[WINED3DRS_POINTSCALEENABLE]) + else if (state->render_states[WINED3D_RS_POINTSCALEENABLE]) { WARN("POINT_PARAMETERS not supported in this version of opengl\n"); } @@ -1485,17 +1558,17 @@ static void state_pscale(DWORD state, struct wined3d_stateblock *stateblock, str checkGLcall("glPointSize(...);"); } -static void state_debug_monitor(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_debug_monitor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - WARN("token: %#x\n", stateblock->state.render_states[WINED3DRS_DEBUGMONITORTOKEN]); + WARN("token: %#x.\n", state->render_states[WINED3D_RS_DEBUGMONITORTOKEN]); } -static void state_colorwrite(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_colorwrite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - DWORD mask0 = stateblock->state.render_states[WINED3DRS_COLORWRITEENABLE]; - DWORD mask1 = stateblock->state.render_states[WINED3DRS_COLORWRITEENABLE1]; - DWORD mask2 = stateblock->state.render_states[WINED3DRS_COLORWRITEENABLE2]; - DWORD mask3 = stateblock->state.render_states[WINED3DRS_COLORWRITEENABLE3]; + DWORD mask0 = state->render_states[WINED3D_RS_COLORWRITEENABLE]; + DWORD mask1 = state->render_states[WINED3D_RS_COLORWRITEENABLE1]; + DWORD mask2 = state->render_states[WINED3D_RS_COLORWRITEENABLE2]; + DWORD mask3 = state->render_states[WINED3D_RS_COLORWRITEENABLE3]; TRACE("Color mask: r(%d) g(%d) b(%d) a(%d)\n", mask0 & WINED3DCOLORWRITEENABLE_RED ? 1 : 0, @@ -1511,7 +1584,7 @@ static void state_colorwrite(DWORD state, struct wined3d_stateblock *stateblock, if (!((mask1 == mask0 && mask2 == mask0 && mask3 == mask0) || (mask1 == 0xf && mask2 == 0xf && mask3 == 0xf))) { - FIXME("WINED3DRS_COLORWRITEENABLE/1/2/3, %#x/%#x/%#x/%#x not yet implemented.\n", + FIXME("WINED3D_RS_COLORWRITEENABLE/1/2/3, %#x/%#x/%#x/%#x not yet implemented.\n", mask0, mask1, mask2, mask3); FIXME("Missing of cap D3DPMISCCAPS_INDEPENDENTWRITEMASKS wasn't honored?\n"); } @@ -1526,29 +1599,29 @@ static void set_color_mask(const struct wined3d_gl_info *gl_info, UINT index, DW mask & WINED3DCOLORWRITEENABLE_ALPHA ? GL_TRUE : GL_FALSE)); } -static void state_colorwrite0(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_colorwrite0(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - set_color_mask(context->gl_info, 0, stateblock->state.render_states[WINED3DRS_COLORWRITEENABLE]); + set_color_mask(context->gl_info, 0, state->render_states[WINED3D_RS_COLORWRITEENABLE]); } -static void state_colorwrite1(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_colorwrite1(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - set_color_mask(context->gl_info, 1, stateblock->state.render_states[WINED3DRS_COLORWRITEENABLE1]); + set_color_mask(context->gl_info, 1, state->render_states[WINED3D_RS_COLORWRITEENABLE1]); } -static void state_colorwrite2(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_colorwrite2(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - set_color_mask(context->gl_info, 2, stateblock->state.render_states[WINED3DRS_COLORWRITEENABLE2]); + set_color_mask(context->gl_info, 2, state->render_states[WINED3D_RS_COLORWRITEENABLE2]); } -static void state_colorwrite3(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_colorwrite3(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - set_color_mask(context->gl_info, 3, stateblock->state.render_states[WINED3DRS_COLORWRITEENABLE3]); + set_color_mask(context->gl_info, 3, state->render_states[WINED3D_RS_COLORWRITEENABLE3]); } -static void state_localviewer(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_localviewer(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_LOCALVIEWER]) + if (state->render_states[WINED3D_RS_LOCALVIEWER]) { glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1)"); @@ -1558,12 +1631,14 @@ static void state_localviewer(DWORD state, struct wined3d_stateblock *stateblock } } -static void state_lastpixel(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_lastpixel(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_LASTPIXEL]) + if (state->render_states[WINED3D_RS_LASTPIXEL]) { TRACE("Last Pixel Drawing Enabled\n"); - } else { + } + else + { static BOOL warned; if (!warned) { FIXME("Last Pixel Drawing Disabled, not handled yet\n"); @@ -1574,12 +1649,12 @@ static void state_lastpixel(DWORD state, struct wined3d_stateblock *stateblock, } } -static void state_pointsprite_w(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_pointsprite_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { static BOOL warned; /* TODO: NV_POINT_SPRITE */ - if (!warned && stateblock->state.render_states[WINED3DRS_POINTSPRITEENABLE]) + if (!warned && state->render_states[WINED3D_RS_POINTSPRITEENABLE]) { /* A FIXME, not a WARN because point sprites should be software emulated if not supported by HW */ FIXME("Point sprites not supported\n"); @@ -1587,24 +1662,10 @@ static void state_pointsprite_w(DWORD state, struct wined3d_stateblock *stateblo } } -static void state_pointsprite(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_pointsprite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - const struct wined3d_gl_info *gl_info = context->gl_info; - const struct wined3d_state *state = &stateblock->state; - - if (state->render_states[WINED3DRS_POINTSPRITEENABLE]) + if (state->render_states[WINED3D_RS_POINTSPRITEENABLE]) { - static BOOL warned; - - if (gl_info->limits.point_sprite_units < gl_info->limits.textures && !warned) - { - if (use_ps(state) || state->lowest_disabled_stage > gl_info->limits.point_sprite_units) - { - FIXME("The app uses point sprite texture coordinates on more units than supported by the driver\n"); - warned = TRUE; - } - } - glEnable(GL_POINT_SPRITE_ARB); checkGLcall("glEnable(GL_POINT_SPRITE_ARB)"); } else { @@ -1613,46 +1674,36 @@ static void state_pointsprite(DWORD state_id, struct wined3d_stateblock *statebl } } -static void state_wrap(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_wrap(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - /** - http://www.cosc.brocku.ca/Offerings/3P98/course/lectures/texture/ - http://www.gamedev.net/reference/programming/features/rendererdll3/page2.asp - Discussion on the ways to turn on WRAPing to solve an OpenGL conversion problem. - http://www.flipcode.org/cgi-bin/fcmsg.cgi?thread_show=10248 - - so far as I can tell, wrapping and texture-coordinate generate go hand in hand, - */ - if (stateblock->state.render_states[WINED3DRS_WRAP0] - || stateblock->state.render_states[WINED3DRS_WRAP1] - || stateblock->state.render_states[WINED3DRS_WRAP2] - || stateblock->state.render_states[WINED3DRS_WRAP3] - || stateblock->state.render_states[WINED3DRS_WRAP4] - || stateblock->state.render_states[WINED3DRS_WRAP5] - || stateblock->state.render_states[WINED3DRS_WRAP6] - || stateblock->state.render_states[WINED3DRS_WRAP7] - || stateblock->state.render_states[WINED3DRS_WRAP8] - || stateblock->state.render_states[WINED3DRS_WRAP9] - || stateblock->state.render_states[WINED3DRS_WRAP10] - || stateblock->state.render_states[WINED3DRS_WRAP11] - || stateblock->state.render_states[WINED3DRS_WRAP12] - || stateblock->state.render_states[WINED3DRS_WRAP13] - || stateblock->state.render_states[WINED3DRS_WRAP14] - || stateblock->state.render_states[WINED3DRS_WRAP15]) - { - FIXME("(WINED3DRS_WRAP0) Texture wrapping not yet supported.\n"); - } + if (state->render_states[WINED3D_RS_WRAP0] + || state->render_states[WINED3D_RS_WRAP1] + || state->render_states[WINED3D_RS_WRAP2] + || state->render_states[WINED3D_RS_WRAP3] + || state->render_states[WINED3D_RS_WRAP4] + || state->render_states[WINED3D_RS_WRAP5] + || state->render_states[WINED3D_RS_WRAP6] + || state->render_states[WINED3D_RS_WRAP7] + || state->render_states[WINED3D_RS_WRAP8] + || state->render_states[WINED3D_RS_WRAP9] + || state->render_states[WINED3D_RS_WRAP10] + || state->render_states[WINED3D_RS_WRAP11] + || state->render_states[WINED3D_RS_WRAP12] + || state->render_states[WINED3D_RS_WRAP13] + || state->render_states[WINED3D_RS_WRAP14] + || state->render_states[WINED3D_RS_WRAP15]) + FIXME("(WINED3D_RS_WRAP0) Texture wrapping not yet supported.\n"); } -static void state_msaa_w(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_msaa_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_MULTISAMPLEANTIALIAS]) - WARN("Multisample antialiasing not supported by gl\n"); + if (state->render_states[WINED3D_RS_MULTISAMPLEANTIALIAS]) + WARN("Multisample antialiasing not supported by GL.\n"); } -static void state_msaa(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_msaa(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_MULTISAMPLEANTIALIAS]) + if (state->render_states[WINED3D_RS_MULTISAMPLEANTIALIAS]) { glEnable(GL_MULTISAMPLE_ARB); checkGLcall("glEnable(GL_MULTISAMPLE_ARB)"); @@ -1662,9 +1713,9 @@ static void state_msaa(DWORD state, struct wined3d_stateblock *stateblock, struc } } -static void state_scissor(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_scissor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_SCISSORTESTENABLE]) + if (state->render_states[WINED3D_RS_SCISSORTESTENABLE]) { glEnable(GL_SCISSOR_TEST); checkGLcall("glEnable(GL_SCISSOR_TEST)"); @@ -1683,12 +1734,12 @@ static void state_scissor(DWORD state, struct wined3d_stateblock *stateblock, st * which makes a guess of the depth buffer format's highest possible value a * reasonable guess. Note that SLOPESCALEDEPTHBIAS is a scaling factor for the * depth slope, and doesn't need to be scaled. */ -static void state_depthbias(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_depthbias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_SLOPESCALEDEPTHBIAS] - || stateblock->state.render_states[WINED3DRS_DEPTHBIAS]) + if (state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS] + || state->render_states[WINED3D_RS_DEPTHBIAS]) { - struct wined3d_surface *depth = stateblock->device->fb.depth_stencil; + const struct wined3d_surface *depth = state->fb->depth_stencil; float scale; union @@ -1697,43 +1748,54 @@ static void state_depthbias(DWORD state, struct wined3d_stateblock *stateblock, float f; } scale_bias, const_bias; - scale_bias.d = stateblock->state.render_states[WINED3DRS_SLOPESCALEDEPTHBIAS]; - const_bias.d = stateblock->state.render_states[WINED3DRS_DEPTHBIAS]; + scale_bias.d = state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS]; + const_bias.d = state->render_states[WINED3D_RS_DEPTHBIAS]; glEnable(GL_POLYGON_OFFSET_FILL); checkGLcall("glEnable(GL_POLYGON_OFFSET_FILL)"); - if (depth) + if (context->swapchain->device->wined3d->flags & WINED3D_LEGACY_DEPTH_BIAS) { - const struct wined3d_format *fmt = depth->resource.format; - scale = powf(2, fmt->depth_size) - 1; - TRACE("Depth format %s, using depthbias scale of %f\n", - debug_d3dformat(fmt->id), scale); + float bias = -(float)const_bias.d; + glPolygonOffset(bias, bias); + checkGLcall("glPolygonOffset"); } else { - /* The context manager will reapply this state on a depth stencil change */ - TRACE("No depth stencil, using depthbias scale of 0.0\n"); - scale = 0; - } + if (depth) + { + const struct wined3d_format *fmt = depth->resource.format; + scale = powf(2, fmt->depth_size) - 1; + TRACE("Depth format %s, using depthbias scale of %.8e.\n", + debug_d3dformat(fmt->id), scale); + } + else + { + /* The context manager will reapply this state on a depth stencil change */ + TRACE("No depth stencil, using depthbias scale of 0.0.\n"); + scale = 0.0f; + } - glPolygonOffset(scale_bias.f, const_bias.f * scale); - checkGLcall("glPolygonOffset(...)"); - } else { + glPolygonOffset(scale_bias.f, const_bias.f * scale); + checkGLcall("glPolygonOffset(...)"); + } + } + else + { glDisable(GL_POLYGON_OFFSET_FILL); checkGLcall("glDisable(GL_POLYGON_OFFSET_FILL)"); } } -static void state_zvisible(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_zvisible(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_ZVISIBLE]) - FIXME("WINED3DRS_ZVISIBLE not implemented.\n"); + if (state->render_states[WINED3D_RS_ZVISIBLE]) + FIXME("WINED3D_RS_ZVISIBLE not implemented.\n"); } -static void state_perspective(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_perspective(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_TEXTUREPERSPECTIVE]) + if (state->render_states[WINED3D_RS_TEXTUREPERSPECTIVE]) { glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); checkGLcall("glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)"); @@ -1743,33 +1805,33 @@ static void state_perspective(DWORD state, struct wined3d_stateblock *stateblock } } -static void state_stippledalpha(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_stippledalpha(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_STIPPLEDALPHA]) - FIXME(" Stippled Alpha not supported yet.\n"); + if (state->render_states[WINED3D_RS_STIPPLEDALPHA]) + FIXME("Stippled Alpha not supported yet.\n"); } -static void state_antialias(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_antialias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_ANTIALIAS]) + if (state->render_states[WINED3D_RS_ANTIALIAS]) FIXME("Antialias not supported yet.\n"); } -static void state_multisampmask(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_multisampmask(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_MULTISAMPLEMASK] != 0xffffffff) - FIXME("WINED3DRS_MULTISAMPLEMASK %#x not yet implemented.\n", - stateblock->state.render_states[WINED3DRS_MULTISAMPLEMASK]); + if (state->render_states[WINED3D_RS_MULTISAMPLEMASK] != 0xffffffff) + FIXME("WINED3D_RS_MULTISAMPLEMASK %#x not yet implemented.\n", + state->render_states[WINED3D_RS_MULTISAMPLEMASK]); } -static void state_patchedgestyle(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_patchedgestyle(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_PATCHEDGESTYLE] != WINED3DPATCHEDGE_DISCRETE) - FIXME("WINED3DRS_PATCHEDGESTYLE %#x not yet implemented.\n", - stateblock->state.render_states[WINED3DRS_PATCHEDGESTYLE]); + if (state->render_states[WINED3D_RS_PATCHEDGESTYLE] != WINED3D_PATCH_EDGE_DISCRETE) + FIXME("WINED3D_RS_PATCHEDGESTYLE %#x not yet implemented.\n", + state->render_states[WINED3D_RS_PATCHEDGESTYLE]); } -static void state_patchsegments(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_patchsegments(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { union { DWORD d; @@ -1777,40 +1839,40 @@ static void state_patchsegments(DWORD state, struct wined3d_stateblock *stateblo } tmpvalue; tmpvalue.f = 1.0f; - if (stateblock->state.render_states[WINED3DRS_PATCHSEGMENTS] != tmpvalue.d) + if (state->render_states[WINED3D_RS_PATCHSEGMENTS] != tmpvalue.d) { static BOOL displayed = FALSE; - tmpvalue.d = stateblock->state.render_states[WINED3DRS_PATCHSEGMENTS]; + tmpvalue.d = state->render_states[WINED3D_RS_PATCHSEGMENTS]; if(!displayed) - FIXME("(WINED3DRS_PATCHSEGMENTS,%f) not yet implemented\n", tmpvalue.f); + FIXME("(WINED3D_RS_PATCHSEGMENTS,%f) not yet implemented\n", tmpvalue.f); displayed = TRUE; } } -static void state_positiondegree(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_positiondegree(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_POSITIONDEGREE] != WINED3DDEGREE_CUBIC) - FIXME("WINED3DRS_POSITIONDEGREE %#x not yet implemented.\n", - stateblock->state.render_states[WINED3DRS_POSITIONDEGREE]); + if (state->render_states[WINED3D_RS_POSITIONDEGREE] != WINED3D_DEGREE_CUBIC) + FIXME("WINED3D_RS_POSITIONDEGREE %#x not yet implemented.\n", + state->render_states[WINED3D_RS_POSITIONDEGREE]); } -static void state_normaldegree(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_normaldegree(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_NORMALDEGREE] != WINED3DDEGREE_LINEAR) - FIXME("WINED3DRS_NORMALDEGREE %#x not yet implemented.\n", - stateblock->state.render_states[WINED3DRS_NORMALDEGREE]); + if (state->render_states[WINED3D_RS_NORMALDEGREE] != WINED3D_DEGREE_LINEAR) + FIXME("WINED3D_RS_NORMALDEGREE %#x not yet implemented.\n", + state->render_states[WINED3D_RS_NORMALDEGREE]); } -static void state_tessellation(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_tessellation(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_ENABLEADAPTIVETESSELLATION]) - FIXME("WINED3DRS_ENABLEADAPTIVETESSELLATION %#x not yet implemented.\n", - stateblock->state.render_states[WINED3DRS_ENABLEADAPTIVETESSELLATION]); + if (state->render_states[WINED3D_RS_ENABLEADAPTIVETESSELLATION]) + FIXME("WINED3D_RS_ENABLEADAPTIVETESSELLATION %#x not yet implemented.\n", + state->render_states[WINED3D_RS_ENABLEADAPTIVETESSELLATION]); } -static void state_nvdb(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_nvdb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { union { DWORD d; @@ -1819,10 +1881,10 @@ static void state_nvdb(DWORD state, struct wined3d_stateblock *stateblock, struc const struct wined3d_gl_info *gl_info = context->gl_info; - if (stateblock->state.render_states[WINED3DRS_ADAPTIVETESS_X] == WINED3DFMT_NVDB) + if (state->render_states[WINED3D_RS_ADAPTIVETESS_X] == WINED3DFMT_NVDB) { - zmin.d = stateblock->state.render_states[WINED3DRS_ADAPTIVETESS_Z]; - zmax.d = stateblock->state.render_states[WINED3DRS_ADAPTIVETESS_W]; + zmin.d = state->render_states[WINED3D_RS_ADAPTIVETESS_Z]; + zmax.d = state->render_states[WINED3D_RS_ADAPTIVETESS_W]; /* If zmin is larger than zmax INVALID_VALUE error is generated. * In d3d9 test is not performed in this case*/ @@ -1843,108 +1905,99 @@ static void state_nvdb(DWORD state, struct wined3d_stateblock *stateblock, struc checkGLcall("glDisable(GL_DEPTH_BOUNDS_TEST_EXT)"); } - state_tessellation(state, stateblock, context); + state_tessellation(context, state, STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION)); } -static void state_wrapu(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_wrapu(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_WRAPU]) - FIXME("Render state WINED3DRS_WRAPU not implemented yet.\n"); + if (state->render_states[WINED3D_RS_WRAPU]) + FIXME("Render state WINED3D_RS_WRAPU not implemented yet.\n"); } -static void state_wrapv(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_wrapv(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_WRAPV]) - FIXME("Render state WINED3DRS_WRAPV not implemented yet.\n"); + if (state->render_states[WINED3D_RS_WRAPV]) + FIXME("Render state WINED3D_RS_WRAPV not implemented yet.\n"); } -static void state_monoenable(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_monoenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_MONOENABLE]) - FIXME("Render state WINED3DRS_MONOENABLE not implemented yet.\n"); + if (state->render_states[WINED3D_RS_MONOENABLE]) + FIXME("Render state WINED3D_RS_MONOENABLE not implemented yet.\n"); } -static void state_rop2(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_rop2(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_ROP2]) - FIXME("Render state WINED3DRS_ROP2 not implemented yet.\n"); + if (state->render_states[WINED3D_RS_ROP2]) + FIXME("Render state WINED3D_RS_ROP2 not implemented yet.\n"); } -static void state_planemask(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_planemask(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_PLANEMASK]) - FIXME("Render state WINED3DRS_PLANEMASK not implemented yet.\n"); + if (state->render_states[WINED3D_RS_PLANEMASK]) + FIXME("Render state WINED3D_RS_PLANEMASK not implemented yet.\n"); } -static void state_subpixel(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_subpixel(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_SUBPIXEL]) - FIXME("Render state WINED3DRS_SUBPIXEL not implemented yet.\n"); + if (state->render_states[WINED3D_RS_SUBPIXEL]) + FIXME("Render state WINED3D_RS_SUBPIXEL not implemented yet.\n"); } -static void state_subpixelx(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_subpixelx(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_SUBPIXELX]) - FIXME("Render state WINED3DRS_SUBPIXELX not implemented yet.\n"); + if (state->render_states[WINED3D_RS_SUBPIXELX]) + FIXME("Render state WINED3D_RS_SUBPIXELX not implemented yet.\n"); } -static void state_stippleenable(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_stippleenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_STIPPLEENABLE]) - FIXME("Render state WINED3DRS_STIPPLEENABLE not implemented yet.\n"); + if (state->render_states[WINED3D_RS_STIPPLEENABLE]) + FIXME("Render state WINED3D_RS_STIPPLEENABLE not implemented yet.\n"); } -static void state_mipmaplodbias(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_mipmaplodbias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_MIPMAPLODBIAS]) - FIXME("Render state WINED3DRS_MIPMAPLODBIAS not implemented yet.\n"); + if (state->render_states[WINED3D_RS_MIPMAPLODBIAS]) + FIXME("Render state WINED3D_RS_MIPMAPLODBIAS not implemented yet.\n"); } -static void state_anisotropy(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_anisotropy(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_ANISOTROPY]) - FIXME("Render state WINED3DRS_ANISOTROPY not implemented yet.\n"); + if (state->render_states[WINED3D_RS_ANISOTROPY]) + FIXME("Render state WINED3D_RS_ANISOTROPY not implemented yet.\n"); } -static void state_flushbatch(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_flushbatch(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_FLUSHBATCH]) - FIXME("Render state WINED3DRS_FLUSHBATCH not implemented yet.\n"); + if (state->render_states[WINED3D_RS_FLUSHBATCH]) + FIXME("Render state WINED3D_RS_FLUSHBATCH not implemented yet.\n"); } -static void state_translucentsi(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_translucentsi(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_TRANSLUCENTSORTINDEPENDENT]) - FIXME("Render state WINED3DRS_TRANSLUCENTSORTINDEPENDENT not implemented yet.\n"); + if (state->render_states[WINED3D_RS_TRANSLUCENTSORTINDEPENDENT]) + FIXME("Render state WINED3D_RS_TRANSLUCENTSORTINDEPENDENT not implemented yet.\n"); } -static void state_extents(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_extents(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_EXTENTS]) - FIXME("Render state WINED3DRS_EXTENTS not implemented yet.\n"); + if (state->render_states[WINED3D_RS_EXTENTS]) + FIXME("Render state WINED3D_RS_EXTENTS not implemented yet.\n"); } -static void state_ckeyblend(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_ckeyblend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_COLORKEYBLENDENABLE]) - FIXME("Render state WINED3DRS_COLORKEYBLENDENABLE not implemented yet.\n"); + if (state->render_states[WINED3D_RS_COLORKEYBLENDENABLE]) + FIXME("Render state WINED3D_RS_COLORKEYBLENDENABLE not implemented yet.\n"); } -static void state_swvp(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_swvp(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if (stateblock->state.render_states[WINED3DRS_SOFTWAREVERTEXPROCESSING]) + if (state->render_states[WINED3D_RS_SOFTWAREVERTEXPROCESSING]) FIXME("Software vertex processing not implemented.\n"); } -/* Set texture operations up - The following avoids lots of ifdefs in this routine!*/ -#if defined (GL_VERSION_1_3) -# define useext(A) A -#elif defined (GL_EXT_texture_env_combine) -# define useext(A) A##_EXT -#elif defined (GL_ARB_texture_env_combine) -# define useext(A) A##_ARB -#endif - static void get_src_and_opr(DWORD arg, BOOL is_alpha, GLenum* source, GLenum* operand) { /* The WINED3DTA_ALPHAREPLICATE flag specifies the alpha component of the * input should be used for all input components. The WINED3DTA_COMPLEMENT @@ -1985,7 +2038,7 @@ static void get_src_and_opr(DWORD arg, BOOL is_alpha, GLenum* source, GLenum* op /* Setup the texture operations texture stage states */ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state, - BOOL isAlpha, int Stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3) + BOOL isAlpha, int Stage, enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3) { GLenum src1, src2, src3; GLenum opr1, opr2, opr3; @@ -2011,25 +2064,27 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined manuals, i.e., replace arg1 with arg3, arg2 with arg1 and arg3 with arg2 This affects WINED3DTOP_MULTIPLYADD and WINED3DTOP_LERP */ - if (isAlpha) { - comb_target = useext(GL_COMBINE_ALPHA); - src0_target = useext(GL_SOURCE0_ALPHA); - src1_target = useext(GL_SOURCE1_ALPHA); - src2_target = useext(GL_SOURCE2_ALPHA); - opr0_target = useext(GL_OPERAND0_ALPHA); - opr1_target = useext(GL_OPERAND1_ALPHA); - opr2_target = useext(GL_OPERAND2_ALPHA); + if (isAlpha) + { + comb_target = GL_COMBINE_ALPHA; + src0_target = GL_SOURCE0_ALPHA; + src1_target = GL_SOURCE1_ALPHA; + src2_target = GL_SOURCE2_ALPHA; + opr0_target = GL_OPERAND0_ALPHA; + opr1_target = GL_OPERAND1_ALPHA; + opr2_target = GL_OPERAND2_ALPHA; scal_target = GL_ALPHA_SCALE; } - else { - comb_target = useext(GL_COMBINE_RGB); - src0_target = useext(GL_SOURCE0_RGB); - src1_target = useext(GL_SOURCE1_RGB); - src2_target = useext(GL_SOURCE2_RGB); - opr0_target = useext(GL_OPERAND0_RGB); - opr1_target = useext(GL_OPERAND1_RGB); - opr2_target = useext(GL_OPERAND2_RGB); - scal_target = useext(GL_RGB_SCALE); + else + { + comb_target = GL_COMBINE_RGB; + src0_target = GL_SOURCE0_RGB; + src1_target = GL_SOURCE1_RGB; + src2_target = GL_SOURCE2_RGB; + opr0_target = GL_OPERAND0_RGB; + opr1_target = GL_OPERAND1_RGB; + opr2_target = GL_OPERAND2_RGB; + scal_target = GL_RGB_SCALE; } /* If a texture stage references an invalid texture unit the stage just @@ -2037,7 +2092,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined if (is_invalid_op(state, Stage, op, arg1, arg2, arg3)) { arg1 = WINED3DTA_CURRENT; - op = WINED3DTOP_SELECTARG1; + op = WINED3D_TOP_SELECT_ARG1; } if (isAlpha && !state->textures[Stage] && arg1 == WINED3DTA_TEXTURE) @@ -2067,8 +2122,9 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined src3_target = GL_SOURCE3_RGB_NV; opr3_target = GL_OPERAND3_RGB_NV; } - switch (op) { - case WINED3DTOP_DISABLE: /* Only for alpha */ + switch (op) + { + case WINED3D_TOP_DISABLE: /* Only for alpha */ glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE"); glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT); @@ -2088,11 +2144,12 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr); checkGLcall("GL_TEXTURE_ENV, opr3_target, opr"); break; - case WINED3DTOP_SELECTARG1: /* = a1 * 1 + 0 * 0 */ - case WINED3DTOP_SELECTARG2: /* = a2 * 1 + 0 * 0 */ + case WINED3D_TOP_SELECT_ARG1: /* = a1 * 1 + 0 * 0 */ + case WINED3D_TOP_SELECT_ARG2: /* = a2 * 1 + 0 * 0 */ glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); - if (op == WINED3DTOP_SELECTARG1) { + if (op == WINED3D_TOP_SELECT_ARG1) + { glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); checkGLcall("GL_TEXTURE_ENV, src0_target, src1"); glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1); @@ -2117,7 +2174,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined checkGLcall("GL_TEXTURE_ENV, opr3_target, opr"); break; - case WINED3DTOP_MODULATE: + case WINED3D_TOP_MODULATE: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */ glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); @@ -2139,7 +2196,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_MODULATE2X: + case WINED3D_TOP_MODULATE_2X: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */ glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); @@ -2161,7 +2218,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 2); checkGLcall("GL_TEXTURE_ENV, scal_target, 2"); break; - case WINED3DTOP_MODULATE4X: + case WINED3D_TOP_MODULATE_4X: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */ glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); @@ -2184,7 +2241,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined checkGLcall("GL_TEXTURE_ENV, scal_target, 4"); break; - case WINED3DTOP_ADD: + case WINED3D_TOP_ADD: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); @@ -2207,9 +2264,9 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_ADDSIGNED: - glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)); - checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)"); + case WINED3D_TOP_ADD_SIGNED: + glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED); + checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); checkGLcall("GL_TEXTURE_ENV, src0_target, src1"); glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1); @@ -2230,9 +2287,9 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_ADDSIGNED2X: - glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)); - checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)"); + case WINED3D_TOP_ADD_SIGNED_2X: + glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED); + checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); checkGLcall("GL_TEXTURE_ENV, src0_target, src1"); glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1); @@ -2253,7 +2310,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined checkGLcall("GL_TEXTURE_ENV, scal_target, 2"); break; - case WINED3DTOP_ADDSMOOTH: + case WINED3D_TOP_ADD_SMOOTH: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); @@ -2282,29 +2339,29 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_BLENDDIFFUSEALPHA: + case WINED3D_TOP_BLEND_DIFFUSE_ALPHA: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); checkGLcall("GL_TEXTURE_ENV, src0_target, src1"); glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1); checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1"); - glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR)); - checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_PRIMARY_COLOR)"); + glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_PRIMARY_COLOR); + checkGLcall("GL_TEXTURE_ENV, src1_target, GL_PRIMARY_COLOR"); glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr); checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr"); glTexEnvi(GL_TEXTURE_ENV, src2_target, src2); checkGLcall("GL_TEXTURE_ENV, src2_target, src2"); glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2); checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2"); - glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR)); - checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_PRIMARY_COLOR)"); + glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_PRIMARY_COLOR); + checkGLcall("GL_TEXTURE_ENV, src3_target, GL_PRIMARY_COLOR"); glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA); checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA"); glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_BLENDTEXTUREALPHA: + case WINED3D_TOP_BLEND_TEXTURE_ALPHA: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); @@ -2326,29 +2383,29 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_BLENDFACTORALPHA: + case WINED3D_TOP_BLEND_FACTOR_ALPHA: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); checkGLcall("GL_TEXTURE_ENV, src0_target, src1"); glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1); checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1"); - glTexEnvi(GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT)); - checkGLcall("GL_TEXTURE_ENV, src1_target, useext(GL_CONSTANT)"); + glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_CONSTANT); + checkGLcall("GL_TEXTURE_ENV, src1_target, GL_CONSTANT"); glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr); checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr"); glTexEnvi(GL_TEXTURE_ENV, src2_target, src2); checkGLcall("GL_TEXTURE_ENV, src2_target, src2"); glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2); checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2"); - glTexEnvi(GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT)); - checkGLcall("GL_TEXTURE_ENV, src3_target, useext(GL_CONSTANT)"); + glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_CONSTANT); + checkGLcall("GL_TEXTURE_ENV, src3_target, GL_CONSTANT"); glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA); checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA"); glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_BLENDTEXTUREALPHAPM: + case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); @@ -2370,7 +2427,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_MODULATEALPHA_ADDCOLOR: + case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */ glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); /* a0 = src1/opr1 */ @@ -2396,7 +2453,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_MODULATECOLOR_ADDALPHA: + case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); @@ -2422,7 +2479,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR: + case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); @@ -2450,7 +2507,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA: + case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); @@ -2482,7 +2539,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_MULTIPLYADD: + case WINED3D_TOP_MULTIPLY_ADD: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src3); @@ -2505,11 +2562,8 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_BUMPENVMAP: - { - } - - case WINED3DTOP_BUMPENVMAPLUMINANCE: + case WINED3D_TOP_BUMPENVMAP: + case WINED3D_TOP_BUMPENVMAP_LUMINANCE: FIXME("Implement bump environment mapping in GL_NV_texture_env_combine4 path\n"); default: @@ -2525,7 +2579,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined Handled = TRUE; /* Again, assume handled */ switch (op) { - case WINED3DTOP_DISABLE: /* Only for alpha */ + case WINED3D_TOP_DISABLE: /* Only for alpha */ glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE"); glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT); @@ -2535,7 +2589,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_SELECTARG1: + case WINED3D_TOP_SELECT_ARG1: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); @@ -2545,7 +2599,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_SELECTARG2: + case WINED3D_TOP_SELECT_ARG2: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src2); @@ -2555,7 +2609,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_MODULATE: + case WINED3D_TOP_MODULATE: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); @@ -2569,7 +2623,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_MODULATE2X: + case WINED3D_TOP_MODULATE_2X: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); @@ -2583,7 +2637,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 2); checkGLcall("GL_TEXTURE_ENV, scal_target, 2"); break; - case WINED3DTOP_MODULATE4X: + case WINED3D_TOP_MODULATE_4X: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); @@ -2597,7 +2651,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 4); checkGLcall("GL_TEXTURE_ENV, scal_target, 4"); break; - case WINED3DTOP_ADD: + case WINED3D_TOP_ADD: glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD); checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); @@ -2611,9 +2665,9 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_ADDSIGNED: - glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)); - checkGLcall("GL_TEXTURE_ENV, comb_target, useext((GL_ADD_SIGNED)"); + case WINED3D_TOP_ADD_SIGNED: + glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED); + checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); checkGLcall("GL_TEXTURE_ENV, src0_target, src1"); glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1); @@ -2625,9 +2679,9 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_ADDSIGNED2X: - glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)); - checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_ADD_SIGNED)"); + case WINED3D_TOP_ADD_SIGNED_2X: + glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED); + checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); checkGLcall("GL_TEXTURE_ENV, src0_target, src1"); glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1); @@ -2639,11 +2693,11 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 2); checkGLcall("GL_TEXTURE_ENV, scal_target, 2"); break; - case WINED3DTOP_SUBTRACT: + case WINED3D_TOP_SUBTRACT: if (gl_info->supported[ARB_TEXTURE_ENV_COMBINE]) { glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_SUBTRACT); - checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_SUBTRACT)"); + checkGLcall("GL_TEXTURE_ENV, comb_target, GL_SUBTRACT"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); checkGLcall("GL_TEXTURE_ENV, src0_target, src1"); glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1); @@ -2659,9 +2713,9 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined } break; - case WINED3DTOP_BLENDDIFFUSEALPHA: - glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)); - checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)"); + case WINED3D_TOP_BLEND_DIFFUSE_ALPHA: + glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE); + checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); checkGLcall("GL_TEXTURE_ENV, src0_target, src1"); glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1); @@ -2670,16 +2724,16 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined checkGLcall("GL_TEXTURE_ENV, src1_target, src2"); glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2); checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2"); - glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PRIMARY_COLOR)); + glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR); checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR"); glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA); checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA"); glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_BLENDTEXTUREALPHA: - glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)); - checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)"); + case WINED3D_TOP_BLEND_TEXTURE_ALPHA: + glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE); + checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); checkGLcall("GL_TEXTURE_ENV, src0_target, src1"); glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1); @@ -2695,9 +2749,9 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_BLENDFACTORALPHA: - glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)); - checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)"); + case WINED3D_TOP_BLEND_FACTOR_ALPHA: + glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE); + checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); checkGLcall("GL_TEXTURE_ENV, src0_target, src1"); glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1); @@ -2706,16 +2760,16 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined checkGLcall("GL_TEXTURE_ENV, src1_target, src2"); glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2); checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2"); - glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_CONSTANT)); + glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_CONSTANT); checkGLcall("GL_TEXTURE_ENV, src2_target, GL_CONSTANT"); glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA); checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA"); glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_BLENDCURRENTALPHA: - glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)); - checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)"); + case WINED3D_TOP_BLEND_CURRENT_ALPHA: + glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE); + checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); checkGLcall("GL_TEXTURE_ENV, src0_target, src1"); glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1); @@ -2724,14 +2778,14 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined checkGLcall("GL_TEXTURE_ENV, src1_target, src2"); glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2); checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2"); - glTexEnvi(GL_TEXTURE_ENV, src2_target, useext(GL_PREVIOUS)); + glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_PREVIOUS); checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PREVIOUS"); glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA); checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA"); glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_DOTPRODUCT3: + case WINED3D_TOP_DOTPRODUCT3: if (gl_info->supported[ARB_TEXTURE_ENV_DOT3]) { glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB); @@ -2755,9 +2809,9 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_LERP: - glTexEnvi(GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)); - checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_INTERPOLATE)"); + case WINED3D_TOP_LERP: + glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE); + checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE"); glTexEnvi(GL_TEXTURE_ENV, src0_target, src1); checkGLcall("GL_TEXTURE_ENV, src0_target, src1"); glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1); @@ -2773,7 +2827,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined glTexEnvi(GL_TEXTURE_ENV, scal_target, 1); checkGLcall("GL_TEXTURE_ENV, scal_target, 1"); break; - case WINED3DTOP_ADDSMOOTH: + case WINED3D_TOP_ADD_SMOOTH: if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3]) { glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI); @@ -2801,7 +2855,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined } else Handled = FALSE; break; - case WINED3DTOP_BLENDTEXTUREALPHAPM: + case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM: if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3]) { glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI); @@ -2823,7 +2877,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined } else Handled = FALSE; break; - case WINED3DTOP_MODULATEALPHA_ADDCOLOR: + case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR: if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3]) { glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI); @@ -2851,7 +2905,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined } else Handled = FALSE; break; - case WINED3DTOP_MODULATECOLOR_ADDALPHA: + case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA: if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3]) { glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI); @@ -2879,7 +2933,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined } else Handled = FALSE; break; - case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR: + case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR: if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3]) { glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI); @@ -2907,7 +2961,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined } else Handled = FALSE; break; - case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA: + case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA: if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3]) { glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI); @@ -2941,7 +2995,7 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined } else Handled = FALSE; break; - case WINED3DTOP_MULTIPLYADD: + case WINED3D_TOP_MULTIPLY_ADD: if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3]) { glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI); @@ -2963,8 +3017,8 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined } else Handled = FALSE; break; - case WINED3DTOP_BUMPENVMAPLUMINANCE: - case WINED3DTOP_BUMPENVMAP: + case WINED3D_TOP_BUMPENVMAP_LUMINANCE: + case WINED3D_TOP_BUMPENVMAP: if (gl_info->supported[NV_TEXTURE_SHADER2]) { /* Technically texture shader support without register combiners is possible, but not expected to occur @@ -2983,23 +3037,25 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined DWORD op2; if (isAlpha) - op2 = state->texture_states[Stage][WINED3DTSS_COLOROP]; + op2 = state->texture_states[Stage][WINED3D_TSS_COLOR_OP]; else - op2 = state->texture_states[Stage][WINED3DTSS_ALPHAOP]; + op2 = state->texture_states[Stage][WINED3D_TSS_ALPHA_OP]; /* Note: If COMBINE4 in effect can't go back to combine! */ - switch (op2) { - case WINED3DTOP_ADDSMOOTH: - case WINED3DTOP_BLENDTEXTUREALPHAPM: - case WINED3DTOP_MODULATEALPHA_ADDCOLOR: - case WINED3DTOP_MODULATECOLOR_ADDALPHA: - case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR: - case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA: - case WINED3DTOP_MULTIPLYADD: + switch (op2) + { + case WINED3D_TOP_ADD_SMOOTH: + case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM: + case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR: + case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA: + case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR: + case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA: + case WINED3D_TOP_MULTIPLY_ADD: /* Ignore those implemented in both cases */ - switch (op) { - case WINED3DTOP_SELECTARG1: - case WINED3DTOP_SELECTARG2: + switch (op) + { + case WINED3D_TOP_SELECT_ARG1: + case WINED3D_TOP_SELECT_ARG2: combineOK = FALSE; Handled = FALSE; break; @@ -3010,9 +3066,10 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined } } - if (combineOK) { - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE)); - checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, useext(GL_COMBINE)"); + if (combineOK) + { + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); + checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE"); return; } @@ -3023,13 +3080,13 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined } -static void tex_colorop(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void tex_colorop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); - BOOL tex_used = stateblock->device->fixed_function_usage_map & (1 << stage); - DWORD mapped_stage = stateblock->device->texUnitMap[stage]; + const struct wined3d_device *device = context->swapchain->device; + BOOL tex_used = device->fixed_function_usage_map & (1 << stage); + DWORD mapped_stage = device->texUnitMap[stage]; const struct wined3d_gl_info *gl_info = context->gl_info; - const struct wined3d_state *state = &stateblock->state; TRACE("Setting color op for stage %d\n", stage); @@ -3045,8 +3102,7 @@ static void tex_colorop(DWORD state_id, struct wined3d_stateblock *stateblock, s FIXME("Attempt to enable unsupported stage!\n"); return; } - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); - checkGLcall("glActiveTextureARB"); + context_active_texture(context, gl_info, mapped_stage); } if (stage >= state->lowest_disabled_stage) @@ -3080,17 +3136,18 @@ static void tex_colorop(DWORD state_id, struct wined3d_stateblock *stateblock, s texture_activate_dimensions(state->textures[stage], gl_info); set_tex_op(gl_info, state, FALSE, stage, - state->texture_states[stage][WINED3DTSS_COLOROP], - state->texture_states[stage][WINED3DTSS_COLORARG1], - state->texture_states[stage][WINED3DTSS_COLORARG2], - state->texture_states[stage][WINED3DTSS_COLORARG0]); + state->texture_states[stage][WINED3D_TSS_COLOR_OP], + state->texture_states[stage][WINED3D_TSS_COLOR_ARG1], + state->texture_states[stage][WINED3D_TSS_COLOR_ARG2], + state->texture_states[stage][WINED3D_TSS_COLOR_ARG0]); } -void tex_alphaop(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); - BOOL tex_used = stateblock->device->fixed_function_usage_map & (1 << stage); - DWORD mapped_stage = stateblock->device->texUnitMap[stage]; + DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); + const struct wined3d_device *device = context->swapchain->device; + BOOL tex_used = device->fixed_function_usage_map & (1 << stage); + DWORD mapped_stage = device->texUnitMap[stage]; const struct wined3d_gl_info *gl_info = context->gl_info; DWORD op, arg1, arg2, arg0; @@ -3103,18 +3160,17 @@ void tex_alphaop(DWORD state, struct wined3d_stateblock *stateblock, struct wine FIXME("Attempt to enable unsupported stage!\n"); return; } - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); - checkGLcall("glActiveTextureARB"); + context_active_texture(context, gl_info, mapped_stage); } - op = stateblock->state.texture_states[stage][WINED3DTSS_ALPHAOP]; - arg1 = stateblock->state.texture_states[stage][WINED3DTSS_ALPHAARG1]; - arg2 = stateblock->state.texture_states[stage][WINED3DTSS_ALPHAARG2]; - arg0 = stateblock->state.texture_states[stage][WINED3DTSS_ALPHAARG0]; + op = state->texture_states[stage][WINED3D_TSS_ALPHA_OP]; + arg1 = state->texture_states[stage][WINED3D_TSS_ALPHA_ARG1]; + arg2 = state->texture_states[stage][WINED3D_TSS_ALPHA_ARG2]; + arg0 = state->texture_states[stage][WINED3D_TSS_ALPHA_ARG0]; - if (stateblock->state.render_states[WINED3DRS_COLORKEYENABLE] && !stage && stateblock->state.textures[0]) + if (state->render_states[WINED3D_RS_COLORKEYENABLE] && !stage && state->textures[0]) { - struct wined3d_texture *texture = stateblock->state.textures[0]; + struct wined3d_texture *texture = state->textures[0]; GLenum texture_dimensions = texture->target; if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB) @@ -3145,26 +3201,26 @@ void tex_alphaop(DWORD state, struct wined3d_stateblock *stateblock, struct wine * * What to do with multitexturing? So far no app has been found that uses color keying with * multitexturing */ - if (op == WINED3DTOP_DISABLE) + if (op == WINED3D_TOP_DISABLE) { arg1 = WINED3DTA_TEXTURE; - op = WINED3DTOP_SELECTARG1; + op = WINED3D_TOP_SELECT_ARG1; } - else if(op == WINED3DTOP_SELECTARG1 && arg1 != WINED3DTA_TEXTURE) + else if (op == WINED3D_TOP_SELECT_ARG1 && arg1 != WINED3DTA_TEXTURE) { - if (stateblock->state.render_states[WINED3DRS_ALPHABLENDENABLE]) + if (state->render_states[WINED3D_RS_ALPHABLENDENABLE]) { arg2 = WINED3DTA_TEXTURE; - op = WINED3DTOP_MODULATE; + op = WINED3D_TOP_MODULATE; } else arg1 = WINED3DTA_TEXTURE; } - else if(op == WINED3DTOP_SELECTARG2 && arg2 != WINED3DTA_TEXTURE) + else if (op == WINED3D_TOP_SELECT_ARG2 && arg2 != WINED3DTA_TEXTURE) { - if (stateblock->state.render_states[WINED3DRS_ALPHABLENDENABLE]) + if (state->render_states[WINED3D_RS_ALPHABLENDENABLE]) { arg1 = WINED3DTA_TEXTURE; - op = WINED3DTOP_MODULATE; + op = WINED3D_TOP_MODULATE; } else arg2 = WINED3DTA_TEXTURE; } @@ -3178,21 +3234,21 @@ void tex_alphaop(DWORD state, struct wined3d_stateblock *stateblock, struct wine TRACE("Setting alpha op for stage %d\n", stage); if (gl_info->supported[NV_REGISTER_COMBINERS]) { - set_tex_op_nvrc(gl_info, &stateblock->state, TRUE, stage, op, arg1, arg2, arg0, - mapped_stage, stateblock->state.texture_states[stage][WINED3DTSS_RESULTARG]); + set_tex_op_nvrc(gl_info, state, TRUE, stage, op, arg1, arg2, arg0, + mapped_stage, state->texture_states[stage][WINED3D_TSS_RESULT_ARG]); } else { - set_tex_op(gl_info, &stateblock->state, TRUE, stage, op, arg1, arg2, arg0); + set_tex_op(gl_info, state, TRUE, stage, op, arg1, arg2, arg0); } } -static void transform_texture(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void transform_texture(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { DWORD texUnit = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); - DWORD mapped_stage = stateblock->device->texUnitMap[texUnit]; + const struct wined3d_device *device = context->swapchain->device; const struct wined3d_gl_info *gl_info = context->gl_info; - const struct wined3d_state *state = &stateblock->state; + DWORD mapped_stage = device->texUnitMap[texUnit]; BOOL generated; int coordIdx; @@ -3206,18 +3262,17 @@ static void transform_texture(DWORD state_id, struct wined3d_stateblock *statebl if (mapped_stage == WINED3D_UNMAPPED_STAGE) return; if (mapped_stage >= gl_info->limits.textures) return; - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); - checkGLcall("glActiveTextureARB"); - generated = (state->texture_states[texUnit][WINED3DTSS_TEXCOORDINDEX] & 0xffff0000) != WINED3DTSS_TCI_PASSTHRU; - coordIdx = min(state->texture_states[texUnit][WINED3DTSS_TEXCOORDINDEX & 0x0000ffff], MAX_TEXTURES - 1); + context_active_texture(context, gl_info, mapped_stage); + generated = (state->texture_states[texUnit][WINED3D_TSS_TEXCOORD_INDEX] & 0xffff0000) != WINED3DTSS_TCI_PASSTHRU; + coordIdx = min(state->texture_states[texUnit][WINED3D_TSS_TEXCOORD_INDEX & 0x0000ffff], MAX_TEXTURES - 1); - set_texture_matrix(&state->transforms[WINED3DTS_TEXTURE0 + texUnit].u.m[0][0], - state->texture_states[texUnit][WINED3DTSS_TEXTURETRANSFORMFLAGS], + set_texture_matrix(&state->transforms[WINED3D_TS_TEXTURE0 + texUnit].u.m[0][0], + state->texture_states[texUnit][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS], generated, context->last_was_rhw, - stateblock->device->strided_streams.use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx)) - ? stateblock->device->strided_streams.elements[WINED3D_FFP_TEXCOORD0 + coordIdx].format->id + device->strided_streams.use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx)) + ? device->strided_streams.elements[WINED3D_FFP_TEXCOORD0 + coordIdx].format->id : WINED3DFMT_UNKNOWN, - stateblock->device->frag_pipe->ffp_proj_control); + device->frag_pipe->ffp_proj_control); /* The sampler applying function calls us if this changes */ if ((context->lastWasPow2Texture & (1 << texUnit)) && state->textures[texUnit]) @@ -3235,43 +3290,50 @@ static void transform_texture(DWORD state_id, struct wined3d_stateblock *statebl } } -static void unloadTexCoords(const struct wined3d_gl_info *gl_info) +static void unload_tex_coords(const struct wined3d_gl_info *gl_info) { unsigned int texture_idx; - for (texture_idx = 0; texture_idx < gl_info->limits.texture_stages; ++texture_idx) + for (texture_idx = 0; texture_idx < gl_info->limits.texture_coords; ++texture_idx) { GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + texture_idx)); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } } -static void loadTexCoords(const struct wined3d_gl_info *gl_info, struct wined3d_stateblock *stateblock, - const struct wined3d_stream_info *si, GLuint *curVBO) +static void load_tex_coords(const struct wined3d_context *context, const struct wined3d_stream_info *si, + GLuint *curVBO, const struct wined3d_state *state) { + const struct wined3d_device *device = context->swapchain->device; + const struct wined3d_gl_info *gl_info = context->gl_info; unsigned int mapped_stage = 0; unsigned int textureNo = 0; for (textureNo = 0; textureNo < gl_info->limits.texture_stages; ++textureNo) { - int coordIdx = stateblock->state.texture_states[textureNo][WINED3DTSS_TEXCOORDINDEX]; + int coordIdx = state->texture_states[textureNo][WINED3D_TSS_TEXCOORD_INDEX]; - mapped_stage = stateblock->device->texUnitMap[textureNo]; + mapped_stage = device->texUnitMap[textureNo]; if (mapped_stage == WINED3D_UNMAPPED_STAGE) continue; + if (mapped_stage >= gl_info->limits.texture_coords) + { + FIXME("Attempted to load unsupported texture coordinate %u\n", mapped_stage); + continue; + } + if (coordIdx < MAX_TEXTURES && (si->use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx)))) { const struct wined3d_stream_info_element *e = &si->elements[WINED3D_FFP_TEXCOORD0 + coordIdx]; - const struct wined3d_stream_state *stream = &stateblock->state.streams[e->stream_idx]; - TRACE("Setting up texture %u, idx %d, cordindx %u, data %p\n", - textureNo, mapped_stage, coordIdx, e->data); + TRACE("Setting up texture %u, idx %d, coordindx %u, data {%#x:%p}.\n", + textureNo, mapped_stage, coordIdx, e->data.buffer_object, e->data.addr); - if (*curVBO != e->buffer_object) + if (*curVBO != e->data.buffer_object) { - GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->buffer_object)); + GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->data.buffer_object)); checkGLcall("glBindBufferARB"); - *curVBO = e->buffer_object; + *curVBO = e->data.buffer_object; } GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); @@ -3279,9 +3341,11 @@ static void loadTexCoords(const struct wined3d_gl_info *gl_info, struct wined3d_ /* The coords to supply depend completely on the fvf / vertex shader */ glTexCoordPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset); + e->data.addr + state->load_base_vertex_index * e->stride); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - } else { + } + else + { GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + mapped_stage, 0, 0, 0, 1)); } } @@ -3297,15 +3361,16 @@ static void loadTexCoords(const struct wined3d_gl_info *gl_info, struct wined3d_ checkGLcall("loadTexCoords"); } -static void tex_coordindex(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void tex_coordindex(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); - DWORD mapped_stage = stateblock->device->texUnitMap[stage]; + DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); + const struct wined3d_device *device = context->swapchain->device; static const GLfloat s_plane[] = { 1.0f, 0.0f, 0.0f, 0.0f }; static const GLfloat t_plane[] = { 0.0f, 1.0f, 0.0f, 0.0f }; static const GLfloat r_plane[] = { 0.0f, 0.0f, 1.0f, 0.0f }; static const GLfloat q_plane[] = { 0.0f, 0.0f, 0.0f, 1.0f }; const struct wined3d_gl_info *gl_info = context->gl_info; + DWORD mapped_stage = device->texUnitMap[stage]; if (mapped_stage == WINED3D_UNMAPPED_STAGE) { @@ -3318,19 +3383,18 @@ static void tex_coordindex(DWORD state, struct wined3d_stateblock *stateblock, s WARN("stage %u not mapped to a valid texture unit (%u)\n", stage, mapped_stage); return; } - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); - checkGLcall("glActiveTextureARB"); + context_active_texture(context, gl_info, mapped_stage); /* Values 0-7 are indexes into the FVF tex coords - See comments in DrawPrimitive * * FIXME: When using generated texture coordinates, the index value is used to specify the wrapping mode. - * eg. SetTextureStageState( 0, WINED3DTSS_TEXCOORDINDEX, WINED3DTSS_TCI_CAMERASPACEPOSITION | 1 ); + * eg. SetTextureStageState( 0, WINED3D_TSS_TEXCOORDINDEX, WINED3D_TSS_TCI_CAMERASPACEPOSITION | 1 ); * means use the vertex position (camera-space) as the input texture coordinates - * for this texture stage, and the wrap mode set in the WINED3DRS_WRAP1 render + * for this texture stage, and the wrap mode set in the WINED3D_RS_WRAP1 render * state. We do not (yet) support the WINED3DRENDERSTATE_WRAPx values, nor tie them up * to the TEXCOORDINDEX value */ - switch (stateblock->state.texture_states[stage][WINED3DTSS_TEXCOORDINDEX] & 0xffff0000) + switch (state->texture_states[stage][WINED3D_TSS_TEXCOORD_INDEX] & 0xffff0000) { case WINED3DTSS_TCI_PASSTHRU: /* Use the specified texture coordinates contained within the @@ -3444,8 +3508,8 @@ static void tex_coordindex(DWORD state, struct wined3d_stateblock *stateblock, s break; default: - FIXME("Unhandled WINED3DTSS_TEXCOORDINDEX %#x.\n", - stateblock->state.texture_states[stage][WINED3DTSS_TEXCOORDINDEX]); + FIXME("Unhandled WINED3D_TSS_TEXCOORD_INDEX %#x.\n", + state->texture_states[stage][WINED3D_TSS_TEXCOORD_INDEX]); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_R); @@ -3455,12 +3519,12 @@ static void tex_coordindex(DWORD state, struct wined3d_stateblock *stateblock, s break; } - /* Update the texture matrix */ - if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_TEXTURE0 + stage))) { - transform_texture(STATE_TEXTURESTAGE(stage, WINED3DTSS_TEXTURETRANSFORMFLAGS), stateblock, context); - } + /* Update the texture matrix. */ + if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + stage))) + transform_texture(context, state, STATE_TEXTURESTAGE(stage, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS)); - if(!isStateDirty(context, STATE_VDECL) && context->namedArraysLoaded) { + if (!isStateDirty(context, STATE_VDECL) && context->namedArraysLoaded) + { /* Reload the arrays if we are using fixed function arrays to reflect the selected coord input * source. Call loadTexCoords directly because there is no need to reparse the vertex declaration * and do all the things linked to it @@ -3468,50 +3532,32 @@ static void tex_coordindex(DWORD state, struct wined3d_stateblock *stateblock, s */ GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0; - unloadTexCoords(gl_info); - loadTexCoords(gl_info, stateblock, &stateblock->device->strided_streams, &curVBO); + unload_tex_coords(gl_info); + load_tex_coords(context, &device->strided_streams, &curVBO, state); } } -static void shaderconstant(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void tex_bumpenvlscale(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - const struct wined3d_state *state = &stateblock->state; - struct wined3d_device *device = stateblock->device; - - /* Vertex and pixel shader states will call a shader upload, don't do anything as long one of them - * has an update pending - */ - if(isStateDirty(context, STATE_VDECL) || - isStateDirty(context, STATE_PIXELSHADER)) { - return; - } - - device->shader_backend->shader_load_constants(context, use_ps(state), use_vs(state)); -} - -static void tex_bumpenvlscale(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) -{ - DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); - const struct wined3d_shader *ps = stateblock->state.pixel_shader; + DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); + const struct wined3d_shader *ps = state->pixel_shader; if (ps && stage && (ps->reg_maps.luminanceparams & (1 << stage))) { - /* The pixel shader has to know the luminance scale. Do a constants update if it - * isn't scheduled anyway - */ - if(!isStateDirty(context, STATE_PIXELSHADERCONSTANT) && - !isStateDirty(context, STATE_PIXELSHADER)) { - shaderconstant(STATE_PIXELSHADERCONSTANT, stateblock, context); - } + /* The pixel shader has to know the luminance scale. Do a constants + * update if it isn't scheduled anyway. */ + if (!isStateDirty(context, STATE_PIXELSHADERCONSTANT) + && !isStateDirty(context, STATE_PIXELSHADER)) + shaderconstant(context, state, STATE_PIXELSHADERCONSTANT); } } -static void sampler_texmatrix(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void sampler_texmatrix(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - const DWORD sampler = state - STATE_SAMPLER(0); - struct wined3d_texture *texture = stateblock->state.textures[sampler]; + const DWORD sampler = state_id - STATE_SAMPLER(0); + const struct wined3d_texture *texture = state->textures[sampler]; - TRACE("state %#x, stateblock %p, context %p\n", state, stateblock, context); + TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id); if(!texture) return; /* The fixed function np2 texture emulation uses the texture matrix to fix up the coordinates @@ -3527,21 +3573,25 @@ static void sampler_texmatrix(DWORD state, struct wined3d_stateblock *stateblock if (texIsPow2 || (context->lastWasPow2Texture & (1 << sampler))) { - if (texIsPow2) context->lastWasPow2Texture |= 1 << sampler; - else context->lastWasPow2Texture &= ~(1 << sampler); - transform_texture(STATE_TEXTURESTAGE(stateblock->device->texUnitMap[sampler], - WINED3DTSS_TEXTURETRANSFORMFLAGS), stateblock, context); + const struct wined3d_device *device = context->swapchain->device; + + if (texIsPow2) + context->lastWasPow2Texture |= 1 << sampler; + else + context->lastWasPow2Texture &= ~(1 << sampler); + + transform_texture(context, state, + STATE_TEXTURESTAGE(device->texUnitMap[sampler], WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS)); } } } -static void sampler(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void sampler(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { + const struct wined3d_device *device = context->swapchain->device; DWORD sampler = state_id - STATE_SAMPLER(0); - struct wined3d_device *device = stateblock->device; DWORD mapped_stage = device->texUnitMap[sampler]; const struct wined3d_gl_info *gl_info = context->gl_info; - const struct wined3d_state *state = &stateblock->state; union { float f; DWORD d; @@ -3562,20 +3612,19 @@ static void sampler(DWORD state_id, struct wined3d_stateblock *stateblock, struc { return; } - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); - checkGLcall("glActiveTextureARB"); + context_active_texture(context, gl_info, mapped_stage); if (state->textures[sampler]) { struct wined3d_texture *texture = state->textures[sampler]; - BOOL srgb = state->sampler_states[sampler][WINED3DSAMP_SRGBTEXTURE]; + BOOL srgb = state->sampler_states[sampler][WINED3D_SAMP_SRGB_TEXTURE]; - texture->texture_ops->texture_bind(texture, gl_info, srgb); + texture->texture_ops->texture_bind(texture, context, srgb); wined3d_texture_apply_state_changes(texture, state->sampler_states[sampler], gl_info); if (gl_info->supported[EXT_TEXTURE_LOD_BIAS]) { - tmpvalue.d = state->sampler_states[sampler][WINED3DSAMP_MIPMAPLODBIAS]; + tmpvalue.d = state->sampler_states[sampler][WINED3D_SAMP_MIPMAP_LOD_BIAS]; glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, tmpvalue.f); @@ -3584,12 +3633,11 @@ static void sampler(DWORD state_id, struct wined3d_stateblock *stateblock, struc if (!use_ps(state) && sampler < state->lowest_disabled_stage) { - if (state->render_states[WINED3DRS_COLORKEYENABLE] && !sampler) + if (state->render_states[WINED3D_RS_COLORKEYENABLE] && !sampler) { - /* If color keying is enabled update the alpha test, it depends on the existence - * of a color key in stage 0 - */ - state_alpha(WINED3DRS_COLORKEYENABLE, stateblock, context); + /* If color keying is enabled update the alpha test, it + * depends on the existence of a color key in stage 0. */ + state_alpha(context, state, WINED3D_RS_COLORKEYENABLE); } } @@ -3597,87 +3645,87 @@ static void sampler(DWORD state_id, struct wined3d_stateblock *stateblock, struc if (!(texture->flags & WINED3D_TEXTURE_POW2_MAT_IDENT)) device->shader_backend->shader_load_np2fixup_constants(device->shader_priv, gl_info, state); } - else if (mapped_stage < gl_info->limits.textures) + else { if (sampler < state->lowest_disabled_stage) { /* TODO: What should I do with pixel shaders here ??? */ - if (state->render_states[WINED3DRS_COLORKEYENABLE] && !sampler) + if (state->render_states[WINED3D_RS_COLORKEYENABLE] && !sampler) { - /* If color keying is enabled update the alpha test, it depends on the existence - * of a color key in stage 0 - */ - state_alpha(WINED3DRS_COLORKEYENABLE, stateblock, context); + /* If color keying is enabled update the alpha test, it + * depends on the existence of a color key in stage 0. */ + state_alpha(context, state, WINED3D_RS_COLORKEYENABLE); } } /* Otherwise tex_colorop disables the stage */ - glBindTexture(GL_TEXTURE_2D, device->dummyTextureName[sampler]); - checkGLcall("glBindTexture(GL_TEXTURE_2D, device->dummyTextureName[sampler])"); + context_bind_texture(context, GL_NONE, 0); } } -void apply_pixelshader(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +void apply_pixelshader(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - const struct wined3d_state *state = &stateblock->state; - struct wined3d_device *device = stateblock->device; + const struct wined3d_device *device = context->swapchain->device; BOOL use_vshader = use_vs(state); BOOL use_pshader = use_ps(state); unsigned int i; - if (use_pshader) { - if(!context->last_was_pshader) { - /* Former draw without a pixel shader, some samplers - * may be disabled because of WINED3DTSS_COLOROP = WINED3DTOP_DISABLE - * make sure to enable them - */ - for(i=0; i < MAX_FRAGMENT_SAMPLERS; i++) { - if(!isStateDirty(context, STATE_SAMPLER(i))) { - sampler(STATE_SAMPLER(i), stateblock, context); - } + if (use_pshader) + { + if (!context->last_was_pshader) + { + /* Former draw without a pixel shader, some samplers may be + * disabled because of WINED3D_TSS_COLOR_OP = WINED3DTOP_DISABLE + * make sure to enable them. */ + for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i) + { + if (!isStateDirty(context, STATE_SAMPLER(i))) + sampler(context, state, STATE_SAMPLER(i)); } context->last_was_pshader = TRUE; - } else { - /* Otherwise all samplers were activated by the code above in earlier draws, or by sampler() - * if a different texture was bound. I don't have to do anything. - */ } - } else { - /* Disabled the pixel shader - color ops weren't applied - * while it was enabled, so re-apply them. */ + else + { + /* Otherwise all samplers were activated by the code above in + * earlier draws, or by sampler() if a different texture was + * bound. I don't have to do anything. */ + } + } + else + { + /* Disabled the pixel shader - color ops weren't applied while it was + * enabled, so re-apply them. */ for (i = 0; i < context->gl_info->limits.texture_stages; ++i) { - if (!isStateDirty(context, STATE_TEXTURESTAGE(i, WINED3DTSS_COLOROP))) - stateblock_apply_state(STATE_TEXTURESTAGE(i, WINED3DTSS_COLOROP), stateblock, context); + if (!isStateDirty(context, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP))) + context_apply_state(context, state, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP)); } context->last_was_pshader = FALSE; } - if(!isStateDirty(context, device->StateTable[STATE_VSHADER].representative)) { + if (!isStateDirty(context, context->state_table[STATE_VSHADER].representative)) + { device->shader_backend->shader_select(context, use_pshader, use_vshader); - if (!isStateDirty(context, STATE_VERTEXSHADERCONSTANT) && (use_vshader || use_pshader)) { - shaderconstant(STATE_VERTEXSHADERCONSTANT, stateblock, context); - } + if (!isStateDirty(context, STATE_VERTEXSHADERCONSTANT) && (use_vshader || use_pshader)) + shaderconstant(context, state, STATE_VERTEXSHADERCONSTANT); } } -static void shader_bumpenvmat(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void shader_bumpenvmat(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); - const struct wined3d_shader *ps = stateblock->state.pixel_shader; + DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); + const struct wined3d_shader *ps = state->pixel_shader; if (ps && stage && (ps->reg_maps.bumpmat & (1 << stage))) { - /* The pixel shader has to know the bump env matrix. Do a constants update if it isn't scheduled - * anyway - */ - if(!isStateDirty(context, STATE_PIXELSHADERCONSTANT) && - !isStateDirty(context, STATE_PIXELSHADER)) { - shaderconstant(STATE_PIXELSHADERCONSTANT, stateblock, context); - } + /* The pixel shader has to know the bump env matrix. Do a constants + * update if it isn't scheduled anyway. */ + if (!isStateDirty(context, STATE_PIXELSHADERCONSTANT) + && !isStateDirty(context, STATE_PIXELSHADER)) + shaderconstant(context, state, STATE_PIXELSHADERCONSTANT); } } -static void transform_world(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void transform_world(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { /* This function is called by transform_view below if the view matrix was changed too * @@ -3692,39 +3740,38 @@ static void transform_world(DWORD state, struct wined3d_stateblock *stateblock, if(context->last_was_rhw) { glLoadIdentity(); checkGLcall("glLoadIdentity()"); - } else { + } + else + { /* In the general case, the view matrix is the identity matrix */ - if (stateblock->device->view_ident) + if (context->swapchain->device->view_ident) { - glLoadMatrixf(&stateblock->state.transforms[WINED3DTS_WORLDMATRIX(0)].u.m[0][0]); + glLoadMatrixf(&state->transforms[WINED3D_TS_WORLD_MATRIX(0)].u.m[0][0]); checkGLcall("glLoadMatrixf"); } else { - glLoadMatrixf(&stateblock->state.transforms[WINED3DTS_VIEW].u.m[0][0]); + glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW].u.m[0][0]); checkGLcall("glLoadMatrixf"); - glMultMatrixf(&stateblock->state.transforms[WINED3DTS_WORLDMATRIX(0)].u.m[0][0]); + glMultMatrixf(&state->transforms[WINED3D_TS_WORLD_MATRIX(0)].u.m[0][0]); checkGLcall("glMultMatrixf"); } } } -static void clipplane(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void clipplane(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - const struct wined3d_state *state = &stateblock->state; UINT index = state_id - STATE_CLIPPLANE(0); - if (isStateDirty(context, STATE_TRANSFORM(WINED3DTS_VIEW)) || index >= context->gl_info->limits.clipplanes) - { + if (isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_VIEW)) || index >= context->gl_info->limits.clipplanes) return; - } glMatrixMode(GL_MODELVIEW); glPushMatrix(); /* Clip Plane settings are affected by the model view in OpenGL, the View transform in direct3d */ if (!use_vs(state)) - glLoadMatrixf(&state->transforms[WINED3DTS_VIEW].u.m[0][0]); + glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW].u.m[0][0]); else /* with vertex shaders, clip planes are not transformed in direct3d, * in OpenGL they are still transformed by the model view. @@ -3742,9 +3789,9 @@ static void clipplane(DWORD state_id, struct wined3d_stateblock *stateblock, str glPopMatrix(); } -static void transform_worldex(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void transform_worldex(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - UINT matrix = state - STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)); + UINT matrix = state_id - STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)); GLenum glMat; TRACE("Setting world matrix %d\n", matrix); @@ -3752,10 +3799,11 @@ static void transform_worldex(DWORD state, struct wined3d_stateblock *stateblock { WARN("Unsupported blend matrix set\n"); return; - } else if(isStateDirty(context, STATE_TRANSFORM(WINED3DTS_VIEW))) { - return; } + if (isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_VIEW))) + return; + /* GL_MODELVIEW0_ARB: 0x1700 * GL_MODELVIEW1_ARB: 0x850a * GL_MODELVIEW2_ARB: 0x8722 @@ -3769,79 +3817,80 @@ static void transform_worldex(DWORD state, struct wined3d_stateblock *stateblock glMatrixMode(glMat); checkGLcall("glMatrixMode(glMat)"); - /* World matrix 0 is multiplied with the view matrix because d3d uses 3 matrices while gl uses only 2. To avoid - * weighting the view matrix incorrectly it has to be multiplied into every gl modelview matrix - */ - if (stateblock->device->view_ident) + /* World matrix 0 is multiplied with the view matrix because d3d uses 3 + * matrices while gl uses only 2. To avoid weighting the view matrix + * incorrectly it has to be multiplied into every GL modelview matrix. */ + if (context->swapchain->device->view_ident) { - glLoadMatrixf(&stateblock->state.transforms[WINED3DTS_WORLDMATRIX(matrix)].u.m[0][0]); + glLoadMatrixf(&state->transforms[WINED3D_TS_WORLD_MATRIX(matrix)].u.m[0][0]); checkGLcall("glLoadMatrixf"); } else { - glLoadMatrixf(&stateblock->state.transforms[WINED3DTS_VIEW].u.m[0][0]); + glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW].u.m[0][0]); checkGLcall("glLoadMatrixf"); - glMultMatrixf(&stateblock->state.transforms[WINED3DTS_WORLDMATRIX(matrix)].u.m[0][0]); + glMultMatrixf(&state->transforms[WINED3D_TS_WORLD_MATRIX(matrix)].u.m[0][0]); checkGLcall("glMultMatrixf"); } } -static void state_vertexblend_w(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_vertexblend_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - WINED3DVERTEXBLENDFLAGS f = stateblock->state.render_states[WINED3DRS_VERTEXBLEND]; + enum wined3d_vertex_blend_flags f = state->render_states[WINED3D_RS_VERTEXBLEND]; static unsigned int once; - if (f == WINED3DVBF_DISABLE) return; + if (f == WINED3D_VBF_DISABLE) + return; if (!once++) FIXME("Vertex blend flags %#x not supported.\n", f); else WARN("Vertex blend flags %#x not supported.\n", f); } -static void state_vertexblend(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void state_vertexblend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - WINED3DVERTEXBLENDFLAGS val = stateblock->state.render_states[WINED3DRS_VERTEXBLEND]; + enum wined3d_vertex_blend_flags val = state->render_states[WINED3D_RS_VERTEXBLEND]; + struct wined3d_device *device = context->swapchain->device; const struct wined3d_gl_info *gl_info = context->gl_info; static unsigned int once; - switch(val) { - case WINED3DVBF_1WEIGHTS: - case WINED3DVBF_2WEIGHTS: - case WINED3DVBF_3WEIGHTS: + switch (val) + { + case WINED3D_VBF_1WEIGHTS: + case WINED3D_VBF_2WEIGHTS: + case WINED3D_VBF_3WEIGHTS: glEnable(GL_VERTEX_BLEND_ARB); checkGLcall("glEnable(GL_VERTEX_BLEND_ARB)"); - /* D3D adds one more matrix which has weight (1 - sum(weights)). This is enabled at context - * creation with enabling GL_WEIGHT_SUM_UNITY_ARB. - */ - GL_EXTCALL(glVertexBlendARB(stateblock->state.render_states[WINED3DRS_VERTEXBLEND] + 1)); + /* D3D adds one more matrix which has weight (1 - sum(weights)). + * This is enabled at context creation with enabling + * GL_WEIGHT_SUM_UNITY_ARB. */ + GL_EXTCALL(glVertexBlendARB(state->render_states[WINED3D_RS_VERTEXBLEND] + 1)); - if (!stateblock->device->vertexBlendUsed) + if (!device->vertexBlendUsed) { unsigned int i; for (i = 1; i < gl_info->limits.blends; ++i) { - if (!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(i)))) - { - transform_worldex(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(i)), stateblock, context); - } + if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(i)))) + transform_worldex(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(i))); } - stateblock->device->vertexBlendUsed = TRUE; + device->vertexBlendUsed = TRUE; } break; - case WINED3DVBF_TWEENING: - case WINED3DVBF_0WEIGHTS: /* Indexed vertex blending, not supported. */ + case WINED3D_VBF_TWEENING: + case WINED3D_VBF_0WEIGHTS: /* Indexed vertex blending, not supported. */ if (!once++) FIXME("Vertex blend flags %#x not supported.\n", val); else WARN("Vertex blend flags %#x not supported.\n", val); /* Fall through. */ - case WINED3DVBF_DISABLE: + case WINED3D_VBF_DISABLE: glDisable(GL_VERTEX_BLEND_ARB); checkGLcall("glDisable(GL_VERTEX_BLEND_ARB)"); break; } } -static void transform_view(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void transform_view(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_light_info *light = NULL; @@ -3855,14 +3904,14 @@ static void transform_view(DWORD state, struct wined3d_stateblock *stateblock, s glMatrixMode(GL_MODELVIEW); checkGLcall("glMatrixMode(GL_MODELVIEW)"); - glLoadMatrixf(&stateblock->state.transforms[WINED3DTS_VIEW].u.m[0][0]); + glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW].u.m[0][0]); checkGLcall("glLoadMatrixf(...)"); /* Reset lights. TODO: Call light apply func */ for (k = 0; k < gl_info->limits.lights; ++k) { - light = stateblock->state.lights[k]; - if(!light) continue; + if (!(light = state->lights[k])) + continue; glLightfv(GL_LIGHT0 + light->glIndex, GL_POSITION, light->lightPosn); checkGLcall("glLightfv posn"); glLightfv(GL_LIGHT0 + light->glIndex, GL_SPOT_DIRECTION, light->lightDirn); @@ -3872,9 +3921,8 @@ static void transform_view(DWORD state, struct wined3d_stateblock *stateblock, s /* Reset Clipping Planes */ for (k = 0; k < gl_info->limits.clipplanes; ++k) { - if(!isStateDirty(context, STATE_CLIPPLANE(k))) { - clipplane(STATE_CLIPPLANE(k), stateblock, context); - } + if (!isStateDirty(context, STATE_CLIPPLANE(k))) + clipplane(context, state, STATE_CLIPPLANE(k)); } if(context->last_was_rhw) { @@ -3885,126 +3933,91 @@ static void transform_view(DWORD state, struct wined3d_stateblock *stateblock, s } /* Call the world matrix state, this will apply the combined WORLD + VIEW matrix - * No need to do it here if the state is scheduled for update. - */ - if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)))) { - transform_world(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), stateblock, context); - } + * No need to do it here if the state is scheduled for update. */ + if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)))) + transform_world(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0))); /* Avoid looping over a number of matrices if the app never used the functionality */ - if (stateblock->device->vertexBlendUsed) + if (context->swapchain->device->vertexBlendUsed) { for (k = 1; k < gl_info->limits.blends; ++k) { - if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(k)))) { - transform_worldex(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(k)), stateblock, context); - } + if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(k)))) + transform_worldex(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(k))); } } } -static void transform_projection(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void transform_projection(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { glMatrixMode(GL_PROJECTION); checkGLcall("glMatrixMode(GL_PROJECTION)"); - glLoadIdentity(); - checkGLcall("glLoadIdentity"); + + /* There are a couple of additional things we have to take into account + * here besides the projection transformation itself: + * - We need to flip along the y-axis in case of offscreen rendering. + * - OpenGL Z range is {-Wc,...,Wc} while D3D Z range is {0,...,Wc}. + * - D3D coordinates refer to pixel centers while GL coordinates refer + * to pixel corners. + * - D3D has a top-left filling convention. We need to maintain this + * even after the y-flip mentioned above. + * In order to handle the last two points, we translate by + * (63.0 / 128.0) / VPw and (63.0 / 128.0) / VPh. This is equivalent to + * translating slightly less than half a pixel. We want the difference to + * be large enough that it doesn't get lost due to rounding inside the + * driver, but small enough to prevent it from interfering with any + * anti-aliasing. */ if (context->last_was_rhw) { - double x = stateblock->state.viewport.X; - double y = stateblock->state.viewport.Y; - double w = stateblock->state.viewport.Width; - double h = stateblock->state.viewport.Height; - - TRACE("Calling glOrtho with x %.8e, y %.8e, w %.8e, h %.8e.\n", x, y, w, h); - if (context->render_offscreen) - glOrtho(x, x + w, -y, -y - h, 0.0, -1.0); - else - glOrtho(x, x + w, y + h, y, 0.0, -1.0); - checkGLcall("glOrtho"); - - /* D3D texture coordinates are flipped compared to OpenGL ones, so - * render everything upside down when rendering offscreen. */ - if (context->render_offscreen) + /* Transform D3D RHW coordinates to OpenGL clip coordinates. */ + double x = state->viewport.x; + double y = state->viewport.y; + double w = state->viewport.width; + double h = state->viewport.height; + double x_scale = 2.0 / w; + double x_offset = ((63.0 / 64.0) - (2.0 * x) - w) / w; + double y_scale = context->render_offscreen ? 2.0 / h : 2.0 / -h; + double y_offset = context->render_offscreen + ? ((63.0 / 64.0) - (2.0 * y) - h) / h + : ((63.0 / 64.0) - (2.0 * y) - h) / -h; + const GLdouble projection[] = { - glScalef(1.0f, -1.0f, 1.0f); - checkGLcall("glScalef"); - } + x_scale, 0.0, 0.0, 0.0, + 0.0, y_scale, 0.0, 0.0, + 0.0, 0.0, 2.0, 0.0, + x_offset, y_offset, -1.0, 1.0, + }; - /* Window Coord 0 is the middle of the first pixel, so translate by 1/2 pixels */ - glTranslatef(63.0f / 128.0f, 63.0f / 128.0f, 0.0f); - checkGLcall("glTranslatef(63.0f / 128.0f, 63.0f / 128.0f, 0.0f)"); + glLoadMatrixd(projection); + checkGLcall("glLoadMatrixd"); } else { - /* The rule is that the window coordinate 0 does not correspond to the - beginning of the first pixel, but the center of the first pixel. - As a consequence if you want to correctly draw one line exactly from - the left to the right end of the viewport (with all matrices set to - be identity), the x coords of both ends of the line would be not - -1 and 1 respectively but (-1-1/viewport_widh) and (1-1/viewport_width) - instead. - - 1.0 / Width is used because the coord range goes from -1.0 to 1.0, then we - divide by the Width/Height, so we need the half range(1.0) to translate by - half a pixel. - - The other fun is that d3d's output z range after the transformation is [0;1], - but opengl's is [-1;1]. Since the z buffer is in range [0;1] for both, gl - scales [-1;1] to [0;1]. This would mean that we end up in [0.5;1] and loose a lot - of Z buffer precision and the clear values do not match in the z test. Thus scale - [0;1] to [-1;1], so when gl undoes that we utilize the full z range - */ - - /* - * Careful with the order of operations here, we're essentially working backwards: - * x = x + 1/w; - * y = (y - 1/h) * flip; - * z = z * 2 - 1; - * - * Becomes: - * glTranslatef(0.0, 0.0, -1.0); - * glScalef(1.0, 1.0, 2.0); - * - * glScalef(1.0, flip, 1.0); - * glTranslatef(1/w, -1/h, 0.0); - * - * This is equivalent to: - * glTranslatef(1/w, -flip/h, -1.0) - * glScalef(1.0, flip, 2.0); - */ - - /* Translate by slightly less than a half pixel to force a top-left - * filling convention. We want the difference to be large enough that - * it doesn't get lost due to rounding inside the driver, but small - * enough to prevent it from interfering with any anti-aliasing. */ - GLfloat xoffset = (63.0f / 64.0f) / stateblock->state.viewport.Width; - GLfloat yoffset = -(63.0f / 64.0f) / stateblock->state.viewport.Height; - - if (context->render_offscreen) + double y_scale = context->render_offscreen ? -1.0 : 1.0; + double x_offset = (63.0 / 64.0) / state->viewport.width; + double y_offset = context->render_offscreen + ? (63.0 / 64.0) / state->viewport.height + : -(63.0 / 64.0) / state->viewport.height; + const GLdouble projection[] = { - /* D3D texture coordinates are flipped compared to OpenGL ones, so - * render everything upside down when rendering offscreen. */ - glTranslatef(xoffset, -yoffset, -1.0f); - checkGLcall("glTranslatef(xoffset, -yoffset, -1.0f)"); - glScalef(1.0f, -1.0f, 2.0f); - } else { - glTranslatef(xoffset, yoffset, -1.0f); - checkGLcall("glTranslatef(xoffset, yoffset, -1.0f)"); - glScalef(1.0f, 1.0f, 2.0f); - } - checkGLcall("glScalef"); + 1.0, 0.0, 0.0, 0.0, + 0.0, y_scale, 0.0, 0.0, + 0.0, 0.0, 2.0, 0.0, + x_offset, y_offset, -1.0, 1.0, + }; - glMultMatrixf(&stateblock->state.transforms[WINED3DTS_PROJECTION].u.m[0][0]); + glLoadMatrixd(projection); + checkGLcall("glLoadMatrixd"); + + glMultMatrixf(&state->transforms[WINED3D_TS_PROJECTION].u.m[0][0]); checkGLcall("glLoadMatrixf"); } } -/* This should match any arrays loaded in loadVertexData. - * TODO: Only load / unload arrays if we have to. - */ -static inline void unloadVertexData(const struct wined3d_gl_info *gl_info) +/* This should match any arrays loaded in load_vertex_data. + * TODO: Only load / unload arrays if we have to. */ +static void unload_vertex_data(const struct wined3d_gl_info *gl_info) { glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); @@ -4017,7 +4030,7 @@ static inline void unloadVertexData(const struct wined3d_gl_info *gl_info) { glDisableClientState(GL_WEIGHT_ARRAY_ARB); } - unloadTexCoords(gl_info); + unload_tex_coords(gl_info); } static inline void unload_numbered_array(struct wined3d_context *context, int i) @@ -4031,34 +4044,27 @@ static inline void unload_numbered_array(struct wined3d_context *context, int i) } /* This should match any arrays loaded in loadNumberedArrays - * TODO: Only load / unload arrays if we have to. - */ -static inline void unloadNumberedArrays(struct wined3d_context *context) + * TODO: Only load / unload arrays if we have to. */ +static void unload_numbered_arrays(struct wined3d_context *context) { /* disable any attribs (this is the same for both GLSL and ARB modes) */ - GLint maxAttribs = 16; int i; - /* Leave all the attribs disabled */ - glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &maxAttribs); - /* MESA does not support it right not */ - if (glGetError() != GL_NO_ERROR) - maxAttribs = 16; - for (i = 0; i < maxAttribs; ++i) { + for (i = 0; i < context->gl_info->limits.vertex_attribs; ++i) { unload_numbered_array(context, i); } } -static void loadNumberedArrays(struct wined3d_stateblock *stateblock, - const struct wined3d_stream_info *stream_info, struct wined3d_context *context) +static void load_numbered_arrays(struct wined3d_context *context, + const struct wined3d_stream_info *stream_info, const struct wined3d_state *state) { + struct wined3d_device *device = context->swapchain->device; const struct wined3d_gl_info *gl_info = context->gl_info; GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0; int i; - struct wined3d_buffer *vb; /* Default to no instancing */ - stateblock->device->instancedDraw = FALSE; + device->instancedDraw = FALSE; for (i = 0; i < MAX_ATTRIBS; i++) { @@ -4070,37 +4076,35 @@ static void loadNumberedArrays(struct wined3d_stateblock *stateblock, continue; } - stream = &stateblock->state.streams[stream_info->elements[i].stream_idx]; + stream = &state->streams[stream_info->elements[i].stream_idx]; /* Do not load instance data. It will be specified using glTexCoord by drawprim */ if (stream->flags & WINED3DSTREAMSOURCE_INSTANCEDATA) { if (context->numbered_array_mask & (1 << i)) unload_numbered_array(context, i); - stateblock->device->instancedDraw = TRUE; + device->instancedDraw = TRUE; continue; } - TRACE_(d3d_shader)("Loading array %u [VBO=%u]\n", i, stream_info->elements[i].buffer_object); + TRACE_(d3d_shader)("Loading array %u [VBO=%u]\n", i, stream_info->elements[i].data.buffer_object); if (stream_info->elements[i].stride) { - if (curVBO != stream_info->elements[i].buffer_object) + if (curVBO != stream_info->elements[i].data.buffer_object) { - GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, stream_info->elements[i].buffer_object)); + GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, stream_info->elements[i].data.buffer_object)); checkGLcall("glBindBufferARB"); - curVBO = stream_info->elements[i].buffer_object; + curVBO = stream_info->elements[i].data.buffer_object; } /* Use the VBO to find out if a vertex buffer exists, not the vb * pointer. vb can point to a user pointer data blob. In that case * curVBO will be 0. If there is a vertex buffer but no vbo we * won't be load converted attributes anyway. */ - vb = stream->buffer; GL_EXTCALL(glVertexAttribPointerARB(i, stream_info->elements[i].format->gl_vtx_format, stream_info->elements[i].format->gl_vtx_type, stream_info->elements[i].format->gl_normalized, - stream_info->elements[i].stride, stream_info->elements[i].data - + stateblock->state.load_base_vertex_index * stream_info->elements[i].stride - + stream->offset)); + stream_info->elements[i].stride, stream_info->elements[i].data.addr + + state->load_base_vertex_index * stream_info->elements[i].stride)); if (!(context->numbered_array_mask & (1 << i))) { @@ -4114,11 +4118,10 @@ static void loadNumberedArrays(struct wined3d_stateblock *stateblock, * glVertexAttribPointerARB doesn't do that. Instead disable the * pointer and set up the attribute statically. But we have to * figure out the system memory address. */ - const BYTE *ptr = stream_info->elements[i].data + stream->offset; - if (stream_info->elements[i].buffer_object) + const BYTE *ptr = stream_info->elements[i].data.addr; + if (stream_info->elements[i].data.buffer_object) { - vb = stream->buffer; - ptr += (ULONG_PTR)buffer_get_sysmem(vb, gl_info); + ptr += (ULONG_PTR)buffer_get_sysmem(stream->buffer, gl_info); } if (context->numbered_array_mask & (1 << i)) unload_numbered_array(context, i); @@ -4211,51 +4214,49 @@ static void loadNumberedArrays(struct wined3d_stateblock *stateblock, checkGLcall("Loading numbered arrays"); } -/* Used from 2 different functions, and too big to justify making it inlined */ -static void loadVertexData(const struct wined3d_context *context, struct wined3d_stateblock *stateblock, - const struct wined3d_stream_info *si) +static void load_vertex_data(const struct wined3d_context *context, + const struct wined3d_stream_info *si, const struct wined3d_state *state) { + struct wined3d_device *device = context->swapchain->device; const struct wined3d_gl_info *gl_info = context->gl_info; GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0; const struct wined3d_stream_info_element *e; - const struct wined3d_stream_state *stream; TRACE("Using fast vertex array code\n"); /* This is fixed function pipeline only, and the fixed function pipeline doesn't do instancing */ - stateblock->device->instancedDraw = FALSE; + device->instancedDraw = FALSE; /* Blend Data ---------------------------------------------- */ if ((si->use_map & (1 << WINED3D_FFP_BLENDWEIGHT)) || si->use_map & (1 << WINED3D_FFP_BLENDINDICES)) { e = &si->elements[WINED3D_FFP_BLENDWEIGHT]; - stream = &stateblock->state.streams[e->stream_idx]; if (gl_info->supported[ARB_VERTEX_BLEND]) { TRACE("Blend %u %p %u\n", e->format->component_count, - e->data + stateblock->state.load_base_vertex_index * e->stride, e->stride + stream->offset); + e->data.addr + state->load_base_vertex_index * e->stride, e->stride); glEnableClientState(GL_WEIGHT_ARRAY_ARB); checkGLcall("glEnableClientState(GL_WEIGHT_ARRAY_ARB)"); GL_EXTCALL(glVertexBlendARB(e->format->component_count + 1)); - if (curVBO != e->buffer_object) + if (curVBO != e->data.buffer_object) { - GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->buffer_object)); + GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->data.buffer_object)); checkGLcall("glBindBufferARB"); - curVBO = e->buffer_object; + curVBO = e->data.buffer_object; } TRACE("glWeightPointerARB(%#x, %#x, %#x, %p);\n", e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset); + e->data.addr + state->load_base_vertex_index * e->stride); GL_EXTCALL(glWeightPointerARB(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset)); + e->data.addr + state->load_base_vertex_index * e->stride)); checkGLcall("glWeightPointerARB"); @@ -4297,13 +4298,12 @@ static void loadVertexData(const struct wined3d_context *context, struct wined3d if (si->use_map & (1 << WINED3D_FFP_POSITION)) { e = &si->elements[WINED3D_FFP_POSITION]; - stream = &stateblock->state.streams[e->stream_idx]; - if (curVBO != e->buffer_object) + if (curVBO != e->data.buffer_object) { - GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->buffer_object)); + GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->data.buffer_object)); checkGLcall("glBindBufferARB"); - curVBO = e->buffer_object; + curVBO = e->data.buffer_object; } /* min(WINED3D_ATR_FORMAT(position),3) to Disable RHW mode as 'w' coord @@ -4314,20 +4314,20 @@ static void loadVertexData(const struct wined3d_context *context, struct wined3d This only applies to user pointer sources, in VBOs the vertices are fixed up */ - if (!e->buffer_object) + if (!e->data.buffer_object) { TRACE("glVertexPointer(3, %#x, %#x, %p);\n", e->format->gl_vtx_type, e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset); + e->data.addr + state->load_base_vertex_index * e->stride); glVertexPointer(3 /* min(e->format->gl_vtx_format, 3) */, e->format->gl_vtx_type, e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset); + e->data.addr + state->load_base_vertex_index * e->stride); } else { TRACE("glVertexPointer(%#x, %#x, %#x, %p);\n", e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset); + e->data.addr + state->load_base_vertex_index * e->stride); glVertexPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset); + e->data.addr + state->load_base_vertex_index * e->stride); } checkGLcall("glVertexPointer(...)"); glEnableClientState(GL_VERTEX_ARRAY); @@ -4338,19 +4338,18 @@ static void loadVertexData(const struct wined3d_context *context, struct wined3d if (si->use_map & (1 << WINED3D_FFP_NORMAL)) { e = &si->elements[WINED3D_FFP_NORMAL]; - stream = &stateblock->state.streams[e->stream_idx]; - if (curVBO != e->buffer_object) + if (curVBO != e->data.buffer_object) { - GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->buffer_object)); + GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->data.buffer_object)); checkGLcall("glBindBufferARB"); - curVBO = e->buffer_object; + curVBO = e->data.buffer_object; } TRACE("glNormalPointer(%#x, %#x, %p);\n", e->format->gl_vtx_type, e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset); + e->data.addr + state->load_base_vertex_index * e->stride); glNormalPointer(e->format->gl_vtx_type, e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset); + e->data.addr + state->load_base_vertex_index * e->stride); checkGLcall("glNormalPointer(...)"); glEnableClientState(GL_NORMAL_ARRAY); checkGLcall("glEnableClientState(GL_NORMAL_ARRAY)"); @@ -4372,20 +4371,19 @@ static void loadVertexData(const struct wined3d_context *context, struct wined3d if (si->use_map & (1 << WINED3D_FFP_DIFFUSE)) { e = &si->elements[WINED3D_FFP_DIFFUSE]; - stream = &stateblock->state.streams[e->stream_idx]; - if (curVBO != e->buffer_object) + if (curVBO != e->data.buffer_object) { - GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->buffer_object)); + GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->data.buffer_object)); checkGLcall("glBindBufferARB"); - curVBO = e->buffer_object; + curVBO = e->data.buffer_object; } TRACE("glColorPointer(%#x, %#x %#x, %p);\n", e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset); + e->data.addr + state->load_base_vertex_index * e->stride); glColorPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset); + e->data.addr + state->load_base_vertex_index * e->stride); checkGLcall("glColorPointer(4, GL_UNSIGNED_BYTE, ...)"); glEnableClientState(GL_COLOR_ARRAY); checkGLcall("glEnableClientState(GL_COLOR_ARRAY)"); @@ -4401,18 +4399,17 @@ static void loadVertexData(const struct wined3d_context *context, struct wined3d TRACE("setting specular colour\n"); e = &si->elements[WINED3D_FFP_SPECULAR]; - stream = &stateblock->state.streams[e->stream_idx]; if (gl_info->supported[EXT_SECONDARY_COLOR]) { GLenum type = e->format->gl_vtx_type; GLint format = e->format->gl_vtx_format; - if (curVBO != e->buffer_object) + if (curVBO != e->data.buffer_object) { - GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->buffer_object)); + GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->data.buffer_object)); checkGLcall("glBindBufferARB"); - curVBO = e->buffer_object; + curVBO = e->data.buffer_object; } if (format != 4 || (gl_info->quirks & WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA)) @@ -4423,9 +4420,9 @@ static void loadVertexData(const struct wined3d_context *context, struct wined3d * 4 component secondary colors use it */ TRACE("glSecondaryColorPointer(%#x, %#x, %#x, %p);\n", format, type, e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset); + e->data.addr + state->load_base_vertex_index * e->stride); GL_EXTCALL(glSecondaryColorPointerEXT(format, type, e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset)); + e->data.addr + state->load_base_vertex_index * e->stride)); checkGLcall("glSecondaryColorPointerEXT(format, type, ...)"); } else @@ -4434,9 +4431,9 @@ static void loadVertexData(const struct wined3d_context *context, struct wined3d { case GL_UNSIGNED_BYTE: TRACE("glSecondaryColorPointer(3, GL_UNSIGNED_BYTE, %#x, %p);\n", e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset); + e->data.addr + state->load_base_vertex_index * e->stride); GL_EXTCALL(glSecondaryColorPointerEXT(3, GL_UNSIGNED_BYTE, e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset)); + e->data.addr + state->load_base_vertex_index * e->stride)); checkGLcall("glSecondaryColorPointerEXT(3, GL_UNSIGNED_BYTE, ...)"); break; @@ -4444,9 +4441,9 @@ static void loadVertexData(const struct wined3d_context *context, struct wined3d FIXME("Add 4 component specular color pointers for type %x\n", type); /* Make sure that the right color component is dropped */ TRACE("glSecondaryColorPointer(3, %#x, %#x, %p);\n", type, e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset); + e->data.addr + state->load_base_vertex_index * e->stride); GL_EXTCALL(glSecondaryColorPointerEXT(3, type, e->stride, - e->data + stateblock->state.load_base_vertex_index * e->stride + stream->offset)); + e->data.addr + state->load_base_vertex_index * e->stride)); checkGLcall("glSecondaryColorPointerEXT(3, type, ...)"); } } @@ -4472,46 +4469,53 @@ static void loadVertexData(const struct wined3d_context *context, struct wined3d } /* Texture coords -------------------------------------------*/ - loadTexCoords(gl_info, stateblock, si, &curVBO); + load_tex_coords(context, si, &curVBO, state); } -static void streamsrc(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void streamsrc(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - struct wined3d_device *device = stateblock->device; - BOOL load_numbered = use_vs(&stateblock->state) && !device->useDrawStridedSlow; - BOOL load_named = !use_vs(&stateblock->state) && !device->useDrawStridedSlow; + const struct wined3d_device *device = context->swapchain->device; + BOOL load_numbered = use_vs(state) && !device->useDrawStridedSlow; + BOOL load_named = !use_vs(state) && !device->useDrawStridedSlow; + if (isStateDirty(context, STATE_VDECL)) return; if (context->numberedArraysLoaded && !load_numbered) { - unloadNumberedArrays(context); + unload_numbered_arrays(context); context->numberedArraysLoaded = FALSE; context->numbered_array_mask = 0; } else if (context->namedArraysLoaded) { - unloadVertexData(context->gl_info); + unload_vertex_data(context->gl_info); context->namedArraysLoaded = FALSE; } if (load_numbered) { TRACE("Loading numbered arrays\n"); - loadNumberedArrays(stateblock, &device->strided_streams, context); + load_numbered_arrays(context, &device->strided_streams, state); context->numberedArraysLoaded = TRUE; } else if (load_named) { TRACE("Loading vertex data\n"); - loadVertexData(context, stateblock, &device->strided_streams); + load_vertex_data(context, &device->strided_streams, state); context->namedArraysLoaded = TRUE; } } -static void vertexdeclaration(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void vdecl_miscpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { + if (isStateDirty(context, STATE_STREAMSRC)) + return; + streamsrc(context, state, STATE_STREAMSRC); +} + +static void vertexdeclaration(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) +{ + const struct wined3d_device *device = context->swapchain->device; const struct wined3d_gl_info *gl_info = context->gl_info; - const struct wined3d_state *state = &stateblock->state; - struct wined3d_device *device = stateblock->device; BOOL useVertexShaderFunction = use_vs(state); BOOL usePixelShaderFunction = use_ps(state); BOOL updateFog = FALSE; @@ -4523,28 +4527,19 @@ static void vertexdeclaration(DWORD state_id, struct wined3d_stateblock *statebl if (transformed != context->last_was_rhw && !useVertexShaderFunction) updateFog = TRUE; - if (transformed) { - context->last_was_rhw = TRUE; - } else { + context->last_was_rhw = transformed; - /* Untransformed, so relies on the view and projection matrices */ - context->last_was_rhw = FALSE; - /* This turns off the Z scale trick to 'disable' viewport frustum clipping in rhw mode*/ - device->untransformed = TRUE; - } - - /* Don't have to apply the matrices when vertex shaders are used. When vshaders are turned - * off this function will be called again anyway to make sure they're properly set - */ - if(!useVertexShaderFunction) { - /* TODO: Move this mainly to the viewport state and only apply when the vp has changed - * or transformed / untransformed was switched - */ - if(wasrhw != context->last_was_rhw && - !isStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION)) && - !isStateDirty(context, STATE_VIEWPORT)) { - transform_projection(STATE_TRANSFORM(WINED3DTS_PROJECTION), stateblock, context); - } + /* Don't have to apply the matrices when vertex shaders are used. When + * vshaders are turned off this function will be called again anyway to + * make sure they're properly set. */ + if (!useVertexShaderFunction) + { + /* TODO: Move this mainly to the viewport state and only apply when + * the vp has changed or transformed / untransformed was switched. */ + if (wasrhw != context->last_was_rhw + && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)) + && !isStateDirty(context, STATE_VIEWPORT)) + transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION)); /* World matrix needs reapplication here only if we're switching between rhw and non-rhw * mode. * @@ -4556,33 +4551,31 @@ static void vertexdeclaration(DWORD state_id, struct wined3d_stateblock *statebl * World and view matrix go into the same gl matrix, so only apply them when neither is * dirty */ - if(transformed != wasrhw && - !isStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0))) && - !isStateDirty(context, STATE_TRANSFORM(WINED3DTS_VIEW))) { - transform_world(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), stateblock, context); - } + if (transformed != wasrhw && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0))) + && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_VIEW))) + transform_world(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0))); + if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_COLORVERTEX))) + state_colormat(context, state, STATE_RENDER(WINED3D_RS_COLORVERTEX)); + if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_LIGHTING))) + state_lighting(context, state, STATE_RENDER(WINED3D_RS_LIGHTING)); - if(!isStateDirty(context, STATE_RENDER(WINED3DRS_COLORVERTEX))) { - state_colormat(STATE_RENDER(WINED3DRS_COLORVERTEX), stateblock, context); - } - if(!isStateDirty(context, STATE_RENDER(WINED3DRS_LIGHTING))) { - state_lighting(STATE_RENDER(WINED3DRS_LIGHTING), stateblock, context); - } - - if(context->last_was_vshader) { + if (context->last_was_vshader) + { updateFog = TRUE; - if(!device->vs_clipping && !isStateDirty(context, STATE_RENDER(WINED3DRS_CLIPPLANEENABLE))) { - state_clipping(STATE_RENDER(WINED3DRS_CLIPPLANEENABLE), stateblock, context); - } + + if (!device->vs_clipping && !isStateDirty(context, STATE_RENDER(WINED3D_RS_CLIPPLANEENABLE))) + state_clipping(context, state, STATE_RENDER(WINED3D_RS_CLIPPLANEENABLE)); + for (i = 0; i < gl_info->limits.clipplanes; ++i) { - clipplane(STATE_CLIPPLANE(i), stateblock, context); + clipplane(context, state, STATE_CLIPPLANE(i)); } } - if(!isStateDirty(context, STATE_RENDER(WINED3DRS_NORMALIZENORMALS))) { - state_normalize(STATE_RENDER(WINED3DRS_NORMALIZENORMALS), stateblock, context); - } - } else { + if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_NORMALIZENORMALS))) + state_normalize(context, state, STATE_RENDER(WINED3D_RS_NORMALIZENORMALS)); + } + else + { if(!context->last_was_vshader) { static BOOL warned = FALSE; if(!device->vs_clipping) { @@ -4595,24 +4588,25 @@ static void vertexdeclaration(DWORD state_id, struct wined3d_stateblock *statebl checkGLcall("glDisable(GL_CLIP_PLANE0 + i)"); } - if (!warned && stateblock->state.render_states[WINED3DRS_CLIPPLANEENABLE]) + if (!warned && state->render_states[WINED3D_RS_CLIPPLANEENABLE]) { FIXME("Clipping not supported with vertex shaders\n"); warned = TRUE; } } - if(wasrhw) { - /* Apply the transform matrices when switching from rhw drawing to vertex shaders. Vertex - * shaders themselves do not need it, but the matrices are not reapplied automatically when - * switching back from vertex shaders to fixed function processing. So make sure we leave the - * fixed function vertex processing states back in a sane state before switching to shaders - */ - if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION))) { - transform_projection(STATE_TRANSFORM(WINED3DTS_PROJECTION), stateblock, context); - } - if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)))) { - transform_world(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), stateblock, context); - } + if (wasrhw) + { + /* Apply the transform matrices when switching from rhw + * drawing to vertex shaders. Vertex shaders themselves do + * not need it, but the matrices are not reapplied + * automatically when switching back from vertex shaders to + * fixed function processing. So make sure we leave the fixed + * function vertex processing states back in a sane state + * before switching to shaders. */ + if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION))) + transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION)); + if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)))) + transform_world(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0))); } updateFog = TRUE; @@ -4622,149 +4616,155 @@ static void vertexdeclaration(DWORD state_id, struct wined3d_stateblock *statebl */ for (i = 0; i < gl_info->limits.clipplanes; ++i) { - clipplane(STATE_CLIPPLANE(i), stateblock, context); + clipplane(context, state, STATE_CLIPPLANE(i)); } } } - /* Vertex and pixel shaders are applied together for now, so let the last dirty state do the - * application - */ - if (!isStateDirty(context, STATE_PIXELSHADER)) { + /* Vertex and pixel shaders are applied together, so let the last dirty + * state do the application. */ + if (!isStateDirty(context, STATE_PIXELSHADER)) + { device->shader_backend->shader_select(context, usePixelShaderFunction, useVertexShaderFunction); - if (!isStateDirty(context, STATE_VERTEXSHADERCONSTANT) && (useVertexShaderFunction || usePixelShaderFunction)) { - shaderconstant(STATE_VERTEXSHADERCONSTANT, stateblock, context); - } + if (!isStateDirty(context, STATE_VERTEXSHADERCONSTANT) + && (useVertexShaderFunction || usePixelShaderFunction)) + shaderconstant(context, state, STATE_VERTEXSHADERCONSTANT); } context->last_was_vshader = useVertexShaderFunction; - if (updateFog) stateblock_apply_state(STATE_RENDER(WINED3DRS_FOGVERTEXMODE), stateblock, context); + if (updateFog) + context_apply_state(context, state, STATE_RENDER(WINED3D_RS_FOGVERTEXMODE)); - if(!useVertexShaderFunction) { - int i; - for(i = 0; i < MAX_TEXTURES; i++) { - if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_TEXTURE0 + i))) { - transform_texture(STATE_TEXTURESTAGE(i, WINED3DTSS_TEXTURETRANSFORMFLAGS), stateblock, context); - } + if (!useVertexShaderFunction) + { + unsigned int i; + + for (i = 0; i < MAX_TEXTURES; ++i) + { + if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + i))) + transform_texture(context, state, STATE_TEXTURESTAGE(i, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS)); } } } -static void viewport_miscpart(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void viewport_miscpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - struct wined3d_surface *target = stateblock->device->fb.render_targets[0]; - UINT width, height; - WINED3DVIEWPORT vp = stateblock->state.viewport; + const struct wined3d_surface *target = state->fb->render_targets[0]; + struct wined3d_viewport vp = state->viewport; - if (vp.Width > target->resource.width) - vp.Width = target->resource.width; - if (vp.Height > target->resource.height) - vp.Height = target->resource.height; + if (vp.width > target->resource.width) + vp.width = target->resource.width; + if (vp.height > target->resource.height) + vp.height = target->resource.height; - glDepthRange(vp.MinZ, vp.MaxZ); + glDepthRange(vp.min_z, vp.max_z); checkGLcall("glDepthRange"); - /* Note: GL requires lower left, DirectX supplies upper left. This is reversed when using offscreen rendering - */ + /* Note: GL requires lower left, DirectX supplies upper left. This is + * reversed when using offscreen rendering. */ if (context->render_offscreen) { - glViewport(vp.X, vp.Y, vp.Width, vp.Height); - } else { - target->get_drawable_size(context, &width, &height); + glViewport(vp.x, vp.y, vp.width, vp.height); + } + else + { + UINT width, height; - glViewport(vp.X, - (height - (vp.Y + vp.Height)), - vp.Width, vp.Height); + target->get_drawable_size(context, &width, &height); + glViewport(vp.x, (height - (vp.y + vp.height)), + vp.width, vp.height); } checkGLcall("glViewport"); } -static void viewport_vertexpart(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void viewport_vertexpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION))) { - transform_projection(STATE_TRANSFORM(WINED3DTS_PROJECTION), stateblock, context); - } - if(!isStateDirty(context, STATE_RENDER(WINED3DRS_POINTSCALEENABLE))) { - state_pscale(STATE_RENDER(WINED3DRS_POINTSCALEENABLE), stateblock, context); - } + if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION))) + transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION)); + if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_POINTSCALEENABLE))) + state_pscale(context, state, STATE_RENDER(WINED3D_RS_POINTSCALEENABLE)); /* Update the position fixup. */ if (!isStateDirty(context, STATE_VERTEXSHADERCONSTANT)) - shaderconstant(STATE_VERTEXSHADERCONSTANT, stateblock, context); + shaderconstant(context, state, STATE_VERTEXSHADERCONSTANT); } -static void light(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void light(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - UINT Index = state - STATE_ACTIVELIGHT(0); - const struct wined3d_light_info *lightInfo = stateblock->state.lights[Index]; + UINT Index = state_id - STATE_ACTIVELIGHT(0); + const struct wined3d_light_info *lightInfo = state->lights[Index]; - if(!lightInfo) { + if (!lightInfo) + { glDisable(GL_LIGHT0 + Index); checkGLcall("glDisable(GL_LIGHT0 + Index)"); - } else { + } + else + { float quad_att; float colRGBA[] = {0.0f, 0.0f, 0.0f, 0.0f}; /* Light settings are affected by the model view in OpenGL, the View transform in direct3d*/ glMatrixMode(GL_MODELVIEW); glPushMatrix(); - glLoadMatrixf(&stateblock->state.transforms[WINED3DTS_VIEW].u.m[0][0]); + glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW].u.m[0][0]); /* Diffuse: */ - colRGBA[0] = lightInfo->OriginalParms.Diffuse.r; - colRGBA[1] = lightInfo->OriginalParms.Diffuse.g; - colRGBA[2] = lightInfo->OriginalParms.Diffuse.b; - colRGBA[3] = lightInfo->OriginalParms.Diffuse.a; + colRGBA[0] = lightInfo->OriginalParms.diffuse.r; + colRGBA[1] = lightInfo->OriginalParms.diffuse.g; + colRGBA[2] = lightInfo->OriginalParms.diffuse.b; + colRGBA[3] = lightInfo->OriginalParms.diffuse.a; glLightfv(GL_LIGHT0 + Index, GL_DIFFUSE, colRGBA); checkGLcall("glLightfv"); /* Specular */ - colRGBA[0] = lightInfo->OriginalParms.Specular.r; - colRGBA[1] = lightInfo->OriginalParms.Specular.g; - colRGBA[2] = lightInfo->OriginalParms.Specular.b; - colRGBA[3] = lightInfo->OriginalParms.Specular.a; + colRGBA[0] = lightInfo->OriginalParms.specular.r; + colRGBA[1] = lightInfo->OriginalParms.specular.g; + colRGBA[2] = lightInfo->OriginalParms.specular.b; + colRGBA[3] = lightInfo->OriginalParms.specular.a; glLightfv(GL_LIGHT0 + Index, GL_SPECULAR, colRGBA); checkGLcall("glLightfv"); /* Ambient */ - colRGBA[0] = lightInfo->OriginalParms.Ambient.r; - colRGBA[1] = lightInfo->OriginalParms.Ambient.g; - colRGBA[2] = lightInfo->OriginalParms.Ambient.b; - colRGBA[3] = lightInfo->OriginalParms.Ambient.a; + colRGBA[0] = lightInfo->OriginalParms.ambient.r; + colRGBA[1] = lightInfo->OriginalParms.ambient.g; + colRGBA[2] = lightInfo->OriginalParms.ambient.b; + colRGBA[3] = lightInfo->OriginalParms.ambient.a; glLightfv(GL_LIGHT0 + Index, GL_AMBIENT, colRGBA); checkGLcall("glLightfv"); - if ((lightInfo->OriginalParms.Range *lightInfo->OriginalParms.Range) >= FLT_MIN) { - quad_att = 1.4f/(lightInfo->OriginalParms.Range *lightInfo->OriginalParms.Range); - } else { + if ((lightInfo->OriginalParms.range * lightInfo->OriginalParms.range) >= FLT_MIN) + quad_att = 1.4f / (lightInfo->OriginalParms.range * lightInfo->OriginalParms.range); + else quad_att = 0.0f; /* 0 or MAX? (0 seems to be ok) */ - } /* Do not assign attenuation values for lights that do not use them. D3D apps are free to pass any junk, * but gl drivers use them and may crash due to bad Attenuation values. Need for Speed most wanted sets * Attenuation0 to NaN and crashes in the gl lib */ - switch (lightInfo->OriginalParms.Type) { - case WINED3DLIGHT_POINT: + switch (lightInfo->OriginalParms.type) + { + case WINED3D_LIGHT_POINT: /* Position */ glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->lightPosn[0]); checkGLcall("glLightfv"); glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff); checkGLcall("glLightf"); /* Attenuation - Are these right? guessing... */ - glLightf(GL_LIGHT0 + Index, GL_CONSTANT_ATTENUATION, lightInfo->OriginalParms.Attenuation0); + glLightf(GL_LIGHT0 + Index, GL_CONSTANT_ATTENUATION, lightInfo->OriginalParms.attenuation0); checkGLcall("glLightf"); - glLightf(GL_LIGHT0 + Index, GL_LINEAR_ATTENUATION, lightInfo->OriginalParms.Attenuation1); + glLightf(GL_LIGHT0 + Index, GL_LINEAR_ATTENUATION, lightInfo->OriginalParms.attenuation1); checkGLcall("glLightf"); - if (quad_att < lightInfo->OriginalParms.Attenuation2) quad_att = lightInfo->OriginalParms.Attenuation2; + if (quad_att < lightInfo->OriginalParms.attenuation2) + quad_att = lightInfo->OriginalParms.attenuation2; glLightf(GL_LIGHT0 + Index, GL_QUADRATIC_ATTENUATION, quad_att); checkGLcall("glLightf"); /* FIXME: Range */ break; - case WINED3DLIGHT_SPOT: + case WINED3D_LIGHT_SPOT: /* Position */ glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->lightPosn[0]); checkGLcall("glLightfv"); @@ -4776,17 +4776,18 @@ static void light(DWORD state, struct wined3d_stateblock *stateblock, struct win glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff); checkGLcall("glLightf"); /* Attenuation - Are these right? guessing... */ - glLightf(GL_LIGHT0 + Index, GL_CONSTANT_ATTENUATION, lightInfo->OriginalParms.Attenuation0); + glLightf(GL_LIGHT0 + Index, GL_CONSTANT_ATTENUATION, lightInfo->OriginalParms.attenuation0); checkGLcall("glLightf"); - glLightf(GL_LIGHT0 + Index, GL_LINEAR_ATTENUATION, lightInfo->OriginalParms.Attenuation1); + glLightf(GL_LIGHT0 + Index, GL_LINEAR_ATTENUATION, lightInfo->OriginalParms.attenuation1); checkGLcall("glLightf"); - if (quad_att < lightInfo->OriginalParms.Attenuation2) quad_att = lightInfo->OriginalParms.Attenuation2; + if (quad_att < lightInfo->OriginalParms.attenuation2) + quad_att = lightInfo->OriginalParms.attenuation2; glLightf(GL_LIGHT0 + Index, GL_QUADRATIC_ATTENUATION, quad_att); checkGLcall("glLightf"); /* FIXME: Range */ break; - case WINED3DLIGHT_DIRECTIONAL: + case WINED3D_LIGHT_DIRECTIONAL: /* Direction */ glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->lightPosn[0]); /* Note gl uses w position of 0 for direction! */ checkGLcall("glLightfv"); @@ -4797,7 +4798,7 @@ static void light(DWORD state, struct wined3d_stateblock *stateblock, struct win break; default: - FIXME("Unrecognized light type %d\n", lightInfo->OriginalParms.Type); + FIXME("Unrecognized light type %#x.\n", lightInfo->OriginalParms.type); } /* Restore the modelview matrix */ @@ -4808,45 +4809,47 @@ static void light(DWORD state, struct wined3d_stateblock *stateblock, struct win } } -static void scissorrect(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void scissorrect(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - struct wined3d_surface *target = stateblock->device->fb.render_targets[0]; - RECT *pRect = &stateblock->state.scissor_rect; - UINT height; - UINT width; + const RECT *r = &state->scissor_rect; - target->get_drawable_size(context, &width, &height); - /* Warning: glScissor uses window coordinates, not viewport coordinates, so our viewport correction does not apply - * Warning2: Even in windowed mode the coords are relative to the window, not the screen - */ - TRACE("(%p) Setting new Scissor Rect to %d:%d-%d:%d\n", stateblock->device, pRect->left, pRect->bottom - height, - pRect->right - pRect->left, pRect->bottom - pRect->top); + /* Warning: glScissor uses window coordinates, not viewport coordinates, + * so our viewport correction does not apply. Warning2: Even in windowed + * mode the coords are relative to the window, not the screen. */ + TRACE("Setting new scissor rect to %s.\n", wine_dbgstr_rect(r)); if (context->render_offscreen) { - glScissor(pRect->left, pRect->top, pRect->right - pRect->left, pRect->bottom - pRect->top); - } else { - glScissor(pRect->left, height - pRect->bottom, pRect->right - pRect->left, pRect->bottom - pRect->top); + glScissor(r->left, r->top, r->right - r->left, r->bottom - r->top); + } + else + { + const struct wined3d_surface *target = state->fb->render_targets[0]; + UINT height; + UINT width; + + target->get_drawable_size(context, &width, &height); + glScissor(r->left, height - r->bottom, r->right - r->left, r->bottom - r->top); } checkGLcall("glScissor"); } -static void indexbuffer(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void indexbuffer(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { const struct wined3d_gl_info *gl_info = context->gl_info; - if (stateblock->state.user_stream || !stateblock->state.index_buffer) + if (state->user_stream || !state->index_buffer) { GL_EXTCALL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0)); } else { - struct wined3d_buffer *ib = stateblock->state.index_buffer; + struct wined3d_buffer *ib = state->index_buffer; GL_EXTCALL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, ib->buffer_object)); } } -static void frontface(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void frontface(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { if (context->render_offscreen) { @@ -4858,7 +4861,7 @@ static void frontface(DWORD state, struct wined3d_stateblock *stateblock, struct } } -static void psorigin_w(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void psorigin_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { static BOOL warned; @@ -4869,7 +4872,7 @@ static void psorigin_w(DWORD state, struct wined3d_stateblock *stateblock, struc } } -static void psorigin(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void psorigin(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { const struct wined3d_gl_info *gl_info = context->gl_info; GLint origin = context->render_offscreen ? GL_LOWER_LEFT : GL_UPPER_LEFT; @@ -4887,173 +4890,173 @@ static void psorigin(DWORD state, struct wined3d_stateblock *stateblock, struct } const struct StateEntryTemplate misc_state_template[] = { - { STATE_RENDER(WINED3DRS_SRCBLEND), { STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_DESTBLEND), { STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), { STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), state_blend }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_EDGEANTIALIAS), { STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ANTIALIASEDLINEENABLE), { STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_SEPARATEALPHABLENDENABLE), { STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_SRCBLENDALPHA), { STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_DESTBLENDALPHA), { STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_DESTBLENDALPHA), { STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_BLENDOPALPHA), { STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_STREAMSRC, { STATE_VDECL, NULL }, WINED3D_GL_EXT_NONE }, - { STATE_VDECL, { STATE_VDECL, streamsrc }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_SRCBLEND), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_DESTBLEND), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), state_blend }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_EDGEANTIALIAS), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ANTIALIASEDLINEENABLE), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_SEPARATEALPHABLENDENABLE), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_SRCBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_DESTBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_DESTBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_BLENDOPALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_STREAMSRC, { STATE_STREAMSRC, streamsrc }, WINED3D_GL_EXT_NONE }, + { STATE_VDECL, { STATE_VDECL, vdecl_miscpart }, WINED3D_GL_EXT_NONE }, { STATE_FRONTFACE, { STATE_FRONTFACE, frontface }, WINED3D_GL_EXT_NONE }, { STATE_SCISSORRECT, { STATE_SCISSORRECT, scissorrect }, WINED3D_GL_EXT_NONE }, { STATE_POINTSPRITECOORDORIGIN, { STATE_POINTSPRITECOORDORIGIN, psorigin }, WINED3D_GL_VERSION_2_0 }, { STATE_POINTSPRITECOORDORIGIN, { STATE_POINTSPRITECOORDORIGIN, psorigin_w }, WINED3D_GL_EXT_NONE }, - /* TODO: Move shader constant loading to vertex and fragment pipeline repectively, as soon as the pshader and + /* TODO: Move shader constant loading to vertex and fragment pipeline respectively, as soon as the pshader and * vshader loadings are untied from each other */ { STATE_VERTEXSHADERCONSTANT, { STATE_VERTEXSHADERCONSTANT, shaderconstant }, WINED3D_GL_EXT_NONE }, { STATE_PIXELSHADERCONSTANT, { STATE_VERTEXSHADERCONSTANT, NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), shader_bumpenvmat }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), shader_bumpenvmat }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), shader_bumpenvmat }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), shader_bumpenvmat }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), shader_bumpenvmat }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), shader_bumpenvmat }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), shader_bumpenvmat }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), shader_bumpenvmat }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVLSCALE), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlscale }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVLOFFSET), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVLSCALE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVLSCALE), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlscale }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVLOFFSET), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVLSCALE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVLSCALE), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlscale }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVLOFFSET), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVLSCALE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVLSCALE), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlscale }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVLOFFSET), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVLSCALE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVLSCALE), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlscale }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVLOFFSET), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVLSCALE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVLSCALE), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlscale }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVLOFFSET), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVLSCALE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVLSCALE), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlscale }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVLOFFSET), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVLSCALE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVLSCALE), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVLSCALE), tex_bumpenvlscale }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVLOFFSET), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVLSCALE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenvmat }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenvmat }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenvmat }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenvmat }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenvmat }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenvmat }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenvmat }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), shader_bumpenvmat }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), tex_bumpenvlscale }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), tex_bumpenvlscale }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), tex_bumpenvlscale }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), tex_bumpenvlscale }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), tex_bumpenvlscale }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), tex_bumpenvlscale }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), tex_bumpenvlscale }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), tex_bumpenvlscale }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE }, { STATE_VIEWPORT, { STATE_VIEWPORT, viewport_miscpart }, WINED3D_GL_EXT_NONE }, { STATE_INDEXBUFFER, { STATE_INDEXBUFFER, indexbuffer }, ARB_VERTEX_BUFFER_OBJECT }, { STATE_INDEXBUFFER, { STATE_INDEXBUFFER, state_nop }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ANTIALIAS), { STATE_RENDER(WINED3DRS_ANTIALIAS), state_antialias }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_TEXTUREPERSPECTIVE), { STATE_RENDER(WINED3DRS_TEXTUREPERSPECTIVE), state_perspective }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ZENABLE), { STATE_RENDER(WINED3DRS_ZENABLE), state_zenable }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAPU), { STATE_RENDER(WINED3DRS_WRAPU), state_wrapu }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAPV), { STATE_RENDER(WINED3DRS_WRAPV), state_wrapv }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FILLMODE), { STATE_RENDER(WINED3DRS_FILLMODE), state_fillmode }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_SHADEMODE), { STATE_RENDER(WINED3DRS_SHADEMODE), state_shademode }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_LINEPATTERN), { STATE_RENDER(WINED3DRS_LINEPATTERN), state_linepattern }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_MONOENABLE), { STATE_RENDER(WINED3DRS_MONOENABLE), state_monoenable }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ROP2), { STATE_RENDER(WINED3DRS_ROP2), state_rop2 }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_PLANEMASK), { STATE_RENDER(WINED3DRS_PLANEMASK), state_planemask }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ZWRITEENABLE), { STATE_RENDER(WINED3DRS_ZWRITEENABLE), state_zwritenable }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ALPHATESTENABLE), { STATE_RENDER(WINED3DRS_ALPHATESTENABLE), state_alpha }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ALPHAREF), { STATE_RENDER(WINED3DRS_ALPHATESTENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ALPHAFUNC), { STATE_RENDER(WINED3DRS_ALPHATESTENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_COLORKEYENABLE), { STATE_RENDER(WINED3DRS_ALPHATESTENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_LASTPIXEL), { STATE_RENDER(WINED3DRS_LASTPIXEL), state_lastpixel }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_CULLMODE), { STATE_RENDER(WINED3DRS_CULLMODE), state_cullmode }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ZFUNC), { STATE_RENDER(WINED3DRS_ZFUNC), state_zfunc }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_DITHERENABLE), { STATE_RENDER(WINED3DRS_DITHERENABLE), state_ditherenable }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_SUBPIXEL), { STATE_RENDER(WINED3DRS_SUBPIXEL), state_subpixel }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_SUBPIXELX), { STATE_RENDER(WINED3DRS_SUBPIXELX), state_subpixelx }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_STIPPLEDALPHA), { STATE_RENDER(WINED3DRS_STIPPLEDALPHA), state_stippledalpha }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_STIPPLEENABLE), { STATE_RENDER(WINED3DRS_STIPPLEENABLE), state_stippleenable }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_MIPMAPLODBIAS), { STATE_RENDER(WINED3DRS_MIPMAPLODBIAS), state_mipmaplodbias }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ANISOTROPY), { STATE_RENDER(WINED3DRS_ANISOTROPY), state_anisotropy }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FLUSHBATCH), { STATE_RENDER(WINED3DRS_FLUSHBATCH), state_flushbatch }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_TRANSLUCENTSORTINDEPENDENT), { STATE_RENDER(WINED3DRS_TRANSLUCENTSORTINDEPENDENT), state_translucentsi }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_STENCILENABLE), { STATE_RENDER(WINED3DRS_STENCILENABLE), state_stencil }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_STENCILFAIL), { STATE_RENDER(WINED3DRS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_STENCILZFAIL), { STATE_RENDER(WINED3DRS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_STENCILPASS), { STATE_RENDER(WINED3DRS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_STENCILFUNC), { STATE_RENDER(WINED3DRS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_STENCILREF), { STATE_RENDER(WINED3DRS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_STENCILMASK), { STATE_RENDER(WINED3DRS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_STENCILWRITEMASK), { STATE_RENDER(WINED3DRS_STENCILWRITEMASK), state_stencilwrite2s}, EXT_STENCIL_TWO_SIDE }, - { STATE_RENDER(WINED3DRS_STENCILWRITEMASK), { STATE_RENDER(WINED3DRS_STENCILWRITEMASK), state_stencilwrite }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_TWOSIDEDSTENCILMODE), { STATE_RENDER(WINED3DRS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_CCW_STENCILFAIL), { STATE_RENDER(WINED3DRS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_CCW_STENCILZFAIL), { STATE_RENDER(WINED3DRS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_CCW_STENCILPASS), { STATE_RENDER(WINED3DRS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_CCW_STENCILFUNC), { STATE_RENDER(WINED3DRS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAP0), { STATE_RENDER(WINED3DRS_WRAP0), state_wrap }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAP1), { STATE_RENDER(WINED3DRS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAP2), { STATE_RENDER(WINED3DRS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAP3), { STATE_RENDER(WINED3DRS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAP4), { STATE_RENDER(WINED3DRS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAP5), { STATE_RENDER(WINED3DRS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAP6), { STATE_RENDER(WINED3DRS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAP7), { STATE_RENDER(WINED3DRS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAP8), { STATE_RENDER(WINED3DRS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAP9), { STATE_RENDER(WINED3DRS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAP10), { STATE_RENDER(WINED3DRS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAP11), { STATE_RENDER(WINED3DRS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAP12), { STATE_RENDER(WINED3DRS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAP13), { STATE_RENDER(WINED3DRS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAP14), { STATE_RENDER(WINED3DRS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_WRAP15), { STATE_RENDER(WINED3DRS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_EXTENTS), { STATE_RENDER(WINED3DRS_EXTENTS), state_extents }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_COLORKEYBLENDENABLE), { STATE_RENDER(WINED3DRS_COLORKEYBLENDENABLE), state_ckeyblend }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_SOFTWAREVERTEXPROCESSING), { STATE_RENDER(WINED3DRS_SOFTWAREVERTEXPROCESSING), state_swvp }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_PATCHEDGESTYLE), { STATE_RENDER(WINED3DRS_PATCHEDGESTYLE), state_patchedgestyle}, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_PATCHSEGMENTS), { STATE_RENDER(WINED3DRS_PATCHSEGMENTS), state_patchsegments }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_POSITIONDEGREE), { STATE_RENDER(WINED3DRS_POSITIONDEGREE), state_positiondegree}, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_NORMALDEGREE), { STATE_RENDER(WINED3DRS_NORMALDEGREE), state_normaldegree }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_MINTESSELLATIONLEVEL), { STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_MAXTESSELLATIONLEVEL), { STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ADAPTIVETESS_X), { STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ADAPTIVETESS_Y), { STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ADAPTIVETESS_Z), { STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ADAPTIVETESS_W), { STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), { STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_nvdb }, EXT_DEPTH_BOUNDS_TEST }, - { STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), { STATE_RENDER(WINED3DRS_ENABLEADAPTIVETESSELLATION), state_tessellation }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_MULTISAMPLEANTIALIAS), { STATE_RENDER(WINED3DRS_MULTISAMPLEANTIALIAS), state_msaa }, ARB_MULTISAMPLE }, - { STATE_RENDER(WINED3DRS_MULTISAMPLEANTIALIAS), { STATE_RENDER(WINED3DRS_MULTISAMPLEANTIALIAS), state_msaa_w }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_MULTISAMPLEMASK), { STATE_RENDER(WINED3DRS_MULTISAMPLEMASK), state_multisampmask }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_DEBUGMONITORTOKEN), { STATE_RENDER(WINED3DRS_DEBUGMONITORTOKEN), state_debug_monitor }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_COLORWRITEENABLE), { STATE_RENDER(WINED3DRS_COLORWRITEENABLE), state_colorwrite0 }, EXT_DRAW_BUFFERS2 }, - { STATE_RENDER(WINED3DRS_COLORWRITEENABLE), { STATE_RENDER(WINED3DRS_COLORWRITEENABLE), state_colorwrite }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_BLENDOP), { STATE_RENDER(WINED3DRS_BLENDOP), state_blendop }, EXT_BLEND_MINMAX }, - { STATE_RENDER(WINED3DRS_BLENDOP), { STATE_RENDER(WINED3DRS_BLENDOP), state_blendop_w }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_SCISSORTESTENABLE), { STATE_RENDER(WINED3DRS_SCISSORTESTENABLE), state_scissor }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_SLOPESCALEDEPTHBIAS), { STATE_RENDER(WINED3DRS_DEPTHBIAS), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_COLORWRITEENABLE1), { STATE_RENDER(WINED3DRS_COLORWRITEENABLE1), state_colorwrite1 }, EXT_DRAW_BUFFERS2 }, - { STATE_RENDER(WINED3DRS_COLORWRITEENABLE1), { STATE_RENDER(WINED3DRS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_COLORWRITEENABLE2), { STATE_RENDER(WINED3DRS_COLORWRITEENABLE2), state_colorwrite2 }, EXT_DRAW_BUFFERS2 }, - { STATE_RENDER(WINED3DRS_COLORWRITEENABLE2), { STATE_RENDER(WINED3DRS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_COLORWRITEENABLE3), { STATE_RENDER(WINED3DRS_COLORWRITEENABLE3), state_colorwrite3 }, EXT_DRAW_BUFFERS2 }, - { STATE_RENDER(WINED3DRS_COLORWRITEENABLE3), { STATE_RENDER(WINED3DRS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_BLENDFACTOR), { STATE_RENDER(WINED3DRS_BLENDFACTOR), state_blendfactor }, EXT_BLEND_COLOR }, - { STATE_RENDER(WINED3DRS_BLENDFACTOR), { STATE_RENDER(WINED3DRS_BLENDFACTOR), state_blendfactor_w }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_DEPTHBIAS), { STATE_RENDER(WINED3DRS_DEPTHBIAS), state_depthbias }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_ZVISIBLE), { STATE_RENDER(WINED3DRS_ZVISIBLE), state_zvisible }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ANTIALIAS), { STATE_RENDER(WINED3D_RS_ANTIALIAS), state_antialias }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_TEXTUREPERSPECTIVE), { STATE_RENDER(WINED3D_RS_TEXTUREPERSPECTIVE), state_perspective }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ZENABLE), { STATE_RENDER(WINED3D_RS_ZENABLE), state_zenable }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAPU), { STATE_RENDER(WINED3D_RS_WRAPU), state_wrapu }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAPV), { STATE_RENDER(WINED3D_RS_WRAPV), state_wrapv }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FILLMODE), { STATE_RENDER(WINED3D_RS_FILLMODE), state_fillmode }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_SHADEMODE), { STATE_RENDER(WINED3D_RS_SHADEMODE), state_shademode }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_LINEPATTERN), { STATE_RENDER(WINED3D_RS_LINEPATTERN), state_linepattern }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_MONOENABLE), { STATE_RENDER(WINED3D_RS_MONOENABLE), state_monoenable }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ROP2), { STATE_RENDER(WINED3D_RS_ROP2), state_rop2 }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_PLANEMASK), { STATE_RENDER(WINED3D_RS_PLANEMASK), state_planemask }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ZWRITEENABLE), { STATE_RENDER(WINED3D_RS_ZWRITEENABLE), state_zwritenable }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), state_alpha }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ALPHAREF), { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ALPHAFUNC), { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_COLORKEYENABLE), { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_LASTPIXEL), { STATE_RENDER(WINED3D_RS_LASTPIXEL), state_lastpixel }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_CULLMODE), { STATE_RENDER(WINED3D_RS_CULLMODE), state_cullmode }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ZFUNC), { STATE_RENDER(WINED3D_RS_ZFUNC), state_zfunc }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_DITHERENABLE), { STATE_RENDER(WINED3D_RS_DITHERENABLE), state_ditherenable }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_SUBPIXEL), { STATE_RENDER(WINED3D_RS_SUBPIXEL), state_subpixel }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_SUBPIXELX), { STATE_RENDER(WINED3D_RS_SUBPIXELX), state_subpixelx }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_STIPPLEDALPHA), { STATE_RENDER(WINED3D_RS_STIPPLEDALPHA), state_stippledalpha }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_STIPPLEENABLE), { STATE_RENDER(WINED3D_RS_STIPPLEENABLE), state_stippleenable }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_MIPMAPLODBIAS), { STATE_RENDER(WINED3D_RS_MIPMAPLODBIAS), state_mipmaplodbias }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ANISOTROPY), { STATE_RENDER(WINED3D_RS_ANISOTROPY), state_anisotropy }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FLUSHBATCH), { STATE_RENDER(WINED3D_RS_FLUSHBATCH), state_flushbatch }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT),{ STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT),state_translucentsi }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_STENCILENABLE), { STATE_RENDER(WINED3D_RS_STENCILENABLE), state_stencil }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_STENCILFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_STENCILZFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_STENCILPASS), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_STENCILFUNC), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_STENCILREF), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_STENCILMASK), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), state_stencilwrite2s}, EXT_STENCIL_TWO_SIDE }, + { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), state_stencilwrite }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_TWOSIDEDSTENCILMODE), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_CCW_STENCILFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_CCW_STENCILZFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_CCW_STENCILPASS), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_CCW_STENCILFUNC), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAP0), { STATE_RENDER(WINED3D_RS_WRAP0), state_wrap }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAP1), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAP2), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAP3), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAP4), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAP5), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAP6), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAP7), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAP8), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAP9), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAP10), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAP11), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAP12), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAP13), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAP14), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_WRAP15), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_EXTENTS), { STATE_RENDER(WINED3D_RS_EXTENTS), state_extents }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_COLORKEYBLENDENABLE), { STATE_RENDER(WINED3D_RS_COLORKEYBLENDENABLE), state_ckeyblend }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_SOFTWAREVERTEXPROCESSING), { STATE_RENDER(WINED3D_RS_SOFTWAREVERTEXPROCESSING), state_swvp }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_PATCHEDGESTYLE), { STATE_RENDER(WINED3D_RS_PATCHEDGESTYLE), state_patchedgestyle}, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_PATCHSEGMENTS), { STATE_RENDER(WINED3D_RS_PATCHSEGMENTS), state_patchsegments }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_POSITIONDEGREE), { STATE_RENDER(WINED3D_RS_POSITIONDEGREE), state_positiondegree}, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_NORMALDEGREE), { STATE_RENDER(WINED3D_RS_NORMALDEGREE), state_normaldegree }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_MINTESSELLATIONLEVEL), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_MAXTESSELLATIONLEVEL), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_X), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_Y), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_Z), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_W), { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),{ STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),state_nvdb }, EXT_DEPTH_BOUNDS_TEST }, + { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),{ STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),state_tessellation }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), state_msaa }, ARB_MULTISAMPLE }, + { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), state_msaa_w }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_MULTISAMPLEMASK), { STATE_RENDER(WINED3D_RS_MULTISAMPLEMASK), state_multisampmask }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_DEBUGMONITORTOKEN), { STATE_RENDER(WINED3D_RS_DEBUGMONITORTOKEN), state_debug_monitor }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), state_colorwrite0 }, EXT_DRAW_BUFFERS2 }, + { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), state_colorwrite }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_BLENDOP), { STATE_RENDER(WINED3D_RS_BLENDOP), state_blendop }, EXT_BLEND_MINMAX }, + { STATE_RENDER(WINED3D_RS_BLENDOP), { STATE_RENDER(WINED3D_RS_BLENDOP), state_blendop_w }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE), { STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE), state_scissor }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_SLOPESCALEDEPTHBIAS), { STATE_RENDER(WINED3D_RS_DEPTHBIAS), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1), state_colorwrite1 }, EXT_DRAW_BUFFERS2 }, + { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2), state_colorwrite2 }, EXT_DRAW_BUFFERS2 }, + { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3), state_colorwrite3 }, EXT_DRAW_BUFFERS2 }, + { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_BLENDFACTOR), { STATE_RENDER(WINED3D_RS_BLENDFACTOR), state_blendfactor }, EXT_BLEND_COLOR }, + { STATE_RENDER(WINED3D_RS_BLENDFACTOR), { STATE_RENDER(WINED3D_RS_BLENDFACTOR), state_blendfactor_w }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_DEPTHBIAS), { STATE_RENDER(WINED3D_RS_DEPTHBIAS), state_depthbias }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_ZVISIBLE), { STATE_RENDER(WINED3D_RS_ZVISIBLE), state_zvisible }, WINED3D_GL_EXT_NONE }, /* Samplers */ { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler }, WINED3D_GL_EXT_NONE }, { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler }, WINED3D_GL_EXT_NONE }, @@ -5075,14 +5078,18 @@ const struct StateEntryTemplate misc_state_template[] = { { STATE_SAMPLER(17), /* Vertex sampler 1 */ { STATE_SAMPLER(17), sampler }, WINED3D_GL_EXT_NONE }, { STATE_SAMPLER(18), /* Vertex sampler 2 */ { STATE_SAMPLER(18), sampler }, WINED3D_GL_EXT_NONE }, { STATE_SAMPLER(19), /* Vertex sampler 3 */ { STATE_SAMPLER(19), sampler }, WINED3D_GL_EXT_NONE }, + { STATE_BASEVERTEXINDEX, { STATE_BASEVERTEXINDEX, state_nop, }, ARB_DRAW_ELEMENTS_BASE_VERTEX }, + { STATE_BASEVERTEXINDEX, { STATE_STREAMSRC, NULL, }, WINED3D_GL_EXT_NONE }, + { STATE_FRAMEBUFFER, { STATE_FRAMEBUFFER, context_state_fb }, WINED3D_GL_EXT_NONE }, + { STATE_PIXELSHADER, { STATE_PIXELSHADER, context_state_drawbuf},WINED3D_GL_EXT_NONE }, {0 /* Terminate */, { 0, 0 }, WINED3D_GL_EXT_NONE }, }; const struct StateEntryTemplate ffp_vertexstate_template[] = { { STATE_VDECL, { STATE_VDECL, vertexdeclaration }, WINED3D_GL_EXT_NONE }, { STATE_VSHADER, { STATE_VDECL, NULL }, WINED3D_GL_EXT_NONE }, - { STATE_MATERIAL, { STATE_RENDER(WINED3DRS_SPECULARENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_SPECULARENABLE), { STATE_RENDER(WINED3DRS_SPECULARENABLE), state_specularenable}, WINED3D_GL_EXT_NONE }, + { STATE_MATERIAL, { STATE_RENDER(WINED3D_RS_SPECULARENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_SPECULARENABLE), { STATE_RENDER(WINED3D_RS_SPECULARENABLE), state_specularenable}, WINED3D_GL_EXT_NONE }, /* Clip planes */ { STATE_CLIPPLANE(0), { STATE_CLIPPLANE(0), clipplane }, WINED3D_GL_EXT_NONE }, { STATE_CLIPPLANE(1), { STATE_CLIPPLANE(1), clipplane }, WINED3D_GL_EXT_NONE }, @@ -5128,322 +5135,321 @@ const struct StateEntryTemplate ffp_vertexstate_template[] = { /* Viewport */ { STATE_VIEWPORT, { STATE_VIEWPORT, viewport_vertexpart }, WINED3D_GL_EXT_NONE }, /* Transform states follow */ - { STATE_TRANSFORM(WINED3DTS_VIEW), { STATE_TRANSFORM(WINED3DTS_VIEW), transform_view }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_PROJECTION), { STATE_TRANSFORM(WINED3DTS_PROJECTION), transform_projection}, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_TEXTURE0), { STATE_TEXTURESTAGE(0,WINED3DTSS_TEXTURETRANSFORMFLAGS), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_TEXTURE1), { STATE_TEXTURESTAGE(1,WINED3DTSS_TEXTURETRANSFORMFLAGS), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_TEXTURE2), { STATE_TEXTURESTAGE(2,WINED3DTSS_TEXTURETRANSFORMFLAGS), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_TEXTURE3), { STATE_TEXTURESTAGE(3,WINED3DTSS_TEXTURETRANSFORMFLAGS), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_TEXTURE4), { STATE_TEXTURESTAGE(4,WINED3DTSS_TEXTURETRANSFORMFLAGS), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_TEXTURE5), { STATE_TEXTURESTAGE(5,WINED3DTSS_TEXTURETRANSFORMFLAGS), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_TEXTURE6), { STATE_TEXTURESTAGE(6,WINED3DTSS_TEXTURETRANSFORMFLAGS), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_TEXTURE7), { STATE_TEXTURESTAGE(7,WINED3DTSS_TEXTURETRANSFORMFLAGS), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 0)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 0)), transform_world }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 1)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 1)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 2)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 2)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 3)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 3)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 4)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 4)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 5)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 5)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 6)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 6)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 7)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 7)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 8)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 8)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 9)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 9)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 10)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 10)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 11)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 11)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 12)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 12)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 13)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 13)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 14)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 14)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 15)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 15)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 16)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 16)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 17)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 17)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 18)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 18)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 19)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 19)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 20)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 20)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 21)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 21)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 22)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 22)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 23)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 23)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 24)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 24)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 25)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 25)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 26)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 26)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 27)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 27)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 28)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 28)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 29)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 29)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 30)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 30)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 31)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 31)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 32)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 32)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 33)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 33)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 34)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 34)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 35)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 35)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 36)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 36)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 37)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 37)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 38)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 38)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 39)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 39)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 40)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 40)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 41)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 41)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 42)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 42)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 43)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 43)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 44)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 44)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 45)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 45)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 46)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 46)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 47)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 47)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 48)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 48)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 49)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 49)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 50)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 50)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 51)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 51)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 52)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 52)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 53)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 53)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 54)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 54)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 55)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 55)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 56)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 56)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 57)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 57)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 58)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 58)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 59)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 59)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 60)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 60)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 61)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 61)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 62)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 62)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 63)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 63)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 64)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 64)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 65)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 65)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 66)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 66)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 67)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 67)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 68)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 68)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 69)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 69)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 70)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 70)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 71)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 71)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 72)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 72)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 73)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 73)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 74)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 74)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 75)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 75)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 76)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 76)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 77)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 77)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 78)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 78)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 79)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 79)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 80)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 80)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 81)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 81)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 82)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 82)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 83)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 83)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 84)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 84)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 85)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 85)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 86)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 86)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 87)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 87)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 88)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 88)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 89)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 89)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 90)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 90)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 91)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 91)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 92)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 92)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 93)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 93)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 94)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 94)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 95)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 95)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 96)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 96)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 97)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 97)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 98)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 98)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 99)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX( 99)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(100)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(100)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(101)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(101)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(102)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(102)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(103)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(103)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(104)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(104)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(105)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(105)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(106)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(106)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(107)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(107)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(108)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(108)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(109)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(109)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(110)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(110)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(111)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(111)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(112)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(112)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(113)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(113)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(114)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(114)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(115)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(115)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(116)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(116)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(117)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(117)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(118)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(118)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(119)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(119)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(120)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(120)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(121)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(121)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(122)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(122)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(123)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(123)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(124)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(124)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(125)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(125)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(126)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(126)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(127)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(127)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(128)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(128)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(129)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(129)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(130)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(130)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(131)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(131)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(132)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(132)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(133)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(133)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(134)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(134)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(135)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(135)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(136)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(136)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(137)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(137)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(138)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(138)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(139)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(139)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(140)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(140)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(141)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(141)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(142)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(142)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(143)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(143)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(144)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(144)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(145)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(145)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(146)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(146)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(147)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(147)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(148)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(148)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(149)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(149)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(150)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(150)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(151)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(151)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(152)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(152)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(153)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(153)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(154)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(154)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(155)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(155)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(156)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(156)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(157)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(157)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(158)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(158)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(159)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(159)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(160)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(160)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(161)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(161)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(162)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(162)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(163)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(163)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(164)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(164)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(165)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(165)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(166)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(166)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(167)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(167)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(168)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(168)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(169)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(169)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(170)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(170)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(171)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(171)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(172)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(172)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(173)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(173)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(174)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(174)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(175)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(175)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(176)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(176)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(177)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(177)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(178)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(178)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(179)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(179)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(180)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(180)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(181)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(181)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(182)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(182)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(183)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(183)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(184)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(184)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(185)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(185)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(186)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(186)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(187)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(187)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(188)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(188)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(189)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(189)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(190)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(190)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(191)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(191)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(192)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(192)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(193)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(193)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(194)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(194)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(195)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(195)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(196)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(196)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(197)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(197)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(198)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(198)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(199)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(199)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(200)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(200)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(201)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(201)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(202)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(202)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(203)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(203)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(204)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(204)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(205)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(205)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(206)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(206)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(207)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(207)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(208)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(208)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(209)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(209)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(210)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(210)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(211)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(211)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(212)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(212)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(213)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(213)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(214)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(214)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(215)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(215)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(216)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(216)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(217)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(217)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(218)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(218)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(219)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(219)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(220)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(220)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(221)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(221)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(222)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(222)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(223)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(223)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(224)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(224)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(225)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(225)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(226)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(226)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(227)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(227)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(228)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(228)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(229)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(229)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(230)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(230)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(231)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(231)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(232)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(232)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(233)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(233)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(234)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(234)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(235)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(235)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(236)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(236)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(237)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(237)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(238)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(238)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(239)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(239)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(240)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(240)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(241)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(241)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(242)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(242)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(243)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(243)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(244)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(244)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(245)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(245)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(246)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(246)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(247)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(247)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(248)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(248)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(249)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(249)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(250)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(250)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(251)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(251)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(252)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(252)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(253)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(253)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(254)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(254)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)), { STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)), transform_worldex }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(0,WINED3DTSS_TEXTURETRANSFORMFLAGS),transform_texture }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(1,WINED3DTSS_TEXTURETRANSFORMFLAGS),transform_texture }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(2,WINED3DTSS_TEXTURETRANSFORMFLAGS),transform_texture }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(3,WINED3DTSS_TEXTURETRANSFORMFLAGS),transform_texture }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(4,WINED3DTSS_TEXTURETRANSFORMFLAGS),transform_texture }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(5,WINED3DTSS_TEXTURETRANSFORMFLAGS),transform_texture }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(6,WINED3DTSS_TEXTURETRANSFORMFLAGS),transform_texture }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(7,WINED3DTSS_TEXTURETRANSFORMFLAGS),transform_texture }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_TEXCOORDINDEX), { STATE_TEXTURESTAGE(0, WINED3DTSS_TEXCOORDINDEX), tex_coordindex }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_TEXCOORDINDEX), { STATE_TEXTURESTAGE(1, WINED3DTSS_TEXCOORDINDEX), tex_coordindex }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_TEXCOORDINDEX), { STATE_TEXTURESTAGE(2, WINED3DTSS_TEXCOORDINDEX), tex_coordindex }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_TEXCOORDINDEX), { STATE_TEXTURESTAGE(3, WINED3DTSS_TEXCOORDINDEX), tex_coordindex }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_TEXCOORDINDEX), { STATE_TEXTURESTAGE(4, WINED3DTSS_TEXCOORDINDEX), tex_coordindex }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_TEXCOORDINDEX), { STATE_TEXTURESTAGE(5, WINED3DTSS_TEXCOORDINDEX), tex_coordindex }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_TEXCOORDINDEX), { STATE_TEXTURESTAGE(6, WINED3DTSS_TEXCOORDINDEX), tex_coordindex }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_TEXCOORDINDEX), { STATE_TEXTURESTAGE(7, WINED3DTSS_TEXCOORDINDEX), tex_coordindex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_VIEW), { STATE_TRANSFORM(WINED3D_TS_VIEW), transform_view }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_PROJECTION), { STATE_TRANSFORM(WINED3D_TS_PROJECTION), transform_projection}, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_TEXTURE0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_TEXTURE1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_TEXTURE2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_TEXTURE3), { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_TEXTURE4), { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_TEXTURE5), { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_TEXTURE6), { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_TEXTURE7), { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 0)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 0)), transform_world }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 1)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 1)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 2)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 2)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 3)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 3)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 4)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 4)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 5)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 5)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 6)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 6)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 7)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 7)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 8)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 8)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 9)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 9)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 10)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 10)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 11)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 11)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 12)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 12)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 13)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 13)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 14)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 14)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 15)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 15)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 16)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 16)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 17)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 17)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 18)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 18)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 19)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 19)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 20)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 20)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 21)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 21)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 22)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 22)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 23)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 23)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 24)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 24)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 25)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 25)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 26)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 26)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 27)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 27)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 28)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 28)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 29)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 29)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 30)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 30)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 31)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 31)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 32)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 32)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 33)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 33)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 34)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 34)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 35)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 35)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 36)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 36)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 37)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 37)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 38)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 38)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 39)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 39)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 40)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 40)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 41)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 41)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 42)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 42)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 43)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 43)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 44)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 44)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 45)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 45)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 46)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 46)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 47)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 47)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 48)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 48)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 49)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 49)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 50)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 50)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 51)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 51)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 52)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 52)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 53)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 53)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 54)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 54)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 55)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 55)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 56)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 56)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 57)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 57)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 58)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 58)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 59)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 59)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 60)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 60)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 61)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 61)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 62)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 62)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 63)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 63)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 64)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 64)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 65)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 65)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 66)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 66)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 67)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 67)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 68)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 68)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 69)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 69)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 70)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 70)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 71)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 71)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 72)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 72)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 73)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 73)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 74)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 74)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 75)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 75)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 76)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 76)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 77)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 77)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 78)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 78)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 79)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 79)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 80)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 80)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 81)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 81)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 82)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 82)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 83)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 83)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 84)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 84)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 85)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 85)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 86)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 86)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 87)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 87)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 88)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 88)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 89)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 89)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 90)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 90)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 91)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 91)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 92)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 92)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 93)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 93)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 94)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 94)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 95)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 95)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 96)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 96)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 97)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 97)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 98)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 98)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 99)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 99)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(100)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(100)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(101)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(101)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(102)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(102)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(103)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(103)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(104)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(104)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(105)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(105)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(106)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(106)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(107)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(107)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(108)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(108)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(109)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(109)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(110)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(110)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(111)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(111)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(112)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(112)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(113)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(113)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(114)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(114)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(115)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(115)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(116)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(116)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(117)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(117)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(118)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(118)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(119)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(119)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(120)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(120)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(121)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(121)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(122)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(122)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(123)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(123)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(124)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(124)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(125)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(125)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(126)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(126)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(127)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(127)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(128)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(128)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(129)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(129)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(130)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(130)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(131)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(131)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(132)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(132)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(133)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(133)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(134)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(134)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(135)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(135)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(136)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(136)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(137)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(137)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(138)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(138)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(139)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(139)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(140)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(140)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(141)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(141)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(142)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(142)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(143)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(143)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(144)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(144)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(145)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(145)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(146)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(146)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(147)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(147)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(148)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(148)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(149)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(149)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(150)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(150)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(151)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(151)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(152)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(152)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(153)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(153)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(154)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(154)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(155)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(155)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(156)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(156)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(157)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(157)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(158)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(158)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(159)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(159)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(160)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(160)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(161)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(161)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(162)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(162)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(163)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(163)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(164)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(164)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(165)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(165)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(166)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(166)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(167)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(167)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(168)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(168)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(169)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(169)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(170)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(170)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(171)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(171)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(172)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(172)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(173)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(173)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(174)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(174)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(175)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(175)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(176)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(176)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(177)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(177)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(178)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(178)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(179)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(179)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(180)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(180)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(181)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(181)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(182)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(182)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(183)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(183)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(184)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(184)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(185)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(185)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(186)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(186)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(187)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(187)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(188)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(188)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(189)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(189)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(190)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(190)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(191)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(191)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(192)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(192)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(193)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(193)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(194)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(194)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(195)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(195)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(196)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(196)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(197)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(197)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(198)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(198)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(199)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(199)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(200)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(200)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(201)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(201)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(202)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(202)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(203)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(203)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(204)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(204)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(205)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(205)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(206)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(206)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(207)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(207)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(208)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(208)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(209)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(209)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(210)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(210)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(211)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(211)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(212)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(212)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(213)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(213)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(214)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(214)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(215)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(215)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(216)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(216)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(217)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(217)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(218)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(218)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(219)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(219)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(220)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(220)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(221)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(221)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(222)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(222)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(223)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(223)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(224)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(224)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(225)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(225)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(226)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(226)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(227)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(227)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(228)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(228)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(229)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(229)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(230)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(230)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(231)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(231)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(232)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(232)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(233)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(233)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(234)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(234)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(235)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(235)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(236)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(236)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(237)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(237)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(238)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(238)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(239)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(239)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(240)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(240)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(241)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(241)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(242)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(242)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(243)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(243)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(244)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(244)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(245)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(245)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(246)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(246)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(247)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(247)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(248)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(248)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(249)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(249)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(250)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(250)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(251)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(251)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(252)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(252)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(253)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(253)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(254)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(254)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)), { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)), transform_worldex }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXCOORD_INDEX), { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXCOORD_INDEX), tex_coordindex }, WINED3D_GL_EXT_NONE }, /* Fog */ - { STATE_RENDER(WINED3DRS_FOGENABLE), { STATE_RENDER(WINED3DRS_FOGENABLE), state_fog_vertexpart}, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FOGTABLEMODE), { STATE_RENDER(WINED3DRS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FOGVERTEXMODE), { STATE_RENDER(WINED3DRS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_RANGEFOGENABLE), { STATE_RENDER(WINED3DRS_RANGEFOGENABLE), state_rangefog }, NV_FOG_DISTANCE }, - { STATE_RENDER(WINED3DRS_RANGEFOGENABLE), { STATE_RENDER(WINED3DRS_RANGEFOGENABLE), state_rangefog_w }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_CLIPPING), { STATE_RENDER(WINED3DRS_CLIPPING), state_clipping }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_CLIPPLANEENABLE), { STATE_RENDER(WINED3DRS_CLIPPING), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_LIGHTING), { STATE_RENDER(WINED3DRS_LIGHTING), state_lighting }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_AMBIENT), { STATE_RENDER(WINED3DRS_AMBIENT), state_ambient }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_COLORVERTEX), { STATE_RENDER(WINED3DRS_COLORVERTEX), state_colormat }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_LOCALVIEWER), { STATE_RENDER(WINED3DRS_LOCALVIEWER), state_localviewer }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_NORMALIZENORMALS), { STATE_RENDER(WINED3DRS_NORMALIZENORMALS), state_normalize }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_DIFFUSEMATERIALSOURCE), { STATE_RENDER(WINED3DRS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_SPECULARMATERIALSOURCE), { STATE_RENDER(WINED3DRS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_AMBIENTMATERIALSOURCE), { STATE_RENDER(WINED3DRS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_EMISSIVEMATERIALSOURCE), { STATE_RENDER(WINED3DRS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_VERTEXBLEND), { STATE_RENDER(WINED3DRS_VERTEXBLEND), state_vertexblend }, ARB_VERTEX_BLEND }, - { STATE_RENDER(WINED3DRS_VERTEXBLEND), { STATE_RENDER(WINED3DRS_VERTEXBLEND), state_vertexblend_w }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_POINTSIZE), { STATE_RENDER(WINED3DRS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_POINTSIZE_MIN), { STATE_RENDER(WINED3DRS_POINTSIZE_MIN), state_psizemin_arb }, ARB_POINT_PARAMETERS }, - { STATE_RENDER(WINED3DRS_POINTSIZE_MIN), { STATE_RENDER(WINED3DRS_POINTSIZE_MIN), state_psizemin_ext }, EXT_POINT_PARAMETERS }, - { STATE_RENDER(WINED3DRS_POINTSIZE_MIN), { STATE_RENDER(WINED3DRS_POINTSIZE_MIN), state_psizemin_w }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_POINTSPRITEENABLE), { STATE_RENDER(WINED3DRS_POINTSPRITEENABLE), state_pointsprite }, ARB_POINT_SPRITE }, - { STATE_RENDER(WINED3DRS_POINTSPRITEENABLE), { STATE_RENDER(WINED3DRS_POINTSPRITEENABLE), state_pointsprite_w }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_POINTSCALEENABLE), { STATE_RENDER(WINED3DRS_POINTSCALEENABLE), state_pscale }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_POINTSCALE_A), { STATE_RENDER(WINED3DRS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_POINTSCALE_B), { STATE_RENDER(WINED3DRS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_POINTSCALE_C), { STATE_RENDER(WINED3DRS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_POINTSIZE_MAX), { STATE_RENDER(WINED3DRS_POINTSIZE_MIN), NULL }, ARB_POINT_PARAMETERS }, - { STATE_RENDER(WINED3DRS_POINTSIZE_MAX), { STATE_RENDER(WINED3DRS_POINTSIZE_MIN), NULL }, EXT_POINT_PARAMETERS }, - { STATE_RENDER(WINED3DRS_POINTSIZE_MAX), { STATE_RENDER(WINED3DRS_POINTSIZE_MIN), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_TWEENFACTOR), { STATE_RENDER(WINED3DRS_VERTEXBLEND), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_INDEXEDVERTEXBLENDENABLE), { STATE_RENDER(WINED3DRS_VERTEXBLEND), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), state_fog_vertexpart}, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGTABLEMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGVERTEXMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_RANGEFOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_CLIPPING), { STATE_RENDER(WINED3D_RS_CLIPPING), state_clipping }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_CLIPPLANEENABLE), { STATE_RENDER(WINED3D_RS_CLIPPING), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_LIGHTING), { STATE_RENDER(WINED3D_RS_LIGHTING), state_lighting }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_AMBIENT), { STATE_RENDER(WINED3D_RS_AMBIENT), state_ambient }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_COLORVERTEX), { STATE_RENDER(WINED3D_RS_COLORVERTEX), state_colormat }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_LOCALVIEWER), { STATE_RENDER(WINED3D_RS_LOCALVIEWER), state_localviewer }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_NORMALIZENORMALS), { STATE_RENDER(WINED3D_RS_NORMALIZENORMALS), state_normalize }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_DIFFUSEMATERIALSOURCE), { STATE_RENDER(WINED3D_RS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_SPECULARMATERIALSOURCE), { STATE_RENDER(WINED3D_RS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_AMBIENTMATERIALSOURCE), { STATE_RENDER(WINED3D_RS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_EMISSIVEMATERIALSOURCE), { STATE_RENDER(WINED3D_RS_COLORVERTEX), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_VERTEXBLEND), { STATE_RENDER(WINED3D_RS_VERTEXBLEND), state_vertexblend }, ARB_VERTEX_BLEND }, + { STATE_RENDER(WINED3D_RS_VERTEXBLEND), { STATE_RENDER(WINED3D_RS_VERTEXBLEND), state_vertexblend_w }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_POINTSIZE), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), state_psizemin_arb }, ARB_POINT_PARAMETERS }, + { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), state_psizemin_ext }, EXT_POINT_PARAMETERS }, + { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), state_psizemin_w }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), state_pointsprite }, ARB_POINT_SPRITE }, + { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), state_pointsprite_w }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), state_pscale }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_POINTSCALE_A), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_POINTSCALE_B), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_POINTSCALE_C), { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_POINTSIZE_MAX), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), NULL }, ARB_POINT_PARAMETERS }, + { STATE_RENDER(WINED3D_RS_POINTSIZE_MAX), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), NULL }, EXT_POINT_PARAMETERS }, + { STATE_RENDER(WINED3D_RS_POINTSIZE_MAX), { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_TWEENFACTOR), { STATE_RENDER(WINED3D_RS_VERTEXBLEND), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_INDEXEDVERTEXBLENDENABLE), { STATE_RENDER(WINED3D_RS_VERTEXBLEND), NULL }, WINED3D_GL_EXT_NONE }, /* Samplers for NP2 texture matrix adjustions. They are not needed if GL_ARB_texture_non_power_of_two is supported, * so register a NULL state handler in that case to get the vertex part of sampler() skipped(VTF is handled in the misc states. @@ -5477,96 +5483,96 @@ const struct StateEntryTemplate ffp_vertexstate_template[] = { }; static const struct StateEntryTemplate ffp_fragmentstate_template[] = { - { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), tex_colorop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(0, WINED3DTSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), tex_colorop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(1, WINED3DTSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), tex_colorop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(2, WINED3DTSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), tex_colorop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(3, WINED3DTSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), tex_colorop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(4, WINED3DTSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), tex_colorop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(5, WINED3DTSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), tex_colorop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(6, WINED3DTSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), tex_colorop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_TEXTURESTAGE(7, WINED3DTSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(0, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(1, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(2, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(3, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(4, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(5, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(6, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), tex_colorop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_TEXTURESTAGE(7, WINED3D_TSS_CONSTANT), { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL }, WINED3D_GL_EXT_NONE }, { STATE_PIXELSHADER, { STATE_PIXELSHADER, apply_pixelshader }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_SRGBWRITEENABLE), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_TEXTUREFACTOR), { STATE_RENDER(WINED3DRS_TEXTUREFACTOR), state_texfactor }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FOGCOLOR), { STATE_RENDER(WINED3DRS_FOGCOLOR), state_fogcolor }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FOGDENSITY), { STATE_RENDER(WINED3DRS_FOGDENSITY), state_fogdensity }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FOGENABLE), { STATE_RENDER(WINED3DRS_FOGENABLE), state_fog_fragpart }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FOGTABLEMODE), { STATE_RENDER(WINED3DRS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FOGVERTEXMODE), { STATE_RENDER(WINED3DRS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FOGSTART), { STATE_RENDER(WINED3DRS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3DRS_FOGEND), { STATE_RENDER(WINED3DRS_FOGSTART), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), state_texfactor }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGCOLOR), { STATE_RENDER(WINED3D_RS_FOGCOLOR), state_fogcolor }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGDENSITY), { STATE_RENDER(WINED3D_RS_FOGDENSITY), state_fogdensity }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), state_fog_fragpart }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGTABLEMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGVERTEXMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGSTART), { STATE_RENDER(WINED3D_RS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_FOGEND), { STATE_RENDER(WINED3D_RS_FOGSTART), NULL }, WINED3D_GL_EXT_NONE }, { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler_texdim }, WINED3D_GL_EXT_NONE }, { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler_texdim }, WINED3D_GL_EXT_NONE }, { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler_texdim }, WINED3D_GL_EXT_NONE }, @@ -5659,17 +5665,17 @@ static unsigned int num_handlers(const APPLYSTATEFUNC *funcs) return i; } -static void multistate_apply_2(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void multistate_apply_2(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - stateblock->device->multistate_funcs[state][0](state, stateblock, context); - stateblock->device->multistate_funcs[state][1](state, stateblock, context); + context->swapchain->device->multistate_funcs[state_id][0](context, state, state_id); + context->swapchain->device->multistate_funcs[state_id][1](context, state, state_id); } -static void multistate_apply_3(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +static void multistate_apply_3(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - stateblock->device->multistate_funcs[state][0](state, stateblock, context); - stateblock->device->multistate_funcs[state][1](state, stateblock, context); - stateblock->device->multistate_funcs[state][2](state, stateblock, context); + context->swapchain->device->multistate_funcs[state_id][0](context, state, state_id); + context->swapchain->device->multistate_funcs[state_id][1](context, state, state_id); + context->swapchain->device->multistate_funcs[state_id][2](context, state, state_id); } static void prune_invalid_states(struct StateEntry *state_table, const struct wined3d_gl_info *gl_info) @@ -5684,16 +5690,16 @@ static void prune_invalid_states(struct StateEntry *state_table, const struct wi state_table[i].apply = state_undefined; } - start = STATE_TRANSFORM(WINED3DTS_TEXTURE0 + gl_info->limits.texture_stages); - last = STATE_TRANSFORM(WINED3DTS_TEXTURE0 + MAX_TEXTURES - 1); + start = STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + gl_info->limits.texture_stages); + last = STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + MAX_TEXTURES - 1); for (i = start; i <= last; ++i) { state_table[i].representative = 0; state_table[i].apply = state_undefined; } - start = STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(gl_info->limits.blends)); - last = STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)); + start = STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(gl_info->limits.blends)); + last = STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)); for (i = start; i <= last; ++i) { state_table[i].representative = 0; @@ -5737,6 +5743,8 @@ static void validate_state_table(struct StateEntry *state_table) STATE_SCISSORRECT, STATE_FRONTFACE, STATE_POINTSPRITECOORDORIGIN, + STATE_BASEVERTEXINDEX, + STATE_FRAMEBUFFER }; unsigned int i, current; diff --git a/reactos/dll/directx/wine/wined3d/stateblock.c b/reactos/dll/directx/wine/wined3d/stateblock.c index 5beea287376..b00fb84c18c 100644 --- a/reactos/dll/directx/wine/wined3d/stateblock.c +++ b/reactos/dll/directx/wine/wined3d/stateblock.c @@ -29,163 +29,163 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d); static const DWORD pixel_states_render[] = { - WINED3DRS_ALPHABLENDENABLE, - WINED3DRS_ALPHAFUNC, - WINED3DRS_ALPHAREF, - WINED3DRS_ALPHATESTENABLE, - WINED3DRS_ANTIALIASEDLINEENABLE, - WINED3DRS_BLENDFACTOR, - WINED3DRS_BLENDOP, - WINED3DRS_BLENDOPALPHA, - WINED3DRS_CCW_STENCILFAIL, - WINED3DRS_CCW_STENCILPASS, - WINED3DRS_CCW_STENCILZFAIL, - WINED3DRS_COLORWRITEENABLE, - WINED3DRS_COLORWRITEENABLE1, - WINED3DRS_COLORWRITEENABLE2, - WINED3DRS_COLORWRITEENABLE3, - WINED3DRS_DEPTHBIAS, - WINED3DRS_DESTBLEND, - WINED3DRS_DESTBLENDALPHA, - WINED3DRS_DITHERENABLE, - WINED3DRS_FILLMODE, - WINED3DRS_FOGDENSITY, - WINED3DRS_FOGEND, - WINED3DRS_FOGSTART, - WINED3DRS_LASTPIXEL, - WINED3DRS_SCISSORTESTENABLE, - WINED3DRS_SEPARATEALPHABLENDENABLE, - WINED3DRS_SHADEMODE, - WINED3DRS_SLOPESCALEDEPTHBIAS, - WINED3DRS_SRCBLEND, - WINED3DRS_SRCBLENDALPHA, - WINED3DRS_SRGBWRITEENABLE, - WINED3DRS_STENCILENABLE, - WINED3DRS_STENCILFAIL, - WINED3DRS_STENCILFUNC, - WINED3DRS_STENCILMASK, - WINED3DRS_STENCILPASS, - WINED3DRS_STENCILREF, - WINED3DRS_STENCILWRITEMASK, - WINED3DRS_STENCILZFAIL, - WINED3DRS_TEXTUREFACTOR, - WINED3DRS_TWOSIDEDSTENCILMODE, - WINED3DRS_WRAP0, - WINED3DRS_WRAP1, - WINED3DRS_WRAP10, - WINED3DRS_WRAP11, - WINED3DRS_WRAP12, - WINED3DRS_WRAP13, - WINED3DRS_WRAP14, - WINED3DRS_WRAP15, - WINED3DRS_WRAP2, - WINED3DRS_WRAP3, - WINED3DRS_WRAP4, - WINED3DRS_WRAP5, - WINED3DRS_WRAP6, - WINED3DRS_WRAP7, - WINED3DRS_WRAP8, - WINED3DRS_WRAP9, - WINED3DRS_ZENABLE, - WINED3DRS_ZFUNC, - WINED3DRS_ZWRITEENABLE, + WINED3D_RS_ALPHABLENDENABLE, + WINED3D_RS_ALPHAFUNC, + WINED3D_RS_ALPHAREF, + WINED3D_RS_ALPHATESTENABLE, + WINED3D_RS_ANTIALIASEDLINEENABLE, + WINED3D_RS_BLENDFACTOR, + WINED3D_RS_BLENDOP, + WINED3D_RS_BLENDOPALPHA, + WINED3D_RS_CCW_STENCILFAIL, + WINED3D_RS_CCW_STENCILPASS, + WINED3D_RS_CCW_STENCILZFAIL, + WINED3D_RS_COLORWRITEENABLE, + WINED3D_RS_COLORWRITEENABLE1, + WINED3D_RS_COLORWRITEENABLE2, + WINED3D_RS_COLORWRITEENABLE3, + WINED3D_RS_DEPTHBIAS, + WINED3D_RS_DESTBLEND, + WINED3D_RS_DESTBLENDALPHA, + WINED3D_RS_DITHERENABLE, + WINED3D_RS_FILLMODE, + WINED3D_RS_FOGDENSITY, + WINED3D_RS_FOGEND, + WINED3D_RS_FOGSTART, + WINED3D_RS_LASTPIXEL, + WINED3D_RS_SCISSORTESTENABLE, + WINED3D_RS_SEPARATEALPHABLENDENABLE, + WINED3D_RS_SHADEMODE, + WINED3D_RS_SLOPESCALEDEPTHBIAS, + WINED3D_RS_SRCBLEND, + WINED3D_RS_SRCBLENDALPHA, + WINED3D_RS_SRGBWRITEENABLE, + WINED3D_RS_STENCILENABLE, + WINED3D_RS_STENCILFAIL, + WINED3D_RS_STENCILFUNC, + WINED3D_RS_STENCILMASK, + WINED3D_RS_STENCILPASS, + WINED3D_RS_STENCILREF, + WINED3D_RS_STENCILWRITEMASK, + WINED3D_RS_STENCILZFAIL, + WINED3D_RS_TEXTUREFACTOR, + WINED3D_RS_TWOSIDEDSTENCILMODE, + WINED3D_RS_WRAP0, + WINED3D_RS_WRAP1, + WINED3D_RS_WRAP10, + WINED3D_RS_WRAP11, + WINED3D_RS_WRAP12, + WINED3D_RS_WRAP13, + WINED3D_RS_WRAP14, + WINED3D_RS_WRAP15, + WINED3D_RS_WRAP2, + WINED3D_RS_WRAP3, + WINED3D_RS_WRAP4, + WINED3D_RS_WRAP5, + WINED3D_RS_WRAP6, + WINED3D_RS_WRAP7, + WINED3D_RS_WRAP8, + WINED3D_RS_WRAP9, + WINED3D_RS_ZENABLE, + WINED3D_RS_ZFUNC, + WINED3D_RS_ZWRITEENABLE, }; static const DWORD pixel_states_texture[] = { - WINED3DTSS_ALPHAARG0, - WINED3DTSS_ALPHAARG1, - WINED3DTSS_ALPHAARG2, - WINED3DTSS_ALPHAOP, - WINED3DTSS_BUMPENVLOFFSET, - WINED3DTSS_BUMPENVLSCALE, - WINED3DTSS_BUMPENVMAT00, - WINED3DTSS_BUMPENVMAT01, - WINED3DTSS_BUMPENVMAT10, - WINED3DTSS_BUMPENVMAT11, - WINED3DTSS_COLORARG0, - WINED3DTSS_COLORARG1, - WINED3DTSS_COLORARG2, - WINED3DTSS_COLOROP, - WINED3DTSS_RESULTARG, - WINED3DTSS_TEXCOORDINDEX, - WINED3DTSS_TEXTURETRANSFORMFLAGS, + WINED3D_TSS_ALPHA_ARG0, + WINED3D_TSS_ALPHA_ARG1, + WINED3D_TSS_ALPHA_ARG2, + WINED3D_TSS_ALPHA_OP, + WINED3D_TSS_BUMPENV_LOFFSET, + WINED3D_TSS_BUMPENV_LSCALE, + WINED3D_TSS_BUMPENV_MAT00, + WINED3D_TSS_BUMPENV_MAT01, + WINED3D_TSS_BUMPENV_MAT10, + WINED3D_TSS_BUMPENV_MAT11, + WINED3D_TSS_COLOR_ARG0, + WINED3D_TSS_COLOR_ARG1, + WINED3D_TSS_COLOR_ARG2, + WINED3D_TSS_COLOR_OP, + WINED3D_TSS_RESULT_ARG, + WINED3D_TSS_TEXCOORD_INDEX, + WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS, }; static const DWORD pixel_states_sampler[] = { - WINED3DSAMP_ADDRESSU, - WINED3DSAMP_ADDRESSV, - WINED3DSAMP_ADDRESSW, - WINED3DSAMP_BORDERCOLOR, - WINED3DSAMP_MAGFILTER, - WINED3DSAMP_MINFILTER, - WINED3DSAMP_MIPFILTER, - WINED3DSAMP_MIPMAPLODBIAS, - WINED3DSAMP_MAXMIPLEVEL, - WINED3DSAMP_MAXANISOTROPY, - WINED3DSAMP_SRGBTEXTURE, - WINED3DSAMP_ELEMENTINDEX, + WINED3D_SAMP_ADDRESS_U, + WINED3D_SAMP_ADDRESS_V, + WINED3D_SAMP_ADDRESS_W, + WINED3D_SAMP_BORDER_COLOR, + WINED3D_SAMP_MAG_FILTER, + WINED3D_SAMP_MIN_FILTER, + WINED3D_SAMP_MIP_FILTER, + WINED3D_SAMP_MIPMAP_LOD_BIAS, + WINED3D_SAMP_MAX_MIP_LEVEL, + WINED3D_SAMP_MAX_ANISOTROPY, + WINED3D_SAMP_SRGB_TEXTURE, + WINED3D_SAMP_ELEMENT_INDEX, }; static const DWORD vertex_states_render[] = { - WINED3DRS_ADAPTIVETESS_W, - WINED3DRS_ADAPTIVETESS_X, - WINED3DRS_ADAPTIVETESS_Y, - WINED3DRS_ADAPTIVETESS_Z, - WINED3DRS_AMBIENT, - WINED3DRS_AMBIENTMATERIALSOURCE, - WINED3DRS_CLIPPING, - WINED3DRS_CLIPPLANEENABLE, - WINED3DRS_COLORVERTEX, - WINED3DRS_CULLMODE, - WINED3DRS_DIFFUSEMATERIALSOURCE, - WINED3DRS_EMISSIVEMATERIALSOURCE, - WINED3DRS_ENABLEADAPTIVETESSELLATION, - WINED3DRS_FOGCOLOR, - WINED3DRS_FOGDENSITY, - WINED3DRS_FOGENABLE, - WINED3DRS_FOGEND, - WINED3DRS_FOGSTART, - WINED3DRS_FOGTABLEMODE, - WINED3DRS_FOGVERTEXMODE, - WINED3DRS_INDEXEDVERTEXBLENDENABLE, - WINED3DRS_LIGHTING, - WINED3DRS_LOCALVIEWER, - WINED3DRS_MAXTESSELLATIONLEVEL, - WINED3DRS_MINTESSELLATIONLEVEL, - WINED3DRS_MULTISAMPLEANTIALIAS, - WINED3DRS_MULTISAMPLEMASK, - WINED3DRS_NORMALDEGREE, - WINED3DRS_NORMALIZENORMALS, - WINED3DRS_PATCHEDGESTYLE, - WINED3DRS_POINTSCALE_A, - WINED3DRS_POINTSCALE_B, - WINED3DRS_POINTSCALE_C, - WINED3DRS_POINTSCALEENABLE, - WINED3DRS_POINTSIZE, - WINED3DRS_POINTSIZE_MAX, - WINED3DRS_POINTSIZE_MIN, - WINED3DRS_POINTSPRITEENABLE, - WINED3DRS_POSITIONDEGREE, - WINED3DRS_RANGEFOGENABLE, - WINED3DRS_SHADEMODE, - WINED3DRS_SPECULARENABLE, - WINED3DRS_SPECULARMATERIALSOURCE, - WINED3DRS_TWEENFACTOR, - WINED3DRS_VERTEXBLEND, + WINED3D_RS_ADAPTIVETESS_W, + WINED3D_RS_ADAPTIVETESS_X, + WINED3D_RS_ADAPTIVETESS_Y, + WINED3D_RS_ADAPTIVETESS_Z, + WINED3D_RS_AMBIENT, + WINED3D_RS_AMBIENTMATERIALSOURCE, + WINED3D_RS_CLIPPING, + WINED3D_RS_CLIPPLANEENABLE, + WINED3D_RS_COLORVERTEX, + WINED3D_RS_CULLMODE, + WINED3D_RS_DIFFUSEMATERIALSOURCE, + WINED3D_RS_EMISSIVEMATERIALSOURCE, + WINED3D_RS_ENABLEADAPTIVETESSELLATION, + WINED3D_RS_FOGCOLOR, + WINED3D_RS_FOGDENSITY, + WINED3D_RS_FOGENABLE, + WINED3D_RS_FOGEND, + WINED3D_RS_FOGSTART, + WINED3D_RS_FOGTABLEMODE, + WINED3D_RS_FOGVERTEXMODE, + WINED3D_RS_INDEXEDVERTEXBLENDENABLE, + WINED3D_RS_LIGHTING, + WINED3D_RS_LOCALVIEWER, + WINED3D_RS_MAXTESSELLATIONLEVEL, + WINED3D_RS_MINTESSELLATIONLEVEL, + WINED3D_RS_MULTISAMPLEANTIALIAS, + WINED3D_RS_MULTISAMPLEMASK, + WINED3D_RS_NORMALDEGREE, + WINED3D_RS_NORMALIZENORMALS, + WINED3D_RS_PATCHEDGESTYLE, + WINED3D_RS_POINTSCALE_A, + WINED3D_RS_POINTSCALE_B, + WINED3D_RS_POINTSCALE_C, + WINED3D_RS_POINTSCALEENABLE, + WINED3D_RS_POINTSIZE, + WINED3D_RS_POINTSIZE_MAX, + WINED3D_RS_POINTSIZE_MIN, + WINED3D_RS_POINTSPRITEENABLE, + WINED3D_RS_POSITIONDEGREE, + WINED3D_RS_RANGEFOGENABLE, + WINED3D_RS_SHADEMODE, + WINED3D_RS_SPECULARENABLE, + WINED3D_RS_SPECULARMATERIALSOURCE, + WINED3D_RS_TWEENFACTOR, + WINED3D_RS_VERTEXBLEND, }; static const DWORD vertex_states_texture[] = { - WINED3DTSS_TEXCOORDINDEX, - WINED3DTSS_TEXTURETRANSFORMFLAGS, + WINED3D_TSS_TEXCOORD_INDEX, + WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS, }; static const DWORD vertex_states_sampler[] = { - WINED3DSAMP_DMAPOFFSET, + WINED3D_SAMP_DMAP_OFFSET, }; /* Allocates the correct amount of space for pixel and vertex shader constants, @@ -241,7 +241,7 @@ static inline void stateblock_set_bits(DWORD *map, UINT map_size) } /* Set all members of a stateblock savedstate to the given value */ -static void stateblock_savedstates_set_all(SAVEDSTATES *states, DWORD vs_consts, DWORD ps_consts) +static void stateblock_savedstates_set_all(struct wined3d_saved_states *states, DWORD vs_consts, DWORD ps_consts) { unsigned int i; @@ -274,7 +274,7 @@ static void stateblock_savedstates_set_all(SAVEDSTATES *states, DWORD vs_consts, memset(states->vertexShaderConstantsF, TRUE, sizeof(BOOL) * vs_consts); } -static void stateblock_savedstates_set_pixel(SAVEDSTATES *states, const DWORD num_constants) +static void stateblock_savedstates_set_pixel(struct wined3d_saved_states *states, const DWORD num_constants) { DWORD texture_mask = 0; WORD sampler_mask = 0; @@ -300,7 +300,7 @@ static void stateblock_savedstates_set_pixel(SAVEDSTATES *states, const DWORD nu memset(states->pixelShaderConstantsF, TRUE, sizeof(BOOL) * num_constants); } -static void stateblock_savedstates_set_vertex(SAVEDSTATES *states, const DWORD num_constants) +static void stateblock_savedstates_set_vertex(struct wined3d_saved_states *states, const DWORD num_constants) { DWORD texture_mask = 0; WORD sampler_mask = 0; @@ -466,6 +466,58 @@ ULONG CDECL wined3d_stateblock_incref(struct wined3d_stateblock *stateblock) return refcount; } +void stateblock_unbind_resources(struct wined3d_stateblock *stateblock) +{ + struct wined3d_state *state = &stateblock->state; + struct wined3d_vertex_declaration *decl; + struct wined3d_texture *texture; + struct wined3d_buffer *buffer; + struct wined3d_shader *shader; + unsigned int i; + + if ((decl = state->vertex_declaration)) + { + state->vertex_declaration = NULL; + wined3d_vertex_declaration_decref(decl); + } + + for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) + { + if ((texture = state->textures[i])) + { + state->textures[i] = NULL; + wined3d_texture_decref(texture); + } + } + + for (i = 0; i < MAX_STREAMS; ++i) + { + if ((buffer = state->streams[i].buffer)) + { + state->streams[i].buffer = NULL; + wined3d_buffer_decref(buffer); + } + } + + if ((buffer = state->index_buffer)) + { + state->index_buffer = NULL; + wined3d_buffer_decref(buffer); + } + + if ((shader = state->vertex_shader)) + { + state->vertex_shader = NULL; + wined3d_shader_decref(shader); + } + + if ((shader = state->pixel_shader)) + { + state->pixel_shader = NULL; + wined3d_shader_decref(shader); + } +} + ULONG CDECL wined3d_stateblock_decref(struct wined3d_stateblock *stateblock) { ULONG refcount = InterlockedDecrement(&stateblock->ref); @@ -474,46 +526,9 @@ ULONG CDECL wined3d_stateblock_decref(struct wined3d_stateblock *stateblock) if (!refcount) { - struct wined3d_buffer *buffer; int counter; - if (stateblock->state.vertex_declaration) - wined3d_vertex_declaration_decref(stateblock->state.vertex_declaration); - - for (counter = 0; counter < MAX_COMBINED_SAMPLERS; counter++) - { - struct wined3d_texture *texture = stateblock->state.textures[counter]; - if (texture) - { - stateblock->state.textures[counter] = NULL; - wined3d_texture_decref(texture); - } - } - - for (counter = 0; counter < MAX_STREAMS; ++counter) - { - buffer = stateblock->state.streams[counter].buffer; - if (buffer) - { - stateblock->state.streams[counter].buffer = NULL; - if (wined3d_buffer_decref(buffer)) - { - WARN("Buffer %p still referenced by stateblock, stream %u.\n", buffer, counter); - } - } - } - - buffer = stateblock->state.index_buffer; - if (buffer) - { - stateblock->state.index_buffer = NULL; - wined3d_buffer_decref(buffer); - } - - if (stateblock->state.vertex_shader) - wined3d_shader_decref(stateblock->state.vertex_shader); - if (stateblock->state.pixel_shader) - wined3d_shader_decref(stateblock->state.pixel_shader); + stateblock_unbind_resources(stateblock); for (counter = 0; counter < LIGHTMAP_SIZE; ++counter) { @@ -708,7 +723,7 @@ HRESULT CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock) /* Others + Render & Texture */ for (i = 0; i < stateblock->num_contained_transform_states; ++i) { - WINED3DTRANSFORMSTATETYPE transform = stateblock->contained_transform_states[i]; + enum wined3d_transform_state transform = stateblock->contained_transform_states[i]; TRACE("Updating transform %#x.\n", transform); @@ -823,7 +838,7 @@ HRESULT CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock) /* Render */ for (i = 0; i < stateblock->num_contained_render_states; ++i) { - WINED3DRENDERSTATETYPE rs = stateblock->contained_render_states[i]; + enum wined3d_render_state rs = stateblock->contained_render_states[i]; TRACE("Updating render state %#x to %u.\n", rs, src_state->render_states[rs]); @@ -880,7 +895,7 @@ HRESULT CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock) wined3d_state_record_lights(&stateblock->state, src_state); - TRACE("Captue done.\n"); + TRACE("Capture done.\n"); return WINED3D_OK; } @@ -909,8 +924,8 @@ HRESULT CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblo unsigned int i; DWORD map; - TRACE("Applying stateblock %p to device %p.\n", stateblock, device); - TRACE("Blocktype: %#x.\n", stateblock->blockType); + TRACE("Applying stateblock %p of type %#x to device %p.\n", + stateblock, stateblock->blockType, device); if (stateblock->changed.vertexShader) wined3d_device_set_vertex_shader(device, stateblock->state.vertex_shader); @@ -1057,7 +1072,7 @@ HRESULT CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblo stateblock->device->stateBlock->state.lowest_disabled_stage = MAX_TEXTURES - 1; for (i = 0; i < MAX_TEXTURES - 1; ++i) { - if (stateblock->device->stateBlock->state.texture_states[i][WINED3DTSS_COLOROP] == WINED3DTOP_DISABLE) + if (stateblock->device->stateBlock->state.texture_states[i][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_DISABLE) { stateblock->device->stateBlock->state.lowest_disabled_stage = i; break; @@ -1074,8 +1089,9 @@ void stateblock_init_default_state(struct wined3d_stateblock *stateblock) struct wined3d_device *device = stateblock->device; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; struct wined3d_state *state = &stateblock->state; - union { - WINED3DLINEPATTERN lp; + union + { + struct wined3d_line_pattern lp; DWORD d; } lp; union { @@ -1089,174 +1105,175 @@ void stateblock_init_default_state(struct wined3d_stateblock *stateblock) TRACE("stateblock %p.\n", stateblock); - stateblock->blockType = WINED3DSBT_INIT; + stateblock->blockType = WINED3D_SBT_INIT; + + memset(stateblock->changed.pixelShaderConstantsF, 0, device->d3d_pshader_constantF * sizeof(BOOL)); + memset(stateblock->changed.vertexShaderConstantsF, 0, device->d3d_vshader_constantF * sizeof(BOOL)); /* Set some of the defaults for lights, transforms etc */ - memcpy(&state->transforms[WINED3DTS_PROJECTION], identity, sizeof(identity)); - memcpy(&state->transforms[WINED3DTS_VIEW], identity, sizeof(identity)); + memcpy(&state->transforms[WINED3D_TS_PROJECTION], identity, sizeof(identity)); + memcpy(&state->transforms[WINED3D_TS_VIEW], identity, sizeof(identity)); for (i = 0; i < 256; ++i) { - memcpy(&state->transforms[WINED3DTS_WORLDMATRIX(i)], identity, sizeof(identity)); + memcpy(&state->transforms[WINED3D_TS_WORLD_MATRIX(i)], identity, sizeof(identity)); } + state->fb = &device->fb; + TRACE("Render states\n"); /* Render states: */ if (device->auto_depth_stencil) - state->render_states[WINED3DRS_ZENABLE] = WINED3DZB_TRUE; + state->render_states[WINED3D_RS_ZENABLE] = WINED3D_ZB_TRUE; else - state->render_states[WINED3DRS_ZENABLE] = WINED3DZB_FALSE; - state->render_states[WINED3DRS_FILLMODE] = WINED3DFILL_SOLID; - state->render_states[WINED3DRS_SHADEMODE] = WINED3DSHADE_GOURAUD; - lp.lp.wRepeatFactor = 0; - lp.lp.wLinePattern = 0; - state->render_states[WINED3DRS_LINEPATTERN] = lp.d; - state->render_states[WINED3DRS_ZWRITEENABLE] = TRUE; - state->render_states[WINED3DRS_ALPHATESTENABLE] = FALSE; - state->render_states[WINED3DRS_LASTPIXEL] = TRUE; - state->render_states[WINED3DRS_SRCBLEND] = WINED3DBLEND_ONE; - state->render_states[WINED3DRS_DESTBLEND] = WINED3DBLEND_ZERO; - state->render_states[WINED3DRS_CULLMODE] = WINED3DCULL_CCW; - state->render_states[WINED3DRS_ZFUNC] = WINED3DCMP_LESSEQUAL; - state->render_states[WINED3DRS_ALPHAFUNC] = WINED3DCMP_ALWAYS; - state->render_states[WINED3DRS_ALPHAREF] = 0; - state->render_states[WINED3DRS_DITHERENABLE] = FALSE; - state->render_states[WINED3DRS_ALPHABLENDENABLE] = FALSE; - state->render_states[WINED3DRS_FOGENABLE] = FALSE; - state->render_states[WINED3DRS_SPECULARENABLE] = FALSE; - state->render_states[WINED3DRS_ZVISIBLE] = 0; - state->render_states[WINED3DRS_FOGCOLOR] = 0; - state->render_states[WINED3DRS_FOGTABLEMODE] = WINED3DFOG_NONE; + state->render_states[WINED3D_RS_ZENABLE] = WINED3D_ZB_FALSE; + state->render_states[WINED3D_RS_FILLMODE] = WINED3D_FILL_SOLID; + state->render_states[WINED3D_RS_SHADEMODE] = WINED3D_SHADE_GOURAUD; + lp.lp.repeat_factor = 0; + lp.lp.line_pattern = 0; + state->render_states[WINED3D_RS_LINEPATTERN] = lp.d; + state->render_states[WINED3D_RS_ZWRITEENABLE] = TRUE; + state->render_states[WINED3D_RS_ALPHATESTENABLE] = FALSE; + state->render_states[WINED3D_RS_LASTPIXEL] = TRUE; + state->render_states[WINED3D_RS_SRCBLEND] = WINED3D_BLEND_ONE; + state->render_states[WINED3D_RS_DESTBLEND] = WINED3D_BLEND_ZERO; + state->render_states[WINED3D_RS_CULLMODE] = WINED3D_CULL_CCW; + state->render_states[WINED3D_RS_ZFUNC] = WINED3D_CMP_LESSEQUAL; + state->render_states[WINED3D_RS_ALPHAFUNC] = WINED3D_CMP_ALWAYS; + state->render_states[WINED3D_RS_ALPHAREF] = 0; + state->render_states[WINED3D_RS_DITHERENABLE] = FALSE; + state->render_states[WINED3D_RS_ALPHABLENDENABLE] = FALSE; + state->render_states[WINED3D_RS_FOGENABLE] = FALSE; + state->render_states[WINED3D_RS_SPECULARENABLE] = FALSE; + state->render_states[WINED3D_RS_ZVISIBLE] = 0; + state->render_states[WINED3D_RS_FOGCOLOR] = 0; + state->render_states[WINED3D_RS_FOGTABLEMODE] = WINED3D_FOG_NONE; tmpfloat.f = 0.0f; - state->render_states[WINED3DRS_FOGSTART] = tmpfloat.d; + state->render_states[WINED3D_RS_FOGSTART] = tmpfloat.d; tmpfloat.f = 1.0f; - state->render_states[WINED3DRS_FOGEND] = tmpfloat.d; + state->render_states[WINED3D_RS_FOGEND] = tmpfloat.d; tmpfloat.f = 1.0f; - state->render_states[WINED3DRS_FOGDENSITY] = tmpfloat.d; - state->render_states[WINED3DRS_EDGEANTIALIAS] = FALSE; - state->render_states[WINED3DRS_RANGEFOGENABLE] = FALSE; - state->render_states[WINED3DRS_STENCILENABLE] = FALSE; - state->render_states[WINED3DRS_STENCILFAIL] = WINED3DSTENCILOP_KEEP; - state->render_states[WINED3DRS_STENCILZFAIL] = WINED3DSTENCILOP_KEEP; - state->render_states[WINED3DRS_STENCILPASS] = WINED3DSTENCILOP_KEEP; - state->render_states[WINED3DRS_STENCILREF] = 0; - state->render_states[WINED3DRS_STENCILMASK] = 0xffffffff; - state->render_states[WINED3DRS_STENCILFUNC] = WINED3DCMP_ALWAYS; - state->render_states[WINED3DRS_STENCILWRITEMASK] = 0xffffffff; - state->render_states[WINED3DRS_TEXTUREFACTOR] = 0xffffffff; - state->render_states[WINED3DRS_WRAP0] = 0; - state->render_states[WINED3DRS_WRAP1] = 0; - state->render_states[WINED3DRS_WRAP2] = 0; - state->render_states[WINED3DRS_WRAP3] = 0; - state->render_states[WINED3DRS_WRAP4] = 0; - state->render_states[WINED3DRS_WRAP5] = 0; - state->render_states[WINED3DRS_WRAP6] = 0; - state->render_states[WINED3DRS_WRAP7] = 0; - state->render_states[WINED3DRS_CLIPPING] = TRUE; - state->render_states[WINED3DRS_LIGHTING] = TRUE; - state->render_states[WINED3DRS_AMBIENT] = 0; - state->render_states[WINED3DRS_FOGVERTEXMODE] = WINED3DFOG_NONE; - state->render_states[WINED3DRS_COLORVERTEX] = TRUE; - state->render_states[WINED3DRS_LOCALVIEWER] = TRUE; - state->render_states[WINED3DRS_NORMALIZENORMALS] = FALSE; - state->render_states[WINED3DRS_DIFFUSEMATERIALSOURCE] = WINED3DMCS_COLOR1; - state->render_states[WINED3DRS_SPECULARMATERIALSOURCE] = WINED3DMCS_COLOR2; - state->render_states[WINED3DRS_AMBIENTMATERIALSOURCE] = WINED3DMCS_MATERIAL; - state->render_states[WINED3DRS_EMISSIVEMATERIALSOURCE] = WINED3DMCS_MATERIAL; - state->render_states[WINED3DRS_VERTEXBLEND] = WINED3DVBF_DISABLE; - state->render_states[WINED3DRS_CLIPPLANEENABLE] = 0; - state->render_states[WINED3DRS_SOFTWAREVERTEXPROCESSING] = FALSE; + state->render_states[WINED3D_RS_FOGDENSITY] = tmpfloat.d; + state->render_states[WINED3D_RS_EDGEANTIALIAS] = FALSE; + state->render_states[WINED3D_RS_RANGEFOGENABLE] = FALSE; + state->render_states[WINED3D_RS_STENCILENABLE] = FALSE; + state->render_states[WINED3D_RS_STENCILFAIL] = WINED3D_STENCIL_OP_KEEP; + state->render_states[WINED3D_RS_STENCILZFAIL] = WINED3D_STENCIL_OP_KEEP; + state->render_states[WINED3D_RS_STENCILPASS] = WINED3D_STENCIL_OP_KEEP; + state->render_states[WINED3D_RS_STENCILREF] = 0; + state->render_states[WINED3D_RS_STENCILMASK] = 0xffffffff; + state->render_states[WINED3D_RS_STENCILFUNC] = WINED3D_CMP_ALWAYS; + state->render_states[WINED3D_RS_STENCILWRITEMASK] = 0xffffffff; + state->render_states[WINED3D_RS_TEXTUREFACTOR] = 0xffffffff; + state->render_states[WINED3D_RS_WRAP0] = 0; + state->render_states[WINED3D_RS_WRAP1] = 0; + state->render_states[WINED3D_RS_WRAP2] = 0; + state->render_states[WINED3D_RS_WRAP3] = 0; + state->render_states[WINED3D_RS_WRAP4] = 0; + state->render_states[WINED3D_RS_WRAP5] = 0; + state->render_states[WINED3D_RS_WRAP6] = 0; + state->render_states[WINED3D_RS_WRAP7] = 0; + state->render_states[WINED3D_RS_CLIPPING] = TRUE; + state->render_states[WINED3D_RS_LIGHTING] = TRUE; + state->render_states[WINED3D_RS_AMBIENT] = 0; + state->render_states[WINED3D_RS_FOGVERTEXMODE] = WINED3D_FOG_NONE; + state->render_states[WINED3D_RS_COLORVERTEX] = TRUE; + state->render_states[WINED3D_RS_LOCALVIEWER] = TRUE; + state->render_states[WINED3D_RS_NORMALIZENORMALS] = FALSE; + state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE] = WINED3D_MCS_COLOR1; + state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] = WINED3D_MCS_COLOR2; + state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE] = WINED3D_MCS_MATERIAL; + state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] = WINED3D_MCS_MATERIAL; + state->render_states[WINED3D_RS_VERTEXBLEND] = WINED3D_VBF_DISABLE; + state->render_states[WINED3D_RS_CLIPPLANEENABLE] = 0; + state->render_states[WINED3D_RS_SOFTWAREVERTEXPROCESSING] = FALSE; tmpfloat.f = 1.0f; - state->render_states[WINED3DRS_POINTSIZE] = tmpfloat.d; + state->render_states[WINED3D_RS_POINTSIZE] = tmpfloat.d; tmpfloat.f = 1.0f; - state->render_states[WINED3DRS_POINTSIZE_MIN] = tmpfloat.d; - state->render_states[WINED3DRS_POINTSPRITEENABLE] = FALSE; - state->render_states[WINED3DRS_POINTSCALEENABLE] = FALSE; + state->render_states[WINED3D_RS_POINTSIZE_MIN] = tmpfloat.d; + state->render_states[WINED3D_RS_POINTSPRITEENABLE] = FALSE; + state->render_states[WINED3D_RS_POINTSCALEENABLE] = FALSE; tmpfloat.f = 1.0f; - state->render_states[WINED3DRS_POINTSCALE_A] = tmpfloat.d; + state->render_states[WINED3D_RS_POINTSCALE_A] = tmpfloat.d; tmpfloat.f = 0.0f; - state->render_states[WINED3DRS_POINTSCALE_B] = tmpfloat.d; + state->render_states[WINED3D_RS_POINTSCALE_B] = tmpfloat.d; tmpfloat.f = 0.0f; - state->render_states[WINED3DRS_POINTSCALE_C] = tmpfloat.d; - state->render_states[WINED3DRS_MULTISAMPLEANTIALIAS] = TRUE; - state->render_states[WINED3DRS_MULTISAMPLEMASK] = 0xffffffff; - state->render_states[WINED3DRS_PATCHEDGESTYLE] = WINED3DPATCHEDGE_DISCRETE; + state->render_states[WINED3D_RS_POINTSCALE_C] = tmpfloat.d; + state->render_states[WINED3D_RS_MULTISAMPLEANTIALIAS] = TRUE; + state->render_states[WINED3D_RS_MULTISAMPLEMASK] = 0xffffffff; + state->render_states[WINED3D_RS_PATCHEDGESTYLE] = WINED3D_PATCH_EDGE_DISCRETE; tmpfloat.f = 1.0f; - state->render_states[WINED3DRS_PATCHSEGMENTS] = tmpfloat.d; - state->render_states[WINED3DRS_DEBUGMONITORTOKEN] = 0xbaadcafe; + state->render_states[WINED3D_RS_PATCHSEGMENTS] = tmpfloat.d; + state->render_states[WINED3D_RS_DEBUGMONITORTOKEN] = 0xbaadcafe; tmpfloat.f = gl_info->limits.pointsize_max; - state->render_states[WINED3DRS_POINTSIZE_MAX] = tmpfloat.d; - state->render_states[WINED3DRS_INDEXEDVERTEXBLENDENABLE] = FALSE; - state->render_states[WINED3DRS_COLORWRITEENABLE] = 0x0000000f; + state->render_states[WINED3D_RS_POINTSIZE_MAX] = tmpfloat.d; + state->render_states[WINED3D_RS_INDEXEDVERTEXBLENDENABLE] = FALSE; + state->render_states[WINED3D_RS_COLORWRITEENABLE] = 0x0000000f; tmpfloat.f = 0.0f; - state->render_states[WINED3DRS_TWEENFACTOR] = tmpfloat.d; - state->render_states[WINED3DRS_BLENDOP] = WINED3DBLENDOP_ADD; - state->render_states[WINED3DRS_POSITIONDEGREE] = WINED3DDEGREE_CUBIC; - state->render_states[WINED3DRS_NORMALDEGREE] = WINED3DDEGREE_LINEAR; + state->render_states[WINED3D_RS_TWEENFACTOR] = tmpfloat.d; + state->render_states[WINED3D_RS_BLENDOP] = WINED3D_BLEND_OP_ADD; + state->render_states[WINED3D_RS_POSITIONDEGREE] = WINED3D_DEGREE_CUBIC; + state->render_states[WINED3D_RS_NORMALDEGREE] = WINED3D_DEGREE_LINEAR; /* states new in d3d9 */ - state->render_states[WINED3DRS_SCISSORTESTENABLE] = FALSE; - state->render_states[WINED3DRS_SLOPESCALEDEPTHBIAS] = 0; + state->render_states[WINED3D_RS_SCISSORTESTENABLE] = FALSE; + state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS] = 0; tmpfloat.f = 1.0f; - state->render_states[WINED3DRS_MINTESSELLATIONLEVEL] = tmpfloat.d; - state->render_states[WINED3DRS_MAXTESSELLATIONLEVEL] = tmpfloat.d; - state->render_states[WINED3DRS_ANTIALIASEDLINEENABLE] = FALSE; + state->render_states[WINED3D_RS_MINTESSELLATIONLEVEL] = tmpfloat.d; + state->render_states[WINED3D_RS_MAXTESSELLATIONLEVEL] = tmpfloat.d; + state->render_states[WINED3D_RS_ANTIALIASEDLINEENABLE] = FALSE; tmpfloat.f = 0.0f; - state->render_states[WINED3DRS_ADAPTIVETESS_X] = tmpfloat.d; - state->render_states[WINED3DRS_ADAPTIVETESS_Y] = tmpfloat.d; + state->render_states[WINED3D_RS_ADAPTIVETESS_X] = tmpfloat.d; + state->render_states[WINED3D_RS_ADAPTIVETESS_Y] = tmpfloat.d; tmpfloat.f = 1.0f; - state->render_states[WINED3DRS_ADAPTIVETESS_Z] = tmpfloat.d; + state->render_states[WINED3D_RS_ADAPTIVETESS_Z] = tmpfloat.d; tmpfloat.f = 0.0f; - state->render_states[WINED3DRS_ADAPTIVETESS_W] = tmpfloat.d; - state->render_states[WINED3DRS_ENABLEADAPTIVETESSELLATION] = FALSE; - state->render_states[WINED3DRS_TWOSIDEDSTENCILMODE] = FALSE; - state->render_states[WINED3DRS_CCW_STENCILFAIL] = WINED3DSTENCILOP_KEEP; - state->render_states[WINED3DRS_CCW_STENCILZFAIL] = WINED3DSTENCILOP_KEEP; - state->render_states[WINED3DRS_CCW_STENCILPASS] = WINED3DSTENCILOP_KEEP; - state->render_states[WINED3DRS_CCW_STENCILFUNC] = WINED3DCMP_ALWAYS; - state->render_states[WINED3DRS_COLORWRITEENABLE1] = 0x0000000f; - state->render_states[WINED3DRS_COLORWRITEENABLE2] = 0x0000000f; - state->render_states[WINED3DRS_COLORWRITEENABLE3] = 0x0000000f; - state->render_states[WINED3DRS_BLENDFACTOR] = 0xFFFFFFFF; - state->render_states[WINED3DRS_SRGBWRITEENABLE] = 0; - state->render_states[WINED3DRS_DEPTHBIAS] = 0; - state->render_states[WINED3DRS_WRAP8] = 0; - state->render_states[WINED3DRS_WRAP9] = 0; - state->render_states[WINED3DRS_WRAP10] = 0; - state->render_states[WINED3DRS_WRAP11] = 0; - state->render_states[WINED3DRS_WRAP12] = 0; - state->render_states[WINED3DRS_WRAP13] = 0; - state->render_states[WINED3DRS_WRAP14] = 0; - state->render_states[WINED3DRS_WRAP15] = 0; - state->render_states[WINED3DRS_SEPARATEALPHABLENDENABLE] = FALSE; - state->render_states[WINED3DRS_SRCBLENDALPHA] = WINED3DBLEND_ONE; - state->render_states[WINED3DRS_DESTBLENDALPHA] = WINED3DBLEND_ZERO; - state->render_states[WINED3DRS_BLENDOPALPHA] = WINED3DBLENDOP_ADD; - - /* clipping status */ - state->clip_status.ClipUnion = 0; - state->clip_status.ClipIntersection = 0xFFFFFFFF; + state->render_states[WINED3D_RS_ADAPTIVETESS_W] = tmpfloat.d; + state->render_states[WINED3D_RS_ENABLEADAPTIVETESSELLATION] = FALSE; + state->render_states[WINED3D_RS_TWOSIDEDSTENCILMODE] = FALSE; + state->render_states[WINED3D_RS_CCW_STENCILFAIL] = WINED3D_STENCIL_OP_KEEP; + state->render_states[WINED3D_RS_CCW_STENCILZFAIL] = WINED3D_STENCIL_OP_KEEP; + state->render_states[WINED3D_RS_CCW_STENCILPASS] = WINED3D_STENCIL_OP_KEEP; + state->render_states[WINED3D_RS_CCW_STENCILFUNC] = WINED3D_CMP_ALWAYS; + state->render_states[WINED3D_RS_COLORWRITEENABLE1] = 0x0000000f; + state->render_states[WINED3D_RS_COLORWRITEENABLE2] = 0x0000000f; + state->render_states[WINED3D_RS_COLORWRITEENABLE3] = 0x0000000f; + state->render_states[WINED3D_RS_BLENDFACTOR] = 0xFFFFFFFF; + state->render_states[WINED3D_RS_SRGBWRITEENABLE] = 0; + state->render_states[WINED3D_RS_DEPTHBIAS] = 0; + state->render_states[WINED3D_RS_WRAP8] = 0; + state->render_states[WINED3D_RS_WRAP9] = 0; + state->render_states[WINED3D_RS_WRAP10] = 0; + state->render_states[WINED3D_RS_WRAP11] = 0; + state->render_states[WINED3D_RS_WRAP12] = 0; + state->render_states[WINED3D_RS_WRAP13] = 0; + state->render_states[WINED3D_RS_WRAP14] = 0; + state->render_states[WINED3D_RS_WRAP15] = 0; + state->render_states[WINED3D_RS_SEPARATEALPHABLENDENABLE] = FALSE; + state->render_states[WINED3D_RS_SRCBLENDALPHA] = WINED3D_BLEND_ONE; + state->render_states[WINED3D_RS_DESTBLENDALPHA] = WINED3D_BLEND_ZERO; + state->render_states[WINED3D_RS_BLENDOPALPHA] = WINED3D_BLEND_OP_ADD; /* Texture Stage States - Put directly into state block, we will call function below */ for (i = 0; i < MAX_TEXTURES; ++i) { TRACE("Setting up default texture states for texture Stage %u.\n", i); - memcpy(&state->transforms[WINED3DTS_TEXTURE0 + i], identity, sizeof(identity)); - state->texture_states[i][WINED3DTSS_COLOROP] = i ? WINED3DTOP_DISABLE : WINED3DTOP_MODULATE; - state->texture_states[i][WINED3DTSS_COLORARG1] = WINED3DTA_TEXTURE; - state->texture_states[i][WINED3DTSS_COLORARG2] = WINED3DTA_CURRENT; - state->texture_states[i][WINED3DTSS_ALPHAOP] = i ? WINED3DTOP_DISABLE : WINED3DTOP_SELECTARG1; - state->texture_states[i][WINED3DTSS_ALPHAARG1] = WINED3DTA_TEXTURE; - state->texture_states[i][WINED3DTSS_ALPHAARG2] = WINED3DTA_CURRENT; - state->texture_states[i][WINED3DTSS_BUMPENVMAT00] = 0; - state->texture_states[i][WINED3DTSS_BUMPENVMAT01] = 0; - state->texture_states[i][WINED3DTSS_BUMPENVMAT10] = 0; - state->texture_states[i][WINED3DTSS_BUMPENVMAT11] = 0; - state->texture_states[i][WINED3DTSS_TEXCOORDINDEX] = i; - state->texture_states[i][WINED3DTSS_BUMPENVLSCALE] = 0; - state->texture_states[i][WINED3DTSS_BUMPENVLOFFSET] = 0; - state->texture_states[i][WINED3DTSS_TEXTURETRANSFORMFLAGS] = WINED3DTTFF_DISABLE; - state->texture_states[i][WINED3DTSS_COLORARG0] = WINED3DTA_CURRENT; - state->texture_states[i][WINED3DTSS_ALPHAARG0] = WINED3DTA_CURRENT; - state->texture_states[i][WINED3DTSS_RESULTARG] = WINED3DTA_CURRENT; + memcpy(&state->transforms[WINED3D_TS_TEXTURE0 + i], identity, sizeof(identity)); + state->texture_states[i][WINED3D_TSS_COLOR_OP] = i ? WINED3D_TOP_DISABLE : WINED3D_TOP_MODULATE; + state->texture_states[i][WINED3D_TSS_COLOR_ARG1] = WINED3DTA_TEXTURE; + state->texture_states[i][WINED3D_TSS_COLOR_ARG2] = WINED3DTA_CURRENT; + state->texture_states[i][WINED3D_TSS_ALPHA_OP] = i ? WINED3D_TOP_DISABLE : WINED3D_TOP_SELECT_ARG1; + state->texture_states[i][WINED3D_TSS_ALPHA_ARG1] = WINED3DTA_TEXTURE; + state->texture_states[i][WINED3D_TSS_ALPHA_ARG2] = WINED3DTA_CURRENT; + state->texture_states[i][WINED3D_TSS_BUMPENV_MAT00] = 0; + state->texture_states[i][WINED3D_TSS_BUMPENV_MAT01] = 0; + state->texture_states[i][WINED3D_TSS_BUMPENV_MAT10] = 0; + state->texture_states[i][WINED3D_TSS_BUMPENV_MAT11] = 0; + state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX] = i; + state->texture_states[i][WINED3D_TSS_BUMPENV_LSCALE] = 0; + state->texture_states[i][WINED3D_TSS_BUMPENV_LOFFSET] = 0; + state->texture_states[i][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS] = WINED3D_TTFF_DISABLE; + state->texture_states[i][WINED3D_TSS_COLOR_ARG0] = WINED3DTA_CURRENT; + state->texture_states[i][WINED3D_TSS_ALPHA_ARG0] = WINED3DTA_CURRENT; + state->texture_states[i][WINED3D_TSS_RESULT_ARG] = WINED3DTA_CURRENT; } state->lowest_disabled_stage = 1; @@ -1264,21 +1281,21 @@ void stateblock_init_default_state(struct wined3d_stateblock *stateblock) for (i = 0 ; i < MAX_COMBINED_SAMPLERS; ++i) { TRACE("Setting up default samplers states for sampler %u.\n", i); - state->sampler_states[i][WINED3DSAMP_ADDRESSU] = WINED3DTADDRESS_WRAP; - state->sampler_states[i][WINED3DSAMP_ADDRESSV] = WINED3DTADDRESS_WRAP; - state->sampler_states[i][WINED3DSAMP_ADDRESSW] = WINED3DTADDRESS_WRAP; - state->sampler_states[i][WINED3DSAMP_BORDERCOLOR] = 0; - state->sampler_states[i][WINED3DSAMP_MAGFILTER] = WINED3DTEXF_POINT; - state->sampler_states[i][WINED3DSAMP_MINFILTER] = WINED3DTEXF_POINT; - state->sampler_states[i][WINED3DSAMP_MIPFILTER] = WINED3DTEXF_NONE; - state->sampler_states[i][WINED3DSAMP_MIPMAPLODBIAS] = 0; - state->sampler_states[i][WINED3DSAMP_MAXMIPLEVEL] = 0; - state->sampler_states[i][WINED3DSAMP_MAXANISOTROPY] = 1; - state->sampler_states[i][WINED3DSAMP_SRGBTEXTURE] = 0; + state->sampler_states[i][WINED3D_SAMP_ADDRESS_U] = WINED3D_TADDRESS_WRAP; + state->sampler_states[i][WINED3D_SAMP_ADDRESS_V] = WINED3D_TADDRESS_WRAP; + state->sampler_states[i][WINED3D_SAMP_ADDRESS_W] = WINED3D_TADDRESS_WRAP; + state->sampler_states[i][WINED3D_SAMP_BORDER_COLOR] = 0; + state->sampler_states[i][WINED3D_SAMP_MAG_FILTER] = WINED3D_TEXF_POINT; + state->sampler_states[i][WINED3D_SAMP_MIN_FILTER] = WINED3D_TEXF_POINT; + state->sampler_states[i][WINED3D_SAMP_MIP_FILTER] = WINED3D_TEXF_NONE; + state->sampler_states[i][WINED3D_SAMP_MIPMAP_LOD_BIAS] = 0; + state->sampler_states[i][WINED3D_SAMP_MAX_MIP_LEVEL] = 0; + state->sampler_states[i][WINED3D_SAMP_MAX_ANISOTROPY] = 1; + state->sampler_states[i][WINED3D_SAMP_SRGB_TEXTURE] = 0; /* TODO: Indicates which element of a multielement texture to use. */ - state->sampler_states[i][WINED3DSAMP_ELEMENTINDEX] = 0; + state->sampler_states[i][WINED3D_SAMP_ELEMENT_INDEX] = 0; /* TODO: Vertex offset in the presampled displacement map. */ - state->sampler_states[i][WINED3DSAMP_DMAPOFFSET] = 0; + state->sampler_states[i][WINED3D_SAMP_DMAP_OFFSET] = 0; } for (i = 0; i < gl_info->limits.textures; ++i) @@ -1290,7 +1307,7 @@ void stateblock_init_default_state(struct wined3d_stateblock *stateblock) hr = wined3d_device_get_swapchain(device, 0, &swapchain); if (SUCCEEDED(hr) && swapchain) { - hr = wined3d_swapchain_get_back_buffer(swapchain, 0, WINED3DBACKBUFFER_TYPE_MONO, &backbuffer); + hr = wined3d_swapchain_get_back_buffer(swapchain, 0, WINED3D_BACKBUFFER_TYPE_MONO, &backbuffer); if (SUCCEEDED(hr) && backbuffer) { struct wined3d_resource_desc desc; @@ -1306,12 +1323,12 @@ void stateblock_init_default_state(struct wined3d_stateblock *stateblock) } /* Set the default viewport */ - state->viewport.X = 0; - state->viewport.Y = 0; - state->viewport.Width = swapchain->presentParms.BackBufferWidth; - state->viewport.Height = swapchain->presentParms.BackBufferHeight; - state->viewport.MinZ = 0.0f; - state->viewport.MaxZ = 1.0f; + state->viewport.x = 0; + state->viewport.y = 0; + state->viewport.width = swapchain->desc.backbuffer_width; + state->viewport.height = swapchain->desc.backbuffer_height; + state->viewport.min_z = 0.0f; + state->viewport.max_z = 1.0f; wined3d_swapchain_decref(swapchain); } @@ -1320,7 +1337,7 @@ void stateblock_init_default_state(struct wined3d_stateblock *stateblock) } static HRESULT stateblock_init(struct wined3d_stateblock *stateblock, - struct wined3d_device *device, WINED3DSTATEBLOCKTYPE type) + struct wined3d_device *device, enum wined3d_stateblock_type type) { unsigned int i; HRESULT hr; @@ -1337,26 +1354,26 @@ static HRESULT stateblock_init(struct wined3d_stateblock *stateblock, hr = stateblock_allocate_shader_constants(stateblock); if (FAILED(hr)) return hr; - /* The WINED3DSBT_INIT stateblock type is used during initialization to + /* The WINED3D_SBT_INIT stateblock type is used during initialization to * produce a placeholder stateblock so other functions called can update a * state block. */ - if (type == WINED3DSBT_INIT || type == WINED3DSBT_RECORDED) return WINED3D_OK; + if (type == WINED3D_SBT_INIT || type == WINED3D_SBT_RECORDED) return WINED3D_OK; TRACE("Updating changed flags appropriate for type %#x.\n", type); switch (type) { - case WINED3DSBT_ALL: + case WINED3D_SBT_ALL: stateblock_init_lights(stateblock, device->stateBlock->state.light_map); stateblock_savedstates_set_all(&stateblock->changed, device->d3d_vshader_constantF, device->d3d_pshader_constantF); break; - case WINED3DSBT_PIXELSTATE: + case WINED3D_SBT_PIXEL_STATE: stateblock_savedstates_set_pixel(&stateblock->changed, device->d3d_pshader_constantF); break; - case WINED3DSBT_VERTEXSTATE: + case WINED3D_SBT_VERTEX_STATE: stateblock_init_lights(stateblock, device->stateBlock->state.light_map); stateblock_savedstates_set_vertex(&stateblock->changed, device->d3d_vshader_constantF); break; @@ -1373,7 +1390,7 @@ static HRESULT stateblock_init(struct wined3d_stateblock *stateblock, } HRESULT CDECL wined3d_stateblock_create(struct wined3d_device *device, - WINED3DSTATEBLOCKTYPE type, struct wined3d_stateblock **stateblock) + enum wined3d_stateblock_type type, struct wined3d_stateblock **stateblock) { struct wined3d_stateblock *object; HRESULT hr; diff --git a/reactos/dll/directx/wine/wined3d/surface.c b/reactos/dll/directx/wine/wined3d/surface.c index 91b16a6fa0e..df5855eca29 100644 --- a/reactos/dll/directx/wine/wined3d/surface.c +++ b/reactos/dll/directx/wine/wined3d/surface.c @@ -6,7 +6,7 @@ * Copyright 2002-2003 Raphael Junqueira * Copyright 2004 Christian Costa * Copyright 2005 Oliver Stieber - * Copyright 2006-2008 Stefan Dösinger for CodeWeavers + * Copyright 2006-2011 Stefan Dösinger for CodeWeavers * Copyright 2007-2008 Henri Verbeet * Copyright 2006-2008 Roderick Colenbrander * Copyright 2009-2011 Henri Verbeet for CodeWeavers @@ -35,18 +35,20 @@ WINE_DECLARE_DEBUG_CHANNEL(d3d); static HRESULT surface_cpu_blt(struct wined3d_surface *dst_surface, const RECT *dst_rect, struct wined3d_surface *src_surface, const RECT *src_rect, DWORD flags, - const WINEDDBLTFX *fx, WINED3DTEXTUREFILTERTYPE filter); -static HRESULT surface_cpu_bltfast(struct wined3d_surface *dst_surface, DWORD dst_x, DWORD dst_y, - struct wined3d_surface *src_surface, const RECT *src_rect, DWORD trans); + const WINEDDBLTFX *fx, enum wined3d_texture_filter_type filter); static HRESULT IWineD3DSurfaceImpl_BltOverride(struct wined3d_surface *dst_surface, const RECT *dst_rect, struct wined3d_surface *src_surface, const RECT *src_rect, DWORD flags, const WINEDDBLTFX *fx, - WINED3DTEXTUREFILTERTYPE filter); + enum wined3d_texture_filter_type filter); static void surface_cleanup(struct wined3d_surface *surface) { + struct wined3d_surface *overlay, *cur; + TRACE("surface %p.\n", surface); - if (surface->texture_name || (surface->flags & SFLAG_PBO) || !list_empty(&surface->renderbuffers)) + if (surface->texture_name || (surface->flags & SFLAG_PBO) + || surface->rb_multisample || surface->rb_resolved + || !list_empty(&surface->renderbuffers)) { struct wined3d_renderbuffer_entry *entry, *entry2; const struct wined3d_gl_info *gl_info; @@ -69,6 +71,18 @@ static void surface_cleanup(struct wined3d_surface *surface) GL_EXTCALL(glDeleteBuffersARB(1, &surface->pbo)); } + if (surface->rb_multisample) + { + TRACE("Deleting multisample renderbuffer %u.\n", surface->rb_multisample); + gl_info->fbo_ops.glDeleteRenderbuffers(1, &surface->rb_multisample); + } + + if (surface->rb_resolved) + { + TRACE("Deleting resolved renderbuffer %u.\n", surface->rb_resolved); + gl_info->fbo_ops.glDeleteRenderbuffers(1, &surface->rb_resolved); + } + LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &surface->renderbuffers, struct wined3d_renderbuffer_entry, entry) { TRACE("Deleting renderbuffer %u.\n", entry->id); @@ -83,10 +97,7 @@ static void surface_cleanup(struct wined3d_surface *surface) if (surface->flags & SFLAG_DIBSECTION) { - /* Release the DC. */ - SelectObject(surface->hDC, surface->dib.holdbitmap); DeleteDC(surface->hDC); - /* Release the DIB section. */ DeleteObject(surface->dib.DIBsection); surface->dib.bitmap_data = NULL; surface->resource.allocatedMemory = NULL; @@ -97,11 +108,25 @@ static void surface_cleanup(struct wined3d_surface *surface) if (surface->overlay_dest) list_remove(&surface->overlay_entry); - HeapFree(GetProcessHeap(), 0, surface->palette9); + LIST_FOR_EACH_ENTRY_SAFE(overlay, cur, &surface->overlays, struct wined3d_surface, overlay_entry) + { + list_remove(&overlay->overlay_entry); + overlay->overlay_dest = NULL; + } resource_cleanup(&surface->resource); } +void surface_update_draw_binding(struct wined3d_surface *surface) +{ + if (!surface_is_offscreen(surface) || wined3d_settings.offscreen_rendering_mode != ORM_FBO) + surface->draw_binding = SFLAG_INDRAWABLE; + else if (surface->resource.multisample_type) + surface->draw_binding = SFLAG_INRB_MULTISAMPLE; + else + surface->draw_binding = SFLAG_INTEXTURE; +} + void surface_set_container(struct wined3d_surface *surface, enum wined3d_container_type type, void *container) { TRACE("surface %p, container %p.\n", surface, container); @@ -133,6 +158,7 @@ void surface_set_container(struct wined3d_surface *surface, enum wined3d_contain surface->container.type = type; surface->container.u.base = container; + surface_update_draw_binding(surface); } struct blt_info @@ -274,7 +300,7 @@ static void surface_get_blt_info(GLenum target, const RECT *rect, GLsizei w, GLs } } -static inline void surface_get_rect(struct wined3d_surface *surface, const RECT *rect_in, RECT *rect_out) +static void surface_get_rect(const struct wined3d_surface *surface, const RECT *rect_in, RECT *rect_out) { if (rect_in) *rect_out = *rect_in; @@ -288,8 +314,8 @@ static inline void surface_get_rect(struct wined3d_surface *surface, const RECT } /* GL locking and context activation is done by the caller */ -void draw_textured_quad(struct wined3d_surface *src_surface, const RECT *src_rect, - const RECT *dst_rect, WINED3DTEXTUREFILTERTYPE Filter) +void draw_textured_quad(const struct wined3d_surface *src_surface, struct wined3d_context *context, + const RECT *src_rect, const RECT *dst_rect, enum wined3d_texture_filter_type filter) { struct blt_info info; @@ -298,19 +324,19 @@ void draw_textured_quad(struct wined3d_surface *src_surface, const RECT *src_rec glEnable(info.bind_target); checkGLcall("glEnable(bind_target)"); - /* Bind the texture */ - glBindTexture(info.bind_target, src_surface->texture_name); - checkGLcall("glBindTexture"); + context_bind_texture(context, info.bind_target, src_surface->texture_name); /* Filtering for StretchRect */ glTexParameteri(info.bind_target, GL_TEXTURE_MAG_FILTER, - wined3d_gl_mag_filter(magLookup, Filter)); + wined3d_gl_mag_filter(magLookup, filter)); checkGLcall("glTexParameteri"); glTexParameteri(info.bind_target, GL_TEXTURE_MIN_FILTER, - wined3d_gl_min_mip_filter(minMipLookup, Filter, WINED3DTEXF_NONE)); + wined3d_gl_min_mip_filter(minMipLookup, filter, WINED3D_TEXF_NONE)); checkGLcall("glTexParameteri"); glTexParameteri(info.bind_target, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(info.bind_target, GL_TEXTURE_WRAP_T, GL_CLAMP); + if (context->gl_info->supported[EXT_TEXTURE_SRGB_DECODE]) + glTexParameteri(info.bind_target, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); checkGLcall("glTexEnvi"); @@ -330,17 +356,17 @@ void draw_textured_quad(struct wined3d_surface *src_surface, const RECT *src_rec glEnd(); /* Unbind the texture */ - glBindTexture(info.bind_target, 0); - checkGLcall("glBindTexture(info->bind_target, 0)"); + context_bind_texture(context, info.bind_target, 0); /* We changed the filtering settings on the texture. Inform the * container about this to get the filters reset properly next draw. */ if (src_surface->container.type == WINED3D_CONTAINER_TEXTURE) { struct wined3d_texture *texture = src_surface->container.u.texture; - texture->texture_rgb.states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT; - texture->texture_rgb.states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT; - texture->texture_rgb.states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE; + texture->texture_rgb.states[WINED3DTEXSTA_MAGFILTER] = WINED3D_TEXF_POINT; + texture->texture_rgb.states[WINED3DTEXSTA_MINFILTER] = WINED3D_TEXF_POINT; + texture->texture_rgb.states[WINED3DTEXSTA_MIPFILTER] = WINED3D_TEXF_NONE; + texture->texture_rgb.states[WINED3DTEXSTA_SRGBTEXTURE] = FALSE; } } @@ -482,7 +508,7 @@ static HRESULT surface_create_dib_section(struct wined3d_surface *surface) /* Now allocate a DC. */ surface->hDC = CreateCompatibleDC(0); - surface->dib.holdbitmap = SelectObject(surface->hDC, surface->dib.DIBsection); + SelectObject(surface->hDC, surface->dib.DIBsection); TRACE("Using wined3d palette %p.\n", surface->palette); SelectPalette(surface->hDC, surface->palette ? surface->palette->hpal : 0, FALSE); @@ -494,67 +520,65 @@ static HRESULT surface_create_dib_section(struct wined3d_surface *surface) return WINED3D_OK; } +static BOOL surface_need_pbo(const struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info) +{ + if (surface->resource.pool == WINED3D_POOL_SYSTEM_MEM) + return FALSE; + if (!(surface->flags & SFLAG_DYNLOCK)) + return FALSE; + if (surface->flags & (SFLAG_CONVERTED | SFLAG_NONPOW2 | SFLAG_PIN_SYSMEM)) + return FALSE; + if (!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) + return FALSE; + + return TRUE; +} + +static void surface_load_pbo(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info) +{ + struct wined3d_context *context; + GLenum error; + + context = context_acquire(surface->resource.device, NULL); + ENTER_GL(); + + GL_EXTCALL(glGenBuffersARB(1, &surface->pbo)); + error = glGetError(); + if (!surface->pbo || error != GL_NO_ERROR) + ERR("Failed to create a PBO with error %s (%#x).\n", debug_glerror(error), error); + + TRACE("Binding PBO %u.\n", surface->pbo); + + GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, surface->pbo)); + checkGLcall("glBindBufferARB"); + + GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, surface->resource.size + 4, + surface->resource.allocatedMemory, GL_STREAM_DRAW_ARB)); + checkGLcall("glBufferDataARB"); + + GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0)); + checkGLcall("glBindBufferARB"); + + /* We don't need the system memory anymore and we can't even use it for PBOs. */ + if (!(surface->flags & SFLAG_CLIENT)) + { + HeapFree(GetProcessHeap(), 0, surface->resource.heapMemory); + surface->resource.heapMemory = NULL; + } + surface->resource.allocatedMemory = NULL; + surface->flags |= SFLAG_PBO; + LEAVE_GL(); + context_release(context); +} + static void surface_prepare_system_memory(struct wined3d_surface *surface) { - struct wined3d_device *device = surface->resource.device; - const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; + const struct wined3d_gl_info *gl_info = &surface->resource.device->adapter->gl_info; TRACE("surface %p.\n", surface); - /* Performance optimization: Count how often a surface is locked, if it is - * locked regularly do not throw away the system memory copy. This avoids - * the need to download the surface from OpenGL all the time. The surface - * is still downloaded if the OpenGL texture is changed. */ - if (!(surface->flags & SFLAG_DYNLOCK)) - { - if (++surface->lockCount > MAXLOCKCOUNT) - { - TRACE("Surface is locked regularly, not freeing the system memory copy any more.\n"); - surface->flags |= SFLAG_DYNLOCK; - } - } - - /* Create a PBO for dynamically locked surfaces but don't do it for - * converted or NPOT surfaces. Also don't create a PBO for systemmem - * surfaces. */ - if (gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] && (surface->flags & SFLAG_DYNLOCK) - && !(surface->flags & (SFLAG_PBO | SFLAG_CONVERTED | SFLAG_NONPOW2)) - && (surface->resource.pool != WINED3DPOOL_SYSTEMMEM)) - { - struct wined3d_context *context; - GLenum error; - - context = context_acquire(device, NULL); - ENTER_GL(); - - GL_EXTCALL(glGenBuffersARB(1, &surface->pbo)); - error = glGetError(); - if (!surface->pbo || error != GL_NO_ERROR) - ERR("Failed to create a PBO with error %s (%#x).\n", debug_glerror(error), error); - - TRACE("Binding PBO %u.\n", surface->pbo); - - GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, surface->pbo)); - checkGLcall("glBindBufferARB"); - - GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, surface->resource.size + 4, - surface->resource.allocatedMemory, GL_STREAM_DRAW_ARB)); - checkGLcall("glBufferDataARB"); - - GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0)); - checkGLcall("glBindBufferARB"); - - /* We don't need the system memory anymore and we can't even use it for PBOs. */ - if (!(surface->flags & SFLAG_CLIENT)) - { - HeapFree(GetProcessHeap(), 0, surface->resource.heapMemory); - surface->resource.heapMemory = NULL; - } - surface->resource.allocatedMemory = NULL; - surface->flags |= SFLAG_PBO; - LEAVE_GL(); - context_release(context); - } + if (!(surface->flags & SFLAG_PBO) && surface_need_pbo(surface, gl_info)) + surface_load_pbo(surface, gl_info); else if (!(surface->resource.allocatedMemory || surface->flags & SFLAG_PBO)) { /* Whatever surface we have, make sure that there is memory allocated @@ -583,11 +607,10 @@ static void surface_evict_sysmem(struct wined3d_surface *surface) /* Context activation is done by the caller. */ static void surface_bind_and_dirtify(struct wined3d_surface *surface, - const struct wined3d_gl_info *gl_info, BOOL srgb) + struct wined3d_context *context, BOOL srgb) { struct wined3d_device *device = surface->resource.device; DWORD active_sampler; - GLint active_texture; /* We don't need a specific texture unit, but after binding the texture * the current unit is dirty. Read the unit back instead of switching to @@ -597,21 +620,12 @@ static void surface_bind_and_dirtify(struct wined3d_surface *surface, * To be more specific, this is tricky because we can implicitly be * called from sampler() in state.c. This means we can't touch anything * other than whatever happens to be the currently active texture, or we - * would risk marking already applied sampler states dirty again. - * - * TODO: Track the current active texture per GL context instead of using - * glGet(). */ - - ENTER_GL(); - glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); - LEAVE_GL(); - active_sampler = device->rev_tex_unit_map[active_texture - GL_TEXTURE0_ARB]; + * would risk marking already applied sampler states dirty again. */ + active_sampler = device->rev_tex_unit_map[context->active_texture]; if (active_sampler != WINED3D_UNMAPPED_STAGE) - { - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(active_sampler)); - } - surface_bind(surface, gl_info, srgb); + device_invalidate_state(device, STATE_SAMPLER(active_sampler)); + surface_bind(surface, context, srgb); } static void surface_force_reload(struct wined3d_surface *surface) @@ -627,13 +641,13 @@ static void surface_release_client_storage(struct wined3d_surface *surface) glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE); if (surface->texture_name) { - surface_bind_and_dirtify(surface, context->gl_info, FALSE); + surface_bind_and_dirtify(surface, context, FALSE); glTexImage2D(surface->texture_target, surface->texture_level, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); } if (surface->texture_name_srgb) { - surface_bind_and_dirtify(surface, context->gl_info, TRUE); + surface_bind_and_dirtify(surface, context, TRUE); glTexImage2D(surface->texture_target, surface->texture_level, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); } @@ -706,7 +720,7 @@ static HRESULT surface_private_setup(struct wined3d_surface *surface) * Blts. Some apps (e.g. Swat 3) create textures with a Height of * 16 and a Width > 3000 and blt 16x16 letter areas from them to * the render target. */ - if (surface->resource.pool == WINED3DPOOL_DEFAULT || surface->resource.pool == WINED3DPOOL_MANAGED) + if (surface->resource.pool == WINED3D_POOL_DEFAULT || surface->resource.pool == WINED3D_POOL_MANAGED) { WARN("Unable to allocate a surface which exceeds the maximum OpenGL texture size.\n"); return WINED3DERR_NOTAVAILABLE; @@ -750,7 +764,8 @@ static HRESULT surface_private_setup(struct wined3d_surface *surface) return WINED3DERR_INVALIDCALL; } - surface->flags |= SFLAG_INSYSMEM; + if (surface->resource.usage & WINED3DUSAGE_DEPTHSTENCIL) + surface->flags |= SFLAG_LOST; return WINED3D_OK; } @@ -806,7 +821,7 @@ static void surface_realize_palette(struct wined3d_surface *surface) /* Propagate the changes to the drawable when we have a palette. */ if (surface->resource.usage & WINED3DUSAGE_RENDERTARGET) - surface_load_location(surface, SFLAG_INDRAWABLE, NULL); + surface_load_location(surface, surface->draw_binding, NULL); } static HRESULT surface_draw_overlay(struct wined3d_surface *surface) @@ -824,19 +839,12 @@ static HRESULT surface_draw_overlay(struct wined3d_surface *surface) surface->overlay_dest->flags |= SFLAG_INOVERLAYDRAW; hr = wined3d_surface_blt(surface->overlay_dest, &surface->overlay_destrect, surface, - &surface->overlay_srcrect, WINEDDBLT_WAIT, NULL, WINED3DTEXF_LINEAR); + &surface->overlay_srcrect, WINEDDBLT_WAIT, NULL, WINED3D_TEXF_LINEAR); surface->overlay_dest->flags &= ~SFLAG_INOVERLAYDRAW; return hr; } -static void surface_preload(struct wined3d_surface *surface) -{ - TRACE("surface %p.\n", surface); - - surface_internal_preload(surface, SRGB_ANY); -} - static void surface_map(struct wined3d_surface *surface, const RECT *rect, DWORD flags) { struct wined3d_device *device = surface->resource.device; @@ -859,11 +867,7 @@ static void surface_map(struct wined3d_surface *surface, const RECT *rect, DWORD && rect->right == surface->resource.width && rect->bottom == surface->resource.height) pass_rect = NULL; - - if (!(wined3d_settings.rendertargetlock_mode == RTL_DISABLE - && ((surface->container.type == WINED3D_CONTAINER_SWAPCHAIN) - || surface == device->fb.render_targets[0]))) - surface_load_location(surface, SFLAG_INSYSMEM, pass_rect); + surface_load_location(surface, SFLAG_INSYSMEM, pass_rect); } if (surface->flags & SFLAG_PBO) @@ -901,14 +905,14 @@ static void surface_map(struct wined3d_surface *surface, const RECT *rect, DWORD surface_add_dirty_rect(surface, NULL); else { - WINED3DBOX b; + struct wined3d_box b; - b.Left = rect->left; - b.Top = rect->top; - b.Right = rect->right; - b.Bottom = rect->bottom; - b.Front = 0; - b.Back = 1; + b.left = rect->left; + b.top = rect->top; + b.right = rect->right; + b.bottom = rect->bottom; + b.front = 0; + b.back = 1; surface_add_dirty_rect(surface, &b); } } @@ -955,17 +959,6 @@ static void surface_unmap(struct wined3d_surface *surface) if (surface->container.type == WINED3D_CONTAINER_SWAPCHAIN || (device->fb.render_targets && surface == device->fb.render_targets[0])) { - if (wined3d_settings.rendertargetlock_mode == RTL_DISABLE) - { - static BOOL warned = FALSE; - if (!warned) - { - ERR("The application tries to write to the render target, but render target locking is disabled.\n"); - warned = TRUE; - } - goto done; - } - if (!surface->dirtyRect.left && !surface->dirtyRect.top && surface->dirtyRect.right == surface->resource.width && surface->dirtyRect.bottom == surface->resource.height) @@ -979,7 +972,7 @@ static void surface_unmap(struct wined3d_surface *surface) surface->flags |= SFLAG_INSYSMEM; } - surface_load_location(surface, SFLAG_INDRAWABLE, fullsurface ? NULL : &surface->dirtyRect); + surface_load_location(surface, surface->draw_binding, fullsurface ? NULL : &surface->dirtyRect); /* Partial rectangle tracking is not commonly implemented, it is only * done for render targets. INSYSMEM was set before to tell @@ -990,7 +983,7 @@ static void surface_unmap(struct wined3d_surface *surface) * date because only a subrectangle was read in Map(). */ if (!fullsurface) { - surface_modify_location(surface, SFLAG_INDRAWABLE, TRUE); + surface_modify_location(surface, surface->draw_binding, TRUE); surface_evict_sysmem(surface); } @@ -1007,72 +1000,10 @@ static void surface_unmap(struct wined3d_surface *surface) done: /* Overlays have to be redrawn manually after changes with the GL implementation */ if (surface->overlay_dest) - surface->surface_ops->surface_draw_overlay(surface); + surface_draw_overlay(surface); } -static HRESULT surface_getdc(struct wined3d_surface *surface) -{ - WINED3DLOCKED_RECT lock; - HRESULT hr; - - TRACE("surface %p.\n", surface); - - /* Create a DIB section if there isn't a dc yet. */ - if (!surface->hDC) - { - if (surface->flags & SFLAG_CLIENT) - { - surface_load_location(surface, SFLAG_INSYSMEM, NULL); - surface_release_client_storage(surface); - } - hr = surface_create_dib_section(surface); - if (FAILED(hr)) - return WINED3DERR_INVALIDCALL; - - /* Use the DIB section from now on if we are not using a PBO. */ - if (!(surface->flags & SFLAG_PBO)) - surface->resource.allocatedMemory = surface->dib.bitmap_data; - } - - /* Map the surface. */ - hr = wined3d_surface_map(surface, &lock, NULL, 0); - if (FAILED(hr)) - ERR("Map failed, hr %#x.\n", hr); - - /* Sync the DIB with the PBO. This can't be done earlier because Map() - * activates the allocatedMemory. */ - if (surface->flags & SFLAG_PBO) - memcpy(surface->dib.bitmap_data, surface->resource.allocatedMemory, surface->dib.bitmap_size); - - return hr; -} - -static HRESULT surface_flip(struct wined3d_surface *surface, struct wined3d_surface *override) -{ - TRACE("surface %p, override %p.\n", surface, override); - - /* Flipping is only supported on render targets and overlays. */ - if (!(surface->resource.usage & (WINED3DUSAGE_RENDERTARGET | WINED3DUSAGE_OVERLAY))) - { - WARN("Tried to flip a non-render target, non-overlay surface.\n"); - return WINEDDERR_NOTFLIPPABLE; - } - - if (surface->resource.usage & WINED3DUSAGE_OVERLAY) - { - flip_surface(surface, override); - - /* Update the overlay if it is visible */ - if (surface->overlay_dest) - return surface->surface_ops->surface_draw_overlay(surface); - else - return WINED3D_OK; - } - - return WINED3D_OK; -} - -static BOOL surface_is_full_rect(struct wined3d_surface *surface, const RECT *r) +static BOOL surface_is_full_rect(const struct wined3d_surface *surface, const RECT *r) { if ((r->left && r->right) || abs(r->right - r->left) != surface->resource.width) return FALSE; @@ -1081,7 +1012,7 @@ static BOOL surface_is_full_rect(struct wined3d_surface *surface, const RECT *r) return TRUE; } -static void wined3d_surface_depth_blt_fbo(struct wined3d_device *device, struct wined3d_surface *src_surface, +static void wined3d_surface_depth_blt_fbo(const struct wined3d_device *device, struct wined3d_surface *src_surface, const RECT *src_rect, struct wined3d_surface *dst_surface, const RECT *dst_rect) { const struct wined3d_gl_info *gl_info; @@ -1147,21 +1078,21 @@ static void wined3d_surface_depth_blt_fbo(struct wined3d_device *device, struct if (gl_mask & GL_DEPTH_BUFFER_BIT) { glDepthMask(GL_TRUE); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_ZWRITEENABLE)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ZWRITEENABLE)); } if (gl_mask & GL_STENCIL_BUFFER_BIT) { if (context->gl_info->supported[EXT_STENCIL_TWO_SIDE]) { glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_TWOSIDEDSTENCILMODE)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_TWOSIDEDSTENCILMODE)); } glStencilMask(~0U); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_STENCILWRITEMASK)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK)); } glDisable(GL_SCISSOR_TEST); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE)); gl_info->fbo_ops.glBlitFramebuffer(src_rect->left, src_rect->top, src_rect->right, src_rect->bottom, dst_rect->left, dst_rect->top, dst_rect->right, dst_rect->bottom, gl_mask, GL_NEAREST); @@ -1175,15 +1106,138 @@ static void wined3d_surface_depth_blt_fbo(struct wined3d_device *device, struct context_release(context); } +/* Blit between surface locations. Onscreen on different swapchains is not supported. + * Depth / stencil is not supported. */ +static void surface_blt_fbo(const struct wined3d_device *device, enum wined3d_texture_filter_type filter, + struct wined3d_surface *src_surface, DWORD src_location, const RECT *src_rect_in, + struct wined3d_surface *dst_surface, DWORD dst_location, const RECT *dst_rect_in) +{ + const struct wined3d_gl_info *gl_info; + struct wined3d_context *context; + RECT src_rect, dst_rect; + GLenum gl_filter; + GLenum buffer; + + TRACE("device %p, filter %s,\n", device, debug_d3dtexturefiltertype(filter)); + TRACE("src_surface %p, src_location %s, src_rect %s,\n", + src_surface, debug_surflocation(src_location), wine_dbgstr_rect(src_rect_in)); + TRACE("dst_surface %p, dst_location %s, dst_rect %s.\n", + dst_surface, debug_surflocation(dst_location), wine_dbgstr_rect(dst_rect_in)); + + src_rect = *src_rect_in; + dst_rect = *dst_rect_in; + + switch (filter) + { + case WINED3D_TEXF_LINEAR: + gl_filter = GL_LINEAR; + break; + + default: + FIXME("Unsupported filter mode %s (%#x).\n", debug_d3dtexturefiltertype(filter), filter); + case WINED3D_TEXF_NONE: + case WINED3D_TEXF_POINT: + gl_filter = GL_NEAREST; + break; + } + + /* Resolve the source surface first if needed. */ + if (src_location == SFLAG_INRB_MULTISAMPLE + && (src_surface->resource.format->id != dst_surface->resource.format->id + || abs(src_rect.bottom - src_rect.top) != abs(dst_rect.bottom - dst_rect.top) + || abs(src_rect.right - src_rect.left) != abs(dst_rect.right - dst_rect.left))) + src_location = SFLAG_INRB_RESOLVED; + + /* Make sure the locations are up-to-date. Loading the destination + * surface isn't required if the entire surface is overwritten. (And is + * in fact harmful if we're being called by surface_load_location() with + * the purpose of loading the destination surface.) */ + surface_load_location(src_surface, src_location, NULL); + if (!surface_is_full_rect(dst_surface, &dst_rect)) + surface_load_location(dst_surface, dst_location, NULL); + + if (src_location == SFLAG_INDRAWABLE) context = context_acquire(device, src_surface); + else if (dst_location == SFLAG_INDRAWABLE) context = context_acquire(device, dst_surface); + else context = context_acquire(device, NULL); + + if (!context->valid) + { + context_release(context); + WARN("Invalid context, skipping blit.\n"); + return; + } + + gl_info = context->gl_info; + + if (src_location == SFLAG_INDRAWABLE) + { + TRACE("Source surface %p is onscreen.\n", src_surface); + buffer = surface_get_gl_buffer(src_surface); + surface_translate_drawable_coords(src_surface, context->win_handle, &src_rect); + } + else + { + TRACE("Source surface %p is offscreen.\n", src_surface); + buffer = GL_COLOR_ATTACHMENT0; + } + + ENTER_GL(); + context_apply_fbo_state_blit(context, GL_READ_FRAMEBUFFER, src_surface, NULL, src_location); + glReadBuffer(buffer); + checkGLcall("glReadBuffer()"); + context_check_fbo_status(context, GL_READ_FRAMEBUFFER); + LEAVE_GL(); + + if (dst_location == SFLAG_INDRAWABLE) + { + TRACE("Destination surface %p is onscreen.\n", dst_surface); + buffer = surface_get_gl_buffer(dst_surface); + surface_translate_drawable_coords(dst_surface, context->win_handle, &dst_rect); + } + else + { + TRACE("Destination surface %p is offscreen.\n", dst_surface); + buffer = GL_COLOR_ATTACHMENT0; + } + + ENTER_GL(); + context_apply_fbo_state_blit(context, GL_DRAW_FRAMEBUFFER, dst_surface, NULL, dst_location); + context_set_draw_buffer(context, buffer); + context_check_fbo_status(context, GL_DRAW_FRAMEBUFFER); + context_invalidate_state(context, STATE_FRAMEBUFFER); + + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3)); + + glDisable(GL_SCISSOR_TEST); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE)); + + gl_info->fbo_ops.glBlitFramebuffer(src_rect.left, src_rect.top, src_rect.right, src_rect.bottom, + dst_rect.left, dst_rect.top, dst_rect.right, dst_rect.bottom, GL_COLOR_BUFFER_BIT, gl_filter); + checkGLcall("glBlitFramebuffer()"); + + LEAVE_GL(); + + if (wined3d_settings.strict_draw_ordering + || (dst_location == SFLAG_INDRAWABLE + && dst_surface->container.u.swapchain->front_buffer == dst_surface)) + wglFlush(); + + context_release(context); +} + static BOOL fbo_blit_supported(const struct wined3d_gl_info *gl_info, enum wined3d_blit_op blit_op, - const RECT *src_rect, DWORD src_usage, WINED3DPOOL src_pool, const struct wined3d_format *src_format, - const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool, const struct wined3d_format *dst_format) + const RECT *src_rect, DWORD src_usage, enum wined3d_pool src_pool, const struct wined3d_format *src_format, + const RECT *dst_rect, DWORD dst_usage, enum wined3d_pool dst_pool, const struct wined3d_format *dst_format) { if ((wined3d_settings.offscreen_rendering_mode != ORM_FBO) || !gl_info->fbo_ops.glBlitFramebuffer) return FALSE; /* Source and/or destination need to be on the GL side */ - if (src_pool == WINED3DPOOL_SYSTEMMEM || dst_pool == WINED3DPOOL_SYSTEMMEM) + if (src_pool == WINED3D_POOL_SYSTEM_MEM || dst_pool == WINED3D_POOL_SYSTEM_MEM) return FALSE; switch (blit_op) @@ -1214,7 +1268,74 @@ static BOOL fbo_blit_supported(const struct wined3d_gl_info *gl_info, enum wined return TRUE; } -static BOOL surface_convert_depth_to_float(struct wined3d_surface *surface, DWORD depth, float *float_depth) +/* This function checks if the primary render target uses the 8bit paletted format. */ +static BOOL primary_render_target_is_p8(const struct wined3d_device *device) +{ + if (device->fb.render_targets && device->fb.render_targets[0]) + { + const struct wined3d_surface *render_target = device->fb.render_targets[0]; + if ((render_target->resource.usage & WINED3DUSAGE_RENDERTARGET) + && (render_target->resource.format->id == WINED3DFMT_P8_UINT)) + return TRUE; + } + return FALSE; +} + +static BOOL surface_convert_color_to_float(const struct wined3d_surface *surface, + DWORD color, struct wined3d_color *float_color) +{ + const struct wined3d_format *format = surface->resource.format; + const struct wined3d_device *device = surface->resource.device; + + switch (format->id) + { + case WINED3DFMT_P8_UINT: + if (surface->palette) + { + float_color->r = surface->palette->palents[color].peRed / 255.0f; + float_color->g = surface->palette->palents[color].peGreen / 255.0f; + float_color->b = surface->palette->palents[color].peBlue / 255.0f; + } + else + { + float_color->r = 0.0f; + float_color->g = 0.0f; + float_color->b = 0.0f; + } + float_color->a = primary_render_target_is_p8(device) ? color / 255.0f : 1.0f; + break; + + case WINED3DFMT_B5G6R5_UNORM: + float_color->r = ((color >> 11) & 0x1f) / 31.0f; + float_color->g = ((color >> 5) & 0x3f) / 63.0f; + float_color->b = (color & 0x1f) / 31.0f; + float_color->a = 1.0f; + break; + + case WINED3DFMT_B8G8R8_UNORM: + case WINED3DFMT_B8G8R8X8_UNORM: + float_color->r = D3DCOLOR_R(color); + float_color->g = D3DCOLOR_G(color); + float_color->b = D3DCOLOR_B(color); + float_color->a = 1.0f; + break; + + case WINED3DFMT_B8G8R8A8_UNORM: + float_color->r = D3DCOLOR_R(color); + float_color->g = D3DCOLOR_G(color); + float_color->b = D3DCOLOR_B(color); + float_color->a = D3DCOLOR_A(color); + break; + + default: + ERR("Unhandled conversion from %s to floating point.\n", debug_d3dformat(format->id)); + return FALSE; + } + + return TRUE; +} + +static BOOL surface_convert_depth_to_float(const struct wined3d_surface *surface, DWORD depth, float *float_depth) { const struct wined3d_format *format = surface->resource.format; @@ -1275,32 +1396,174 @@ static HRESULT wined3d_surface_depth_blt(struct wined3d_surface *src_surface, co wined3d_surface_depth_blt_fbo(device, src_surface, src_rect, dst_surface, dst_rect); - surface_modify_ds_location(dst_surface, SFLAG_DS_OFFSCREEN, + surface_modify_ds_location(dst_surface, SFLAG_INTEXTURE, dst_surface->ds_current_size.cx, dst_surface->ds_current_size.cy); - surface_modify_location(dst_surface, SFLAG_INDRAWABLE, TRUE); return WINED3D_OK; } /* Do not call while under the GL lock. */ -static HRESULT surface_blt(struct wined3d_surface *dst_surface, const RECT *dst_rect_in, +HRESULT CDECL wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst_rect_in, struct wined3d_surface *src_surface, const RECT *src_rect_in, DWORD flags, - const WINEDDBLTFX *fx, WINED3DTEXTUREFILTERTYPE filter) + const WINEDDBLTFX *fx, enum wined3d_texture_filter_type filter) { + struct wined3d_swapchain *src_swapchain, *dst_swapchain; struct wined3d_device *device = dst_surface->resource.device; DWORD src_ds_flags, dst_ds_flags; + RECT src_rect, dst_rect; + BOOL scale, convert; + + static const DWORD simple_blit = WINEDDBLT_ASYNC + | WINEDDBLT_COLORFILL + | WINEDDBLT_WAIT + | WINEDDBLT_DEPTHFILL + | WINEDDBLT_DONOTWAIT; TRACE("dst_surface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p, filter %s.\n", dst_surface, wine_dbgstr_rect(dst_rect_in), src_surface, wine_dbgstr_rect(src_rect_in), flags, fx, debug_d3dtexturefiltertype(filter)); TRACE("Usage is %s.\n", debug_d3dusage(dst_surface->resource.usage)); + if (fx) + { + TRACE("dwSize %#x.\n", fx->dwSize); + TRACE("dwDDFX %#x.\n", fx->dwDDFX); + TRACE("dwROP %#x.\n", fx->dwROP); + TRACE("dwDDROP %#x.\n", fx->dwDDROP); + TRACE("dwRotationAngle %#x.\n", fx->dwRotationAngle); + TRACE("dwZBufferOpCode %#x.\n", fx->dwZBufferOpCode); + TRACE("dwZBufferLow %#x.\n", fx->dwZBufferLow); + TRACE("dwZBufferHigh %#x.\n", fx->dwZBufferHigh); + TRACE("dwZBufferBaseDest %#x.\n", fx->dwZBufferBaseDest); + TRACE("dwZDestConstBitDepth %#x.\n", fx->dwZDestConstBitDepth); + TRACE("lpDDSZBufferDest %p.\n", fx->u1.lpDDSZBufferDest); + TRACE("dwZSrcConstBitDepth %#x.\n", fx->dwZSrcConstBitDepth); + TRACE("lpDDSZBufferSrc %p.\n", fx->u2.lpDDSZBufferSrc); + TRACE("dwAlphaEdgeBlendBitDepth %#x.\n", fx->dwAlphaEdgeBlendBitDepth); + TRACE("dwAlphaEdgeBlend %#x.\n", fx->dwAlphaEdgeBlend); + TRACE("dwReserved %#x.\n", fx->dwReserved); + TRACE("dwAlphaDestConstBitDepth %#x.\n", fx->dwAlphaDestConstBitDepth); + TRACE("lpDDSAlphaDest %p.\n", fx->u3.lpDDSAlphaDest); + TRACE("dwAlphaSrcConstBitDepth %#x.\n", fx->dwAlphaSrcConstBitDepth); + TRACE("lpDDSAlphaSrc %p.\n", fx->u4.lpDDSAlphaSrc); + TRACE("lpDDSPattern %p.\n", fx->u5.lpDDSPattern); + TRACE("ddckDestColorkey {%#x, %#x}.\n", + fx->ddckDestColorkey.color_space_low_value, + fx->ddckDestColorkey.color_space_high_value); + TRACE("ddckSrcColorkey {%#x, %#x}.\n", + fx->ddckSrcColorkey.color_space_low_value, + fx->ddckSrcColorkey.color_space_high_value); + } + if ((dst_surface->flags & SFLAG_LOCKED) || (src_surface && (src_surface->flags & SFLAG_LOCKED))) { - WARN(" Surface is busy, returning DDERR_SURFACEBUSY\n"); + WARN("Surface is busy, returning WINEDDERR_SURFACEBUSY.\n"); return WINEDDERR_SURFACEBUSY; } + surface_get_rect(dst_surface, dst_rect_in, &dst_rect); + + if (dst_rect.left >= dst_rect.right || dst_rect.top >= dst_rect.bottom + || dst_rect.left > dst_surface->resource.width || dst_rect.left < 0 + || dst_rect.top > dst_surface->resource.height || dst_rect.top < 0 + || dst_rect.right > dst_surface->resource.width || dst_rect.right < 0 + || dst_rect.bottom > dst_surface->resource.height || dst_rect.bottom < 0) + { + WARN("The application gave us a bad destination rectangle.\n"); + return WINEDDERR_INVALIDRECT; + } + + if (src_surface) + { + surface_get_rect(src_surface, src_rect_in, &src_rect); + + if (src_rect.left >= src_rect.right || src_rect.top >= src_rect.bottom + || src_rect.left > src_surface->resource.width || src_rect.left < 0 + || src_rect.top > src_surface->resource.height || src_rect.top < 0 + || src_rect.right > src_surface->resource.width || src_rect.right < 0 + || src_rect.bottom > src_surface->resource.height || src_rect.bottom < 0) + { + WARN("Application gave us bad source rectangle for Blt.\n"); + return WINEDDERR_INVALIDRECT; + } + } + else + { + memset(&src_rect, 0, sizeof(src_rect)); + } + + if (!fx || !(fx->dwDDFX)) + flags &= ~WINEDDBLT_DDFX; + + if (flags & WINEDDBLT_WAIT) + flags &= ~WINEDDBLT_WAIT; + + if (flags & WINEDDBLT_ASYNC) + { + static unsigned int once; + + if (!once++) + FIXME("Can't handle WINEDDBLT_ASYNC flag.\n"); + flags &= ~WINEDDBLT_ASYNC; + } + + /* WINEDDBLT_DONOTWAIT appeared in DX7. */ + if (flags & WINEDDBLT_DONOTWAIT) + { + static unsigned int once; + + if (!once++) + FIXME("Can't handle WINEDDBLT_DONOTWAIT flag.\n"); + flags &= ~WINEDDBLT_DONOTWAIT; + } + + if (!device->d3d_initialized) + { + WARN("D3D not initialized, using fallback.\n"); + goto cpu; + } + + /* We want to avoid invalidating the sysmem location for converted + * surfaces, since otherwise we'd have to convert the data back when + * locking them. */ + if (dst_surface->flags & SFLAG_CONVERTED) + { + WARN("Converted surface, using CPU blit.\n"); + return surface_cpu_blt(dst_surface, &dst_rect, src_surface, &src_rect, flags, fx, filter); + } + + if (flags & ~simple_blit) + { + WARN("Using fallback for complex blit (%#x).\n", flags); + goto fallback; + } + + if (src_surface && src_surface->container.type == WINED3D_CONTAINER_SWAPCHAIN) + src_swapchain = src_surface->container.u.swapchain; + else + src_swapchain = NULL; + + if (dst_surface->container.type == WINED3D_CONTAINER_SWAPCHAIN) + dst_swapchain = dst_surface->container.u.swapchain; + else + dst_swapchain = NULL; + + /* This isn't strictly needed. FBO blits for example could deal with + * cross-swapchain blits by first downloading the source to a texture + * before switching to the destination context. We just have this here to + * not have to deal with the issue, since cross-swapchain blits should be + * rare. */ + if (src_swapchain && dst_swapchain && src_swapchain != dst_swapchain) + { + FIXME("Using fallback for cross-swapchain blit.\n"); + goto fallback; + } + + scale = src_surface + && (src_rect.right - src_rect.left != dst_rect.right - dst_rect.left + || src_rect.bottom - src_rect.top != dst_rect.bottom - dst_rect.top); + convert = src_surface && src_surface->resource.format->id != dst_surface->resource.format->id; + dst_ds_flags = dst_surface->resource.format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL); if (src_surface) src_ds_flags = src_surface->resource.format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL); @@ -1312,22 +1575,17 @@ static HRESULT surface_blt(struct wined3d_surface *dst_surface, const RECT *dst_ if (flags & WINEDDBLT_DEPTHFILL) { float depth; - RECT rect; TRACE("Depth fill.\n"); - surface_get_rect(dst_surface, dst_rect_in, &rect); - if (!surface_convert_depth_to_float(dst_surface, fx->u5.dwFillDepth, &depth)) return WINED3DERR_INVALIDCALL; - if (SUCCEEDED(wined3d_surface_depth_fill(dst_surface, &rect, depth))) + if (SUCCEEDED(wined3d_surface_depth_fill(dst_surface, &dst_rect, depth))) return WINED3D_OK; } else { - RECT src_rect, dst_rect; - /* Accessing depth / stencil surfaces is supposed to fail while in * a scene, except for fills, which seem to work. */ if (device->inScene) @@ -1342,172 +1600,180 @@ static HRESULT surface_blt(struct wined3d_surface *dst_surface, const RECT *dst_ return WINED3DERR_INVALIDCALL; } - if (src_rect_in && (src_rect_in->top || src_rect_in->left - || src_rect_in->bottom != src_surface->resource.height - || src_rect_in->right != src_surface->resource.width)) + if (src_rect.top || src_rect.left + || src_rect.bottom != src_surface->resource.height + || src_rect.right != src_surface->resource.width) { WARN("Rejecting depth / stencil blit with invalid source rect %s.\n", - wine_dbgstr_rect(src_rect_in)); + wine_dbgstr_rect(&src_rect)); return WINED3DERR_INVALIDCALL; } - if (dst_rect_in && (dst_rect_in->top || dst_rect_in->left - || dst_rect_in->bottom != dst_surface->resource.height - || dst_rect_in->right != dst_surface->resource.width)) + if (dst_rect.top || dst_rect.left + || dst_rect.bottom != dst_surface->resource.height + || dst_rect.right != dst_surface->resource.width) { WARN("Rejecting depth / stencil blit with invalid destination rect %s.\n", - wine_dbgstr_rect(src_rect_in)); + wine_dbgstr_rect(&src_rect)); return WINED3DERR_INVALIDCALL; } - if (src_surface->resource.height != dst_surface->resource.height - || src_surface->resource.width != dst_surface->resource.width) + if (scale) { WARN("Rejecting depth / stencil blit with mismatched surface sizes.\n"); return WINED3DERR_INVALIDCALL; } - surface_get_rect(src_surface, src_rect_in, &src_rect); - surface_get_rect(dst_surface, dst_rect_in, &dst_rect); - if (SUCCEEDED(wined3d_surface_depth_blt(src_surface, &src_rect, dst_surface, &dst_rect))) return WINED3D_OK; } } + else + { + /* In principle this would apply to depth blits as well, but we don't + * implement those in the CPU blitter at the moment. */ + if ((dst_surface->flags & SFLAG_INSYSMEM) + && (!src_surface || (src_surface->flags & SFLAG_INSYSMEM))) + { + if (scale) + TRACE("Not doing sysmem blit because of scaling.\n"); + else if (convert) + TRACE("Not doing sysmem blit because of format conversion.\n"); + else + return surface_cpu_blt(dst_surface, &dst_rect, src_surface, &src_rect, flags, fx, filter); + } + + if (flags & WINEDDBLT_COLORFILL) + { + struct wined3d_color color; + + TRACE("Color fill.\n"); + + if (!surface_convert_color_to_float(dst_surface, fx->u5.dwFillColor, &color)) + goto fallback; + + if (SUCCEEDED(surface_color_fill(dst_surface, &dst_rect, &color))) + return WINED3D_OK; + } + else + { + TRACE("Color blit.\n"); + + /* Upload */ + if ((src_surface->flags & SFLAG_INSYSMEM) && !(dst_surface->flags & SFLAG_INSYSMEM)) + { + if (scale) + TRACE("Not doing upload because of scaling.\n"); + else if (convert) + TRACE("Not doing upload because of format conversion.\n"); + else + { + POINT dst_point = {dst_rect.left, dst_rect.top}; + + if (SUCCEEDED(surface_upload_from_surface(dst_surface, &dst_point, src_surface, &src_rect))) + { + if (!surface_is_offscreen(dst_surface)) + surface_load_location(dst_surface, dst_surface->draw_binding, NULL); + return WINED3D_OK; + } + } + } + + /* Use present for back -> front blits. The idea behind this is + * that present is potentially faster than a blit, in particular + * when FBO blits aren't available. Some ddraw applications like + * Half-Life and Prince of Persia 3D use Blt() from the backbuffer + * to the frontbuffer instead of doing a Flip(). D3D8 and D3D9 + * applications can't blit directly to the frontbuffer. */ + if (dst_swapchain && dst_swapchain->back_buffers + && dst_surface == dst_swapchain->front_buffer + && src_surface == dst_swapchain->back_buffers[0]) + { + enum wined3d_swap_effect swap_effect = dst_swapchain->desc.swap_effect; + + TRACE("Using present for backbuffer -> frontbuffer blit.\n"); + + /* Set the swap effect to COPY, we don't want the backbuffer + * to become undefined. */ + dst_swapchain->desc.swap_effect = WINED3D_SWAP_EFFECT_COPY; + wined3d_swapchain_present(dst_swapchain, NULL, NULL, dst_swapchain->win_handle, NULL, 0); + dst_swapchain->desc.swap_effect = swap_effect; + + return WINED3D_OK; + } + + if (fbo_blit_supported(&device->adapter->gl_info, WINED3D_BLIT_OP_COLOR_BLIT, + &src_rect, src_surface->resource.usage, src_surface->resource.pool, src_surface->resource.format, + &dst_rect, dst_surface->resource.usage, dst_surface->resource.pool, dst_surface->resource.format)) + { + TRACE("Using FBO blit.\n"); + + surface_blt_fbo(device, filter, + src_surface, src_surface->draw_binding, &src_rect, + dst_surface, dst_surface->draw_binding, &dst_rect); + surface_modify_location(dst_surface, dst_surface->draw_binding, TRUE); + return WINED3D_OK; + } + + if (arbfp_blit.blit_supported(&device->adapter->gl_info, WINED3D_BLIT_OP_COLOR_BLIT, + &src_rect, src_surface->resource.usage, src_surface->resource.pool, src_surface->resource.format, + &dst_rect, dst_surface->resource.usage, dst_surface->resource.pool, dst_surface->resource.format)) + { + TRACE("Using arbfp blit.\n"); + + if (SUCCEEDED(arbfp_blit_surface(device, filter, src_surface, &src_rect, dst_surface, &dst_rect))) + return WINED3D_OK; + } + } + } + +fallback: /* Special cases for render targets. */ if ((dst_surface->resource.usage & WINED3DUSAGE_RENDERTARGET) || (src_surface && (src_surface->resource.usage & WINED3DUSAGE_RENDERTARGET))) { - if (SUCCEEDED(IWineD3DSurfaceImpl_BltOverride(dst_surface, dst_rect_in, - src_surface, src_rect_in, flags, fx, filter))) + if (SUCCEEDED(IWineD3DSurfaceImpl_BltOverride(dst_surface, &dst_rect, + src_surface, &src_rect, flags, fx, filter))) return WINED3D_OK; } +cpu: + /* For the rest call the X11 surface implementation. For render targets * this should be implemented OpenGL accelerated in BltOverride, other * blits are rather rare. */ - return surface_cpu_blt(dst_surface, dst_rect_in, src_surface, src_rect_in, flags, fx, filter); + return surface_cpu_blt(dst_surface, &dst_rect, src_surface, &src_rect, flags, fx, filter); } -/* Do not call while under the GL lock. */ -static HRESULT surface_bltfast(struct wined3d_surface *dst_surface, DWORD dst_x, DWORD dst_y, - struct wined3d_surface *src_surface, const RECT *src_rect_in, DWORD trans) +HRESULT CDECL wined3d_surface_get_render_target_data(struct wined3d_surface *surface, + struct wined3d_surface *render_target) { - struct wined3d_device *device = dst_surface->resource.device; + TRACE("surface %p, render_target %p.\n", surface, render_target); - TRACE("dst_surface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n", - dst_surface, dst_x, dst_y, src_surface, wine_dbgstr_rect(src_rect_in), trans); + /* TODO: Check surface sizes, pools, etc. */ - if ((dst_surface->flags & SFLAG_LOCKED) || (src_surface->flags & SFLAG_LOCKED)) - { - WARN("Surface is busy, returning WINEDDERR_SURFACEBUSY.\n"); - return WINEDDERR_SURFACEBUSY; - } - - if (device->inScene && (dst_surface == device->fb.depth_stencil || src_surface == device->fb.depth_stencil)) - { - WARN("Attempt to access the depth / stencil surface while in a scene.\n"); + if (render_target->resource.multisample_type) return WINED3DERR_INVALIDCALL; - } - /* Special cases for RenderTargets */ - if ((dst_surface->resource.usage & WINED3DUSAGE_RENDERTARGET) - || (src_surface->resource.usage & WINED3DUSAGE_RENDERTARGET)) - { - - RECT src_rect, dst_rect; - DWORD flags = 0; - - surface_get_rect(src_surface, src_rect_in, &src_rect); - - dst_rect.left = dst_x; - dst_rect.top = dst_y; - dst_rect.right = dst_x + src_rect.right - src_rect.left; - dst_rect.bottom = dst_y + src_rect.bottom - src_rect.top; - - /* Convert BltFast flags into Blt ones because BltOverride is called - * from Blt as well. */ - if (trans & WINEDDBLTFAST_SRCCOLORKEY) - flags |= WINEDDBLT_KEYSRC; - if (trans & WINEDDBLTFAST_DESTCOLORKEY) - flags |= WINEDDBLT_KEYDEST; - if (trans & WINEDDBLTFAST_WAIT) - flags |= WINEDDBLT_WAIT; - if (trans & WINEDDBLTFAST_DONOTWAIT) - flags |= WINEDDBLT_DONOTWAIT; - - if (SUCCEEDED(IWineD3DSurfaceImpl_BltOverride(dst_surface, - &dst_rect, src_surface, &src_rect, flags, NULL, WINED3DTEXF_POINT))) - return WINED3D_OK; - } - - return surface_cpu_bltfast(dst_surface, dst_x, dst_y, src_surface, src_rect_in, trans); -} - -static HRESULT surface_set_mem(struct wined3d_surface *surface, void *mem) -{ - TRACE("surface %p, mem %p.\n", surface, mem); - - if (mem && mem != surface->resource.allocatedMemory) - { - void *release = NULL; - - /* Do I have to copy the old surface content? */ - if (surface->flags & SFLAG_DIBSECTION) - { - SelectObject(surface->hDC, surface->dib.holdbitmap); - DeleteDC(surface->hDC); - /* Release the DIB section. */ - DeleteObject(surface->dib.DIBsection); - surface->dib.bitmap_data = NULL; - surface->resource.allocatedMemory = NULL; - surface->hDC = NULL; - surface->flags &= ~SFLAG_DIBSECTION; - } - else if (!(surface->flags & SFLAG_USERPTR)) - { - release = surface->resource.heapMemory; - surface->resource.heapMemory = NULL; - } - surface->resource.allocatedMemory = mem; - surface->flags |= SFLAG_USERPTR; - - /* Now the surface memory is most up do date. Invalidate drawable and texture. */ - surface_modify_location(surface, SFLAG_INSYSMEM, TRUE); - - /* For client textures OpenGL has to be notified. */ - if (surface->flags & SFLAG_CLIENT) - surface_release_client_storage(surface); - - /* Now free the old memory if any. */ - HeapFree(GetProcessHeap(), 0, release); - } - else if (surface->flags & SFLAG_USERPTR) - { - /* Map and GetDC will re-create the dib section and allocated memory. */ - surface->resource.allocatedMemory = NULL; - /* HeapMemory should be NULL already. */ - if (surface->resource.heapMemory) - ERR("User pointer surface has heap memory allocated.\n"); - surface->flags &= ~(SFLAG_USERPTR | SFLAG_INSYSMEM); - - if (surface->flags & SFLAG_CLIENT) - surface_release_client_storage(surface); - - surface_prepare_system_memory(surface); - surface_modify_location(surface, SFLAG_INSYSMEM, TRUE); - } - - return WINED3D_OK; + return wined3d_surface_blt(surface, NULL, render_target, NULL, 0, NULL, WINED3D_TEXF_POINT); } /* Context activation is done by the caller. */ static void surface_remove_pbo(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info) { - if (!surface->resource.heapMemory) + if (surface->flags & SFLAG_DIBSECTION) { - surface->resource.heapMemory = HeapAlloc(GetProcessHeap(), 0, surface->resource.size + RESOURCE_ALIGNMENT); + surface->resource.allocatedMemory = surface->dib.bitmap_data; + } + else + { + if (!surface->resource.heapMemory) + surface->resource.heapMemory = HeapAlloc(GetProcessHeap(), 0, surface->resource.size + RESOURCE_ALIGNMENT); + else if (!(surface->flags & SFLAG_CLIENT)) + ERR("Surface %p has heapMemory %p and flags %#x.\n", + surface, surface->resource.heapMemory, surface->flags); + surface->resource.allocatedMemory = (BYTE *)(((ULONG_PTR)surface->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1)); } @@ -1537,7 +1803,7 @@ static void surface_unload(struct wined3d_resource *resource) TRACE("surface %p.\n", surface); - if (resource->pool == WINED3DPOOL_DEFAULT) + if (resource->pool == WINED3D_POOL_DEFAULT) { /* Default pool resources are supposed to be destroyed before Reset is called. * Implicit resources stay however. So this means we have an implicit render target @@ -1549,13 +1815,19 @@ static void surface_unload(struct wined3d_resource *resource) * or the depth stencil into an FBO the texture or render buffer will be removed * and all flags get lost */ - surface_init_sysmem(surface); + if (!(surface->flags & SFLAG_PBO)) + surface_init_sysmem(surface); + /* We also get here when the ddraw swapchain is destroyed, for example + * for a mode switch. In this case this surface won't necessarily be + * an implicit surface. We have to mark it lost so that the + * application can restore it after the mode switch. */ + surface->flags |= SFLAG_LOST; } else { /* Load the surface into system memory */ surface_load_location(surface, SFLAG_INSYSMEM, NULL); - surface_modify_location(surface, SFLAG_INDRAWABLE, FALSE); + surface_modify_location(surface, surface->draw_binding, FALSE); } surface_modify_location(surface, SFLAG_INTEXTURE, FALSE); surface_modify_location(surface, SFLAG_INSRGBTEX, FALSE); @@ -1583,17 +1855,29 @@ static void surface_unload(struct wined3d_resource *resource) list_init(&surface->renderbuffers); surface->current_renderbuffer = NULL; + ENTER_GL(); + /* If we're in a texture, the texture name belongs to the texture. * Otherwise, destroy it. */ if (surface->container.type != WINED3D_CONTAINER_TEXTURE) { - ENTER_GL(); glDeleteTextures(1, &surface->texture_name); surface->texture_name = 0; glDeleteTextures(1, &surface->texture_name_srgb); surface->texture_name_srgb = 0; - LEAVE_GL(); } + if (surface->rb_multisample) + { + gl_info->fbo_ops.glDeleteRenderbuffers(1, &surface->rb_multisample); + surface->rb_multisample = 0; + } + if (surface->rb_resolved) + { + gl_info->fbo_ops.glDeleteRenderbuffers(1, &surface->rb_resolved); + surface->rb_resolved = 0; + } + + LEAVE_GL(); context_release(context); @@ -1608,17 +1892,9 @@ static const struct wined3d_resource_ops surface_resource_ops = static const struct wined3d_surface_ops surface_ops = { surface_private_setup, - surface_cleanup, surface_realize_palette, - surface_draw_overlay, - surface_preload, surface_map, surface_unmap, - surface_getdc, - surface_flip, - surface_blt, - surface_bltfast, - surface_set_mem, }; /***************************************************************************** @@ -1665,31 +1941,6 @@ static HRESULT gdi_surface_private_setup(struct wined3d_surface *surface) return WINED3D_OK; } -static void surface_gdi_cleanup(struct wined3d_surface *surface) -{ - TRACE("surface %p.\n", surface); - - if (surface->flags & SFLAG_DIBSECTION) - { - /* Release the DC. */ - SelectObject(surface->hDC, surface->dib.holdbitmap); - DeleteDC(surface->hDC); - /* Release the DIB section. */ - DeleteObject(surface->dib.DIBsection); - surface->dib.bitmap_data = NULL; - surface->resource.allocatedMemory = NULL; - } - - if (surface->flags & SFLAG_USERPTR) - wined3d_surface_set_mem(surface, NULL); - if (surface->overlay_dest) - list_remove(&surface->overlay_entry); - - HeapFree(GetProcessHeap(), 0, surface->palette9); - - resource_cleanup(&surface->resource); -} - static void gdi_surface_realize_palette(struct wined3d_surface *surface) { struct wined3d_palette *palette = surface->palette; @@ -1728,25 +1979,12 @@ static void gdi_surface_realize_palette(struct wined3d_surface *surface) } } -static HRESULT gdi_surface_draw_overlay(struct wined3d_surface *surface) -{ - FIXME("GDI surfaces can't draw overlays yet.\n"); - return E_FAIL; -} - -static void gdi_surface_preload(struct wined3d_surface *surface) -{ - TRACE("surface %p.\n", surface); - - ERR("Preloading GDI surfaces is not supported.\n"); -} - static void gdi_surface_map(struct wined3d_surface *surface, const RECT *rect, DWORD flags) { TRACE("surface %p, rect %s, flags %#x.\n", surface, wine_dbgstr_rect(rect), flags); - if (!surface->resource.allocatedMemory) + if (!(surface->flags & SFLAG_DIBSECTION)) { /* This happens on gdi surfaces if the application set a user pointer * and resets it. Recreate the DIB section. */ @@ -1772,116 +2010,12 @@ static void gdi_surface_unmap(struct wined3d_surface *surface) memset(&surface->lockedRect, 0, sizeof(RECT)); } -static HRESULT gdi_surface_getdc(struct wined3d_surface *surface) -{ - WINED3DLOCKED_RECT lock; - HRESULT hr; - - TRACE("surface %p.\n", surface); - - /* Should have a DIB section already. */ - if (!(surface->flags & SFLAG_DIBSECTION)) - { - WARN("DC not supported on this surface\n"); - return WINED3DERR_INVALIDCALL; - } - - /* Map the surface. */ - hr = wined3d_surface_map(surface, &lock, NULL, 0); - if (FAILED(hr)) - ERR("Map failed, hr %#x.\n", hr); - - return hr; -} - -static HRESULT gdi_surface_flip(struct wined3d_surface *surface, struct wined3d_surface *override) -{ - TRACE("surface %p, override %p.\n", surface, override); - - return WINED3D_OK; -} - -static HRESULT gdi_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst_rect, - struct wined3d_surface *src_surface, const RECT *src_rect, DWORD flags, - const WINEDDBLTFX *fx, WINED3DTEXTUREFILTERTYPE filter) -{ - TRACE("dst_surface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p, filter %s.\n", - dst_surface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect), - flags, fx, debug_d3dtexturefiltertype(filter)); - - return surface_cpu_blt(dst_surface, dst_rect, src_surface, src_rect, flags, fx, filter); -} - -static HRESULT gdi_surface_bltfast(struct wined3d_surface *dst_surface, DWORD dst_x, DWORD dst_y, - struct wined3d_surface *src_surface, const RECT *src_rect, DWORD trans) -{ - TRACE("dst_surface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n", - dst_surface, dst_x, dst_y, src_surface, wine_dbgstr_rect(src_rect), trans); - - return surface_cpu_bltfast(dst_surface, dst_x, dst_y, src_surface, src_rect, trans); -} - -static HRESULT gdi_surface_set_mem(struct wined3d_surface *surface, void *mem) -{ - TRACE("surface %p, mem %p.\n", surface, mem); - - /* Render targets depend on their hdc, and we can't create an hdc on a user pointer. */ - if (surface->resource.usage & WINED3DUSAGE_RENDERTARGET) - { - ERR("Not supported on render targets.\n"); - return WINED3DERR_INVALIDCALL; - } - - if (mem && mem != surface->resource.allocatedMemory) - { - void *release = NULL; - - /* Do I have to copy the old surface content? */ - if (surface->flags & SFLAG_DIBSECTION) - { - SelectObject(surface->hDC, surface->dib.holdbitmap); - DeleteDC(surface->hDC); - /* Release the DIB section. */ - DeleteObject(surface->dib.DIBsection); - surface->dib.bitmap_data = NULL; - surface->resource.allocatedMemory = NULL; - surface->hDC = NULL; - surface->flags &= ~SFLAG_DIBSECTION; - } - else if (!(surface->flags & SFLAG_USERPTR)) - { - release = surface->resource.allocatedMemory; - } - surface->resource.allocatedMemory = mem; - surface->flags |= SFLAG_USERPTR | SFLAG_INSYSMEM; - - /* Now free the old memory, if any. */ - HeapFree(GetProcessHeap(), 0, release); - } - else if (surface->flags & SFLAG_USERPTR) - { - /* Map() and GetDC() will re-create the dib section and allocated memory. */ - surface->resource.allocatedMemory = NULL; - surface->flags &= ~SFLAG_USERPTR; - } - - return WINED3D_OK; -} - static const struct wined3d_surface_ops gdi_surface_ops = { gdi_surface_private_setup, - surface_gdi_cleanup, gdi_surface_realize_palette, - gdi_surface_draw_overlay, - gdi_surface_preload, gdi_surface_map, gdi_surface_unmap, - gdi_surface_getdc, - gdi_surface_flip, - gdi_surface_blt, - gdi_surface_bltfast, - gdi_surface_set_mem, }; void surface_set_texture_name(struct wined3d_surface *surface, GLuint new_name, BOOL srgb) @@ -1907,8 +2041,10 @@ void surface_set_texture_name(struct wined3d_surface *surface, GLuint new_name, /* FIXME: We shouldn't need to remove SFLAG_INTEXTURE if the * surface has no texture name yet. See if we can get rid of this. */ if (surface->flags & flag) + { ERR("Surface has %s set, but no texture name.\n", debug_surflocation(flag)); - surface_modify_location(surface, flag, FALSE); + surface_modify_location(surface, flag, FALSE); + } } *name = new_name; @@ -1935,16 +2071,16 @@ void surface_set_texture_target(struct wined3d_surface *surface, GLenum target) } /* Context activation is done by the caller. */ -void surface_bind(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info, BOOL srgb) +void surface_bind(struct wined3d_surface *surface, struct wined3d_context *context, BOOL srgb) { - TRACE("surface %p, gl_info %p, srgb %#x.\n", surface, gl_info, srgb); + TRACE("surface %p, context %p, srgb %#x.\n", surface, context, srgb); if (surface->container.type == WINED3D_CONTAINER_TEXTURE) { struct wined3d_texture *texture = surface->container.u.texture; TRACE("Passing to container (%p).\n", texture); - texture->texture_ops->texture_bind(texture, gl_info, srgb); + texture->texture_ops->texture_bind(texture, context, srgb); } else { @@ -1966,8 +2102,7 @@ void surface_bind(struct wined3d_surface *surface, const struct wined3d_gl_info TRACE("Surface %p given name %u.\n", surface, surface->texture_name); - glBindTexture(surface->texture_target, surface->texture_name); - checkGLcall("glBindTexture"); + context_bind_texture(context, surface->texture_target, surface->texture_name); glTexParameteri(surface->texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(surface->texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(surface->texture_target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); @@ -1977,27 +2112,13 @@ void surface_bind(struct wined3d_surface *surface, const struct wined3d_gl_info } else { - glBindTexture(surface->texture_target, surface->texture_name); - checkGLcall("glBindTexture"); + context_bind_texture(context, surface->texture_target, surface->texture_name); } LEAVE_GL(); } } -/* This function checks if the primary render target uses the 8bit paletted format. */ -static BOOL primary_render_target_is_p8(struct wined3d_device *device) -{ - if (device->fb.render_targets && device->fb.render_targets[0]) - { - struct wined3d_surface *render_target = device->fb.render_targets[0]; - if ((render_target->resource.usage & WINED3DUSAGE_RENDERTARGET) - && (render_target->resource.format->id == WINED3DFMT_P8_UINT)) - return TRUE; - } - return FALSE; -} - /* This call just downloads data, the caller is responsible for binding the * correct texture. */ /* Context activation is done by the caller. */ @@ -2008,7 +2129,7 @@ static void surface_download_data(struct wined3d_surface *surface, const struct /* Only support read back of converted P8 surfaces. */ if (surface->flags & SFLAG_CONVERTED && format->id != WINED3DFMT_P8_UINT) { - FIXME("Readback conversion not supported for format %s.\n", debug_d3dformat(format->id)); + ERR("Trying to read back converted surface %p with format %s.\n", surface, debug_d3dformat(format->id)); return; } @@ -2164,61 +2285,94 @@ static void surface_download_data(struct wined3d_surface *surface, const struct * correct texture. */ /* Context activation is done by the caller. */ static void surface_upload_data(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info, - const struct wined3d_format *format, BOOL srgb, const GLvoid *data) + const struct wined3d_format *format, const RECT *src_rect, UINT src_pitch, const POINT *dst_point, + BOOL srgb, const struct wined3d_bo_address *data) { - GLsizei width = surface->resource.width; - GLsizei height = surface->resource.height; - GLenum internal; + UINT update_w = src_rect->right - src_rect->left; + UINT update_h = src_rect->bottom - src_rect->top; - if (srgb) + TRACE("surface %p, gl_info %p, format %s, src_rect %s, src_pitch %u, dst_point %s, srgb %#x, data {%#x:%p}.\n", + surface, gl_info, debug_d3dformat(format->id), wine_dbgstr_rect(src_rect), src_pitch, + wine_dbgstr_point(dst_point), srgb, data->buffer_object, data->addr); + + if (surface->flags & SFLAG_LOCKED) { - internal = format->glGammaInternal; - } - else if (surface->resource.usage & WINED3DUSAGE_RENDERTARGET && surface_is_offscreen(surface)) - { - internal = format->rtInternal; - } - else - { - internal = format->glInternal; + WARN("Uploading a surface that is currently mapped, setting SFLAG_PIN_SYSMEM.\n"); + surface->flags |= SFLAG_PIN_SYSMEM; } - TRACE("surface %p, internal %#x, width %d, height %d, format %#x, type %#x, data %p.\n", - surface, internal, width, height, format->glFormat, format->glType, data); - TRACE("target %#x, level %u, resource size %u.\n", - surface->texture_target, surface->texture_level, surface->resource.size); - - if (format->heightscale != 1.0f && format->heightscale != 0.0f) height *= format->heightscale; + if (format->heightscale != 1.0f && format->heightscale != 0.0f) + update_h *= format->heightscale; ENTER_GL(); - if (surface->flags & SFLAG_PBO) + if (data->buffer_object) { - GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, surface->pbo)); + GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, data->buffer_object)); checkGLcall("glBindBufferARB"); - - TRACE("(%p) pbo: %#x, data: %p.\n", surface, surface->pbo, data); - data = NULL; } if (format->flags & WINED3DFMT_FLAG_COMPRESSED) { - TRACE("Calling glCompressedTexSubImage2DARB.\n"); + UINT row_length = wined3d_format_calculate_size(format, 1, update_w, 1); + UINT row_count = (update_h + format->block_height - 1) / format->block_height; + const BYTE *addr = data->addr; + GLenum internal; - GL_EXTCALL(glCompressedTexSubImage2DARB(surface->texture_target, surface->texture_level, - 0, 0, width, height, internal, surface->resource.size, data)); + addr += (src_rect->top / format->block_height) * src_pitch; + addr += (src_rect->left / format->block_width) * format->block_byte_count; + + if (srgb) + internal = format->glGammaInternal; + else if (surface->resource.usage & WINED3DUSAGE_RENDERTARGET && surface_is_offscreen(surface)) + internal = format->rtInternal; + else + internal = format->glInternal; + + TRACE("glCompressedTexSubImage2DARB, target %#x, level %d, x %d, y %d, w %d, h %d, " + "format %#x, image_size %#x, addr %p.\n", surface->texture_target, surface->texture_level, + dst_point->x, dst_point->y, update_w, update_h, internal, row_count * row_length, addr); + + if (row_length == src_pitch) + { + GL_EXTCALL(glCompressedTexSubImage2DARB(surface->texture_target, surface->texture_level, + dst_point->x, dst_point->y, update_w, update_h, internal, row_count * row_length, addr)); + } + else + { + UINT row, y; + + /* glCompressedTexSubImage2DARB() ignores pixel store state, so we + * can't use the unpack row length like below. */ + for (row = 0, y = dst_point->y; row < row_count; ++row) + { + GL_EXTCALL(glCompressedTexSubImage2DARB(surface->texture_target, surface->texture_level, + dst_point->x, y, update_w, format->block_height, internal, row_length, addr)); + y += format->block_height; + addr += src_pitch; + } + } checkGLcall("glCompressedTexSubImage2DARB"); } else { - TRACE("Calling glTexSubImage2D.\n"); + const BYTE *addr = data->addr; - glTexSubImage2D(surface->texture_target, surface->texture_level, - 0, 0, width, height, format->glFormat, format->glType, data); + addr += src_rect->top * src_pitch; + addr += src_rect->left * format->byte_count; + + TRACE("glTexSubImage2D, target %#x, level %d, x %d, y %d, w %d, h %d, format %#x, type %#x, addr %p.\n", + surface->texture_target, surface->texture_level, dst_point->x, dst_point->y, + update_w, update_h, format->glFormat, format->glType, addr); + + glPixelStorei(GL_UNPACK_ROW_LENGTH, src_pitch / format->byte_count); + glTexSubImage2D(surface->texture_target, surface->texture_level, dst_point->x, dst_point->y, + update_w, update_h, format->glFormat, format->glType, addr); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); checkGLcall("glTexSubImage2D"); } - if (surface->flags & SFLAG_PBO) + if (data->buffer_object) { GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0)); checkGLcall("glBindBufferARB"); @@ -2226,6 +2380,9 @@ static void surface_upload_data(struct wined3d_surface *surface, const struct wi LEAVE_GL(); + if (wined3d_settings.strict_draw_ordering) + wglFlush(); + if (gl_info->quirks & WINED3D_QUIRK_FBO_TEX_UPDATE) { struct wined3d_device *device = surface->resource.device; @@ -2238,6 +2395,122 @@ static void surface_upload_data(struct wined3d_surface *surface, const struct wi } } +HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const POINT *dst_point, + struct wined3d_surface *src_surface, const RECT *src_rect) +{ + const struct wined3d_format *src_format; + const struct wined3d_format *dst_format; + const struct wined3d_gl_info *gl_info; + struct wined3d_context *context; + struct wined3d_bo_address data; + struct wined3d_format format; + UINT update_w, update_h; + CONVERT_TYPES convert; + UINT dst_w, dst_h; + UINT src_w, src_h; + UINT src_pitch; + POINT p; + RECT r; + + TRACE("dst_surface %p, dst_point %s, src_surface %p, src_rect %s.\n", + dst_surface, wine_dbgstr_point(dst_point), + src_surface, wine_dbgstr_rect(src_rect)); + + src_format = src_surface->resource.format; + dst_format = dst_surface->resource.format; + + if (src_format->id != dst_format->id) + { + WARN("Source and destination surfaces should have the same format.\n"); + return WINED3DERR_INVALIDCALL; + } + + if (!dst_point) + { + p.x = 0; + p.y = 0; + dst_point = &p; + } + else if (dst_point->x < 0 || dst_point->y < 0) + { + WARN("Invalid destination point.\n"); + return WINED3DERR_INVALIDCALL; + } + + if (!src_rect) + { + r.left = 0; + r.top = 0; + r.right = src_surface->resource.width; + r.bottom = src_surface->resource.height; + src_rect = &r; + } + else if (src_rect->left < 0 || src_rect->left >= src_rect->right + || src_rect->top < 0 || src_rect->top >= src_rect->bottom) + { + WARN("Invalid source rectangle.\n"); + return WINED3DERR_INVALIDCALL; + } + + src_w = src_surface->resource.width; + src_h = src_surface->resource.height; + + dst_w = dst_surface->resource.width; + dst_h = dst_surface->resource.height; + + update_w = src_rect->right - src_rect->left; + update_h = src_rect->bottom - src_rect->top; + + if (update_w > dst_w || dst_point->x > dst_w - update_w + || update_h > dst_h || dst_point->y > dst_h - update_h) + { + WARN("Destination out of bounds.\n"); + return WINED3DERR_INVALIDCALL; + } + + /* NPOT block sizes would be silly. */ + if ((src_format->flags & WINED3DFMT_FLAG_BLOCKS) + && ((update_w & (src_format->block_width - 1) || update_h & (src_format->block_height - 1)) + && (src_w != update_w || dst_w != update_w || src_h != update_h || dst_h != update_h))) + { + WARN("Update rect not block-aligned.\n"); + return WINED3DERR_INVALIDCALL; + } + + /* Use wined3d_surface_blt() instead of uploading directly if we need conversion. */ + d3dfmt_get_conv(dst_surface, FALSE, TRUE, &format, &convert); + if (convert != NO_CONVERSION || format.convert) + { + RECT dst_rect = {dst_point->x, dst_point->y, dst_point->x + update_w, dst_point->y + update_h}; + return wined3d_surface_blt(dst_surface, &dst_rect, src_surface, src_rect, 0, NULL, WINED3D_TEXF_POINT); + } + + context = context_acquire(dst_surface->resource.device, NULL); + gl_info = context->gl_info; + + /* Only load the surface for partial updates. For newly allocated texture + * the texture wouldn't be the current location, and we'd upload zeroes + * just to overwrite them again. */ + if (update_w == dst_w && update_h == dst_h) + surface_prepare_texture(dst_surface, context, FALSE); + else + surface_load_location(dst_surface, SFLAG_INTEXTURE, NULL); + surface_bind(dst_surface, context, FALSE); + + data.buffer_object = src_surface->pbo; + data.addr = src_surface->resource.allocatedMemory; + src_pitch = wined3d_surface_get_pitch(src_surface); + + surface_upload_data(dst_surface, gl_info, src_format, src_rect, src_pitch, dst_point, FALSE, &data); + + invalidate_active_texture(dst_surface->resource.device, context); + + context_release(context); + + surface_modify_location(dst_surface, SFLAG_INTEXTURE, TRUE); + return WINED3D_OK; +} + /* This call just allocates the texture, the caller is responsible for binding * the correct texture. */ /* Context activation is done by the caller. */ @@ -2323,7 +2596,7 @@ static void surface_allocate_surface(struct wined3d_surface *surface, const stru * render target dimensions. With FBOs, the dimensions have to be an exact match. */ /* TODO: We should synchronize the renderbuffer's content with the texture's content. */ /* GL locking is done by the caller */ -void surface_set_compatible_renderbuffer(struct wined3d_surface *surface, struct wined3d_surface *rt) +void surface_set_compatible_renderbuffer(struct wined3d_surface *surface, const struct wined3d_surface *rt) { const struct wined3d_gl_info *gl_info = &surface->resource.device->adapter->gl_info; struct wined3d_renderbuffer_entry *entry; @@ -2386,9 +2659,9 @@ void surface_set_compatible_renderbuffer(struct wined3d_surface *surface, struct checkGLcall("set_compatible_renderbuffer"); } -GLenum surface_get_gl_buffer(struct wined3d_surface *surface) +GLenum surface_get_gl_buffer(const struct wined3d_surface *surface) { - struct wined3d_swapchain *swapchain = surface->container.u.swapchain; + const struct wined3d_swapchain *swapchain = surface->container.u.swapchain; TRACE("surface %p.\n", surface); @@ -2419,7 +2692,7 @@ GLenum surface_get_gl_buffer(struct wined3d_surface *surface) } /* Slightly inefficient way to handle multiple dirty rects but it works :) */ -void surface_add_dirty_rect(struct wined3d_surface *surface, const WINED3DBOX *dirty_rect) +void surface_add_dirty_rect(struct wined3d_surface *surface, const struct wined3d_box *dirty_rect) { TRACE("surface %p, dirty_rect %p.\n", surface, dirty_rect); @@ -2430,10 +2703,10 @@ void surface_add_dirty_rect(struct wined3d_surface *surface, const WINED3DBOX *d surface_modify_location(surface, SFLAG_INSYSMEM, TRUE); if (dirty_rect) { - surface->dirtyRect.left = min(surface->dirtyRect.left, dirty_rect->Left); - surface->dirtyRect.top = min(surface->dirtyRect.top, dirty_rect->Top); - surface->dirtyRect.right = max(surface->dirtyRect.right, dirty_rect->Right); - surface->dirtyRect.bottom = max(surface->dirtyRect.bottom, dirty_rect->Bottom); + surface->dirtyRect.left = min(surface->dirtyRect.left, dirty_rect->left); + surface->dirtyRect.top = min(surface->dirtyRect.top, dirty_rect->top); + surface->dirtyRect.right = max(surface->dirtyRect.right, dirty_rect->right); + surface->dirtyRect.bottom = max(surface->dirtyRect.bottom, dirty_rect->bottom); } else { @@ -2451,82 +2724,26 @@ void surface_add_dirty_rect(struct wined3d_surface *surface, const WINED3DBOX *d } } -static BOOL surface_convert_color_to_float(struct wined3d_surface *surface, - DWORD color, WINED3DCOLORVALUE *float_color) -{ - const struct wined3d_format *format = surface->resource.format; - struct wined3d_device *device = surface->resource.device; - - switch (format->id) - { - case WINED3DFMT_P8_UINT: - if (surface->palette) - { - float_color->r = surface->palette->palents[color].peRed / 255.0f; - float_color->g = surface->palette->palents[color].peGreen / 255.0f; - float_color->b = surface->palette->palents[color].peBlue / 255.0f; - } - else - { - float_color->r = 0.0f; - float_color->g = 0.0f; - float_color->b = 0.0f; - } - float_color->a = primary_render_target_is_p8(device) ? color / 255.0f : 1.0f; - break; - - case WINED3DFMT_B5G6R5_UNORM: - float_color->r = ((color >> 11) & 0x1f) / 31.0f; - float_color->g = ((color >> 5) & 0x3f) / 63.0f; - float_color->b = (color & 0x1f) / 31.0f; - float_color->a = 1.0f; - break; - - case WINED3DFMT_B8G8R8_UNORM: - case WINED3DFMT_B8G8R8X8_UNORM: - float_color->r = D3DCOLOR_R(color); - float_color->g = D3DCOLOR_G(color); - float_color->b = D3DCOLOR_B(color); - float_color->a = 1.0f; - break; - - case WINED3DFMT_B8G8R8A8_UNORM: - float_color->r = D3DCOLOR_R(color); - float_color->g = D3DCOLOR_G(color); - float_color->b = D3DCOLOR_B(color); - float_color->a = D3DCOLOR_A(color); - break; - - default: - ERR("Unhandled conversion from %s to floating point.\n", debug_d3dformat(format->id)); - return FALSE; - } - - return TRUE; -} - HRESULT surface_load(struct wined3d_surface *surface, BOOL srgb) { DWORD flag = srgb ? SFLAG_INSRGBTEX : SFLAG_INTEXTURE; + BOOL ck_changed; TRACE("surface %p, srgb %#x.\n", surface, srgb); - if (surface->resource.pool == WINED3DPOOL_SCRATCH) + if (surface->resource.pool == WINED3D_POOL_SCRATCH) { ERR("Not supported on scratch surfaces.\n"); return WINED3DERR_INVALIDCALL; } - if (!(surface->flags & flag)) - { - TRACE("Reloading because surface is dirty\n"); - } + ck_changed = !(surface->flags & SFLAG_GLCKEY) != !(surface->CKeyFlags & WINEDDSD_CKSRCBLT); + /* Reload if either the texture and sysmem have different ideas about the * color key, or the actual key values changed. */ - else if (!(surface->flags & SFLAG_GLCKEY) != !(surface->CKeyFlags & WINEDDSD_CKSRCBLT) - || ((surface->CKeyFlags & WINEDDSD_CKSRCBLT) - && (surface->glCKey.dwColorSpaceLowValue != surface->SrcBltCKey.dwColorSpaceLowValue - || surface->glCKey.dwColorSpaceHighValue != surface->SrcBltCKey.dwColorSpaceHighValue))) + if (ck_changed || ((surface->CKeyFlags & WINEDDSD_CKSRCBLT) + && (surface->gl_color_key.color_space_low_value != surface->src_blt_color_key.color_space_low_value + || surface->gl_color_key.color_space_high_value != surface->src_blt_color_key.color_space_high_value))) { TRACE("Reloading because of color keying\n"); /* To perform the color key conversion we need a sysmem copy of @@ -2537,6 +2754,13 @@ HRESULT surface_load(struct wined3d_surface *surface, BOOL srgb) * this kills performance though :( */ /* TODO: This is not necessarily needed with hw palettized texture support. */ surface_modify_location(surface, SFLAG_INSYSMEM, TRUE); + /* Switching color keying on / off may change the internal format. */ + if (ck_changed) + surface_force_reload(surface); + } + else if (!(surface->flags & flag)) + { + TRACE("Reloading because surface is dirty.\n"); } else { @@ -2668,7 +2892,7 @@ ULONG CDECL wined3d_surface_decref(struct wined3d_surface *surface) if (!refcount) { - surface->surface_ops->surface_cleanup(surface); + surface_cleanup(surface); surface->resource.parent_ops->wined3d_object_destroyed(surface->resource.parent); TRACE("Destroyed surface %p.\n", surface); @@ -2678,23 +2902,6 @@ ULONG CDECL wined3d_surface_decref(struct wined3d_surface *surface) return refcount; } -HRESULT CDECL wined3d_surface_set_private_data(struct wined3d_surface *surface, - REFGUID riid, const void *data, DWORD data_size, DWORD flags) -{ - return resource_set_private_data(&surface->resource, riid, data, data_size, flags); -} - -HRESULT CDECL wined3d_surface_get_private_data(const struct wined3d_surface *surface, - REFGUID guid, void *data, DWORD *data_size) -{ - return resource_get_private_data(&surface->resource, guid, data, data_size); -} - -HRESULT CDECL wined3d_surface_free_private_data(struct wined3d_surface *surface, REFGUID refguid) -{ - return resource_free_private_data(&surface->resource, refguid); -} - DWORD CDECL wined3d_surface_set_priority(struct wined3d_surface *surface, DWORD priority) { return resource_set_priority(&surface->resource, priority); @@ -2709,7 +2916,13 @@ void CDECL wined3d_surface_preload(struct wined3d_surface *surface) { TRACE("surface %p.\n", surface); - surface->surface_ops->surface_preload(surface); + if (!surface->resource.device->d3d_initialized) + { + ERR("D3D not initialized.\n"); + return; + } + + surface_internal_preload(surface, SRGB_ANY); } void * CDECL wined3d_surface_get_parent(const struct wined3d_surface *surface) @@ -2770,7 +2983,6 @@ HRESULT CDECL wined3d_surface_restore(struct wined3d_surface *surface) { TRACE("surface %p.\n", surface); - /* So far we don't lose anything :) */ surface->flags &= ~SFLAG_LOST; return WINED3D_OK; } @@ -2802,7 +3014,7 @@ HRESULT CDECL wined3d_surface_set_palette(struct wined3d_surface *surface, struc } HRESULT CDECL wined3d_surface_set_color_key(struct wined3d_surface *surface, - DWORD flags, const WINEDDCOLORKEY *color_key) + DWORD flags, const struct wined3d_color_key *color_key) { TRACE("surface %p, flags %#x, color_key %p.\n", surface, flags, color_key); @@ -2818,22 +3030,22 @@ HRESULT CDECL wined3d_surface_set_color_key(struct wined3d_surface *surface, switch (flags & ~WINEDDCKEY_COLORSPACE) { case WINEDDCKEY_DESTBLT: - surface->DestBltCKey = *color_key; + surface->dst_blt_color_key = *color_key; surface->CKeyFlags |= WINEDDSD_CKDESTBLT; break; case WINEDDCKEY_DESTOVERLAY: - surface->DestOverlayCKey = *color_key; + surface->dst_overlay_color_key = *color_key; surface->CKeyFlags |= WINEDDSD_CKDESTOVERLAY; break; case WINEDDCKEY_SRCOVERLAY: - surface->SrcOverlayCKey = *color_key; + surface->src_overlay_color_key = *color_key; surface->CKeyFlags |= WINEDDSD_CKSRCOVERLAY; break; case WINEDDCKEY_SRCBLT: - surface->SrcBltCKey = *color_key; + surface->src_blt_color_key = *color_key; surface->CKeyFlags |= WINEDDSD_CKSRCBLT; break; } @@ -2877,7 +3089,7 @@ DWORD CDECL wined3d_surface_get_pitch(const struct wined3d_surface *surface) TRACE("surface %p.\n", surface); - if ((format->flags & (WINED3DFMT_FLAG_COMPRESSED | WINED3DFMT_FLAG_BROKEN_PITCH)) == WINED3DFMT_FLAG_COMPRESSED) + if (format->flags & WINED3DFMT_FLAG_BLOCKS) { /* Since compressed formats are block based, pitch means the amount of * bytes to the next row of block rather than the next row of pixels. */ @@ -2906,7 +3118,66 @@ HRESULT CDECL wined3d_surface_set_mem(struct wined3d_surface *surface, void *mem return WINED3DERR_INVALIDCALL; } - return surface->surface_ops->surface_set_mem(surface, mem); + /* Render targets depend on their hdc, and we can't create an hdc on a user pointer. */ + if (surface->resource.usage & WINED3DUSAGE_RENDERTARGET) + { + ERR("Not supported on render targets.\n"); + return WINED3DERR_INVALIDCALL; + } + + if (mem && mem != surface->resource.allocatedMemory) + { + void *release = NULL; + + /* Do I have to copy the old surface content? */ + if (surface->flags & SFLAG_DIBSECTION) + { + DeleteDC(surface->hDC); + DeleteObject(surface->dib.DIBsection); + surface->dib.bitmap_data = NULL; + surface->resource.allocatedMemory = NULL; + surface->hDC = NULL; + surface->flags &= ~SFLAG_DIBSECTION; + } + else if (!(surface->flags & SFLAG_USERPTR)) + { + release = surface->resource.heapMemory; + surface->resource.heapMemory = NULL; + } + surface->resource.allocatedMemory = mem; + surface->flags |= SFLAG_USERPTR; + + /* Now the surface memory is most up do date. Invalidate drawable and texture. */ + surface_modify_location(surface, SFLAG_INSYSMEM, TRUE); + + /* For client textures OpenGL has to be notified. */ + if (surface->flags & SFLAG_CLIENT) + surface_release_client_storage(surface); + + /* Now free the old memory if any. */ + HeapFree(GetProcessHeap(), 0, release); + } + else if (surface->flags & SFLAG_USERPTR) + { + /* HeapMemory should be NULL already. */ + if (surface->resource.heapMemory) + ERR("User pointer surface has heap memory allocated.\n"); + + if (!mem) + { + surface->resource.allocatedMemory = NULL; + surface->flags &= ~(SFLAG_USERPTR | SFLAG_INSYSMEM); + + if (surface->flags & SFLAG_CLIENT) + surface_release_client_storage(surface); + + surface_prepare_system_memory(surface); + } + + surface_modify_location(surface, SFLAG_INSYSMEM, TRUE); + } + + return WINED3D_OK; } HRESULT CDECL wined3d_surface_set_overlay_position(struct wined3d_surface *surface, LONG x, LONG y) @@ -2928,7 +3199,7 @@ HRESULT CDECL wined3d_surface_set_overlay_position(struct wined3d_surface *surfa surface->overlay_destrect.right = x + w; surface->overlay_destrect.bottom = y + h; - surface->surface_ops->surface_draw_overlay(surface); + surface_draw_overlay(surface); return WINED3D_OK; } @@ -3016,6 +3287,7 @@ HRESULT CDECL wined3d_surface_update_overlay(struct wined3d_surface *surface, co if (surface->overlay_dest && (surface->overlay_dest != dst_surface || flags & WINEDDOVER_HIDE)) { + surface->overlay_dest = NULL; list_remove(&surface->overlay_entry); } @@ -3037,48 +3309,71 @@ HRESULT CDECL wined3d_surface_update_overlay(struct wined3d_surface *surface, co surface->overlay_dest = NULL; } - surface->surface_ops->surface_draw_overlay(surface); + surface_draw_overlay(surface); return WINED3D_OK; } -HRESULT CDECL wined3d_surface_set_clipper(struct wined3d_surface *surface, struct wined3d_clipper *clipper) +HRESULT CDECL wined3d_surface_update_desc(struct wined3d_surface *surface, + UINT width, UINT height, enum wined3d_format_id format_id, + enum wined3d_multisample_type multisample_type, UINT multisample_quality) { - TRACE("surface %p, clipper %p.\n", surface, clipper); + struct wined3d_device *device = surface->resource.device; + const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; + const struct wined3d_format *format = wined3d_get_format(gl_info, format_id); + UINT resource_size = wined3d_format_calculate_size(format, device->surface_alignment, width, height); - surface->clipper = clipper; + TRACE("surface %p, width %u, height %u, format %s, multisample_type %#x, multisample_quality %u.\n", + surface, width, height, debug_d3dformat(format_id), multisample_type, multisample_type); - return WINED3D_OK; -} - -struct wined3d_clipper * CDECL wined3d_surface_get_clipper(const struct wined3d_surface *surface) -{ - TRACE("surface %p.\n", surface); - - return surface->clipper; -} - -HRESULT CDECL wined3d_surface_set_format(struct wined3d_surface *surface, enum wined3d_format_id format_id) -{ - const struct wined3d_format *format = wined3d_get_format(&surface->resource.device->adapter->gl_info, format_id); - - TRACE("surface %p, format %s.\n", surface, debug_d3dformat(format_id)); - - if (surface->resource.format->id != WINED3DFMT_UNKNOWN) - { - FIXME("The format of the surface must be WINED3DFORMAT_UNKNOWN.\n"); + if (!resource_size) return WINED3DERR_INVALIDCALL; + + if (device->d3d_initialized) + surface->resource.resource_ops->resource_unload(&surface->resource); + + if (surface->flags & SFLAG_DIBSECTION) + { + DeleteDC(surface->hDC); + DeleteObject(surface->dib.DIBsection); + surface->dib.bitmap_data = NULL; + surface->flags &= ~SFLAG_DIBSECTION; } - surface->resource.size = wined3d_format_calculate_size(format, surface->resource.device->surface_alignment, - surface->pow2Width, surface->pow2Height); - surface->flags |= (WINED3DFMT_D16_LOCKABLE == format_id) ? SFLAG_LOCKABLE : 0; - surface->flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED); - surface->resource.format = format; + surface->flags &= ~(SFLAG_LOCATIONS | SFLAG_USERPTR); + surface->resource.allocatedMemory = NULL; + HeapFree(GetProcessHeap(), 0, surface->resource.heapMemory); + surface->resource.heapMemory = NULL; - TRACE("size %u, byte_count %u\n", surface->resource.size, format->byte_count); - TRACE("glFormat %#x, glInternal %#x, glType %#x.\n", - format->glFormat, format->glInternal, format->glType); + surface->resource.width = width; + surface->resource.height = height; + if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] || gl_info->supported[ARB_TEXTURE_RECTANGLE] + || gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT]) + { + surface->pow2Width = width; + surface->pow2Height = height; + } + else + { + surface->pow2Width = surface->pow2Height = 1; + while (surface->pow2Width < width) + surface->pow2Width <<= 1; + while (surface->pow2Height < height) + surface->pow2Height <<= 1; + } + + if (surface->pow2Width != width || surface->pow2Height != height) + surface->flags |= SFLAG_NONPOW2; + else + surface->flags &= ~SFLAG_NONPOW2; + + surface->resource.format = format; + surface->resource.multisample_type = multisample_type; + surface->resource.multisample_quality = multisample_quality; + surface->resource.size = resource_size; + + if (!surface_init_sysmem(surface)) + return E_OUTOFMEMORY; return WINED3D_OK; } @@ -3143,6 +3438,8 @@ static void convert_r5g6b5_x8r8g8b8(const BYTE *src, BYTE *dst, } } +/* We use this for both B8G8R8A8 -> B8G8R8X8 and B8G8R8X8 -> B8G8R8A8, since + * in both cases we're just setting the X / Alpha channel to 0xff. */ static void convert_a8r8g8b8_x8r8g8b8(const BYTE *src, BYTE *dst, DWORD pitch_in, DWORD pitch_out, unsigned int w, unsigned int h) { @@ -3261,6 +3558,7 @@ static const struct d3dfmt_convertor_desc convertors[] = {WINED3DFMT_R32_FLOAT, WINED3DFMT_R16_FLOAT, convert_r32_float_r16_float}, {WINED3DFMT_B5G6R5_UNORM, WINED3DFMT_B8G8R8X8_UNORM, convert_r5g6b5_x8r8g8b8}, {WINED3DFMT_B8G8R8A8_UNORM, WINED3DFMT_B8G8R8X8_UNORM, convert_a8r8g8b8_x8r8g8b8}, + {WINED3DFMT_B8G8R8X8_UNORM, WINED3DFMT_B8G8R8A8_UNORM, convert_a8r8g8b8_x8r8g8b8}, {WINED3DFMT_YUY2, WINED3DFMT_B8G8R8X8_UNORM, convert_yuy2_x8r8g8b8}, {WINED3DFMT_YUY2, WINED3DFMT_B5G6R5_UNORM, convert_yuy2_r5g6b5}, }; @@ -3292,8 +3590,8 @@ static inline const struct d3dfmt_convertor_desc *find_convertor(enum wined3d_fo *****************************************************************************/ static struct wined3d_surface *surface_convert_format(struct wined3d_surface *source, enum wined3d_format_id to_fmt) { + struct wined3d_mapped_rect src_map, dst_map; const struct d3dfmt_convertor_desc *conv; - WINED3DLOCKED_RECT lock_src, lock_dst; struct wined3d_surface *ret = NULL; HRESULT hr; @@ -3306,26 +3604,27 @@ static struct wined3d_surface *surface_convert_format(struct wined3d_surface *so } wined3d_surface_create(source->resource.device, source->resource.width, - source->resource.height, to_fmt, TRUE /* lockable */, TRUE /* discard */, 0 /* level */, - 0 /* usage */, WINED3DPOOL_SCRATCH, WINED3DMULTISAMPLE_NONE /* TODO: Multisampled conversion */, - 0 /* MultiSampleQuality */, source->surface_type, NULL /* parent */, &wined3d_null_parent_ops, &ret); + source->resource.height, to_fmt, 0 /* level */, 0 /* usage */, WINED3D_POOL_SCRATCH, + WINED3D_MULTISAMPLE_NONE /* TODO: Multisampled conversion */, 0 /* MultiSampleQuality */, + source->surface_type, WINED3D_SURFACE_MAPPABLE | WINED3D_SURFACE_DISCARD, + NULL /* parent */, &wined3d_null_parent_ops, &ret); if (!ret) { ERR("Failed to create a destination surface for conversion.\n"); return NULL; } - memset(&lock_src, 0, sizeof(lock_src)); - memset(&lock_dst, 0, sizeof(lock_dst)); + memset(&src_map, 0, sizeof(src_map)); + memset(&dst_map, 0, sizeof(dst_map)); - hr = wined3d_surface_map(source, &lock_src, NULL, WINED3DLOCK_READONLY); + hr = wined3d_surface_map(source, &src_map, NULL, WINED3DLOCK_READONLY); if (FAILED(hr)) { ERR("Failed to lock the source surface.\n"); wined3d_surface_decref(ret); return NULL; } - hr = wined3d_surface_map(ret, &lock_dst, NULL, WINED3DLOCK_READONLY); + hr = wined3d_surface_map(ret, &dst_map, NULL, WINED3DLOCK_READONLY); if (FAILED(hr)) { ERR("Failed to lock the destination surface.\n"); @@ -3334,7 +3633,7 @@ static struct wined3d_surface *surface_convert_format(struct wined3d_surface *so return NULL; } - conv->convert(lock_src.pBits, lock_dst.pBits, lock_src.Pitch, lock_dst.Pitch, + conv->convert(src_map.data, dst_map.data, src_map.row_pitch, dst_map.row_pitch, source->resource.width, source->resource.height); wined3d_surface_unmap(ret); @@ -3401,30 +3700,6 @@ do { \ return WINED3D_OK; } -/* Do not call while under the GL lock. */ -HRESULT CDECL wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst_rect, - struct wined3d_surface *src_surface, const RECT *src_rect, DWORD flags, - const WINEDDBLTFX *fx, WINED3DTEXTUREFILTERTYPE filter) -{ - TRACE("dst_surface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p, filter %s.\n", - dst_surface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect), - flags, fx, debug_d3dtexturefiltertype(filter)); - - return dst_surface->surface_ops->surface_blt(dst_surface, - dst_rect, src_surface, src_rect, flags, fx, filter); -} - -/* Do not call while under the GL lock. */ -HRESULT CDECL wined3d_surface_bltfast(struct wined3d_surface *dst_surface, DWORD dst_x, DWORD dst_y, - struct wined3d_surface *src_surface, const RECT *src_rect, DWORD trans) -{ - TRACE("dst_surface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, trans %#x.\n", - dst_surface, dst_x, dst_y, src_surface, wine_dbgstr_rect(src_rect), trans); - - return dst_surface->surface_ops->surface_bltfast(dst_surface, - dst_x, dst_y, src_surface, src_rect, trans); -} - HRESULT CDECL wined3d_surface_unmap(struct wined3d_surface *surface) { TRACE("surface %p.\n", surface); @@ -3442,28 +3717,65 @@ HRESULT CDECL wined3d_surface_unmap(struct wined3d_surface *surface) } HRESULT CDECL wined3d_surface_map(struct wined3d_surface *surface, - WINED3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags) + struct wined3d_mapped_rect *mapped_rect, const RECT *rect, DWORD flags) { - TRACE("surface %p, locked_rect %p, rect %s, flags %#x.\n", - surface, locked_rect, wine_dbgstr_rect(rect), flags); + const struct wined3d_format *format = surface->resource.format; + + TRACE("surface %p, mapped_rect %p, rect %s, flags %#x.\n", + surface, mapped_rect, wine_dbgstr_rect(rect), flags); if (surface->flags & SFLAG_LOCKED) { WARN("Surface is already mapped.\n"); return WINED3DERR_INVALIDCALL; } + if ((format->flags & WINED3DFMT_FLAG_BLOCKS) + && rect && (rect->left || rect->top + || rect->right != surface->resource.width + || rect->bottom != surface->resource.height)) + { + UINT width_mask = format->block_width - 1; + UINT height_mask = format->block_height - 1; + + if ((rect->left & width_mask) || (rect->right & width_mask) + || (rect->top & height_mask) || (rect->bottom & height_mask)) + { + WARN("Map rect %s is misaligned for %ux%u blocks.\n", + wine_dbgstr_rect(rect), format->block_width, format->block_height); + + if (surface->resource.pool == WINED3D_POOL_DEFAULT) + return WINED3DERR_INVALIDCALL; + } + } + surface->flags |= SFLAG_LOCKED; if (!(surface->flags & SFLAG_LOCKABLE)) WARN("Trying to lock unlockable surface.\n"); + /* Performance optimization: Count how often a surface is mapped, if it is + * mapped regularly do not throw away the system memory copy. This avoids + * the need to download the surface from OpenGL all the time. The surface + * is still downloaded if the OpenGL texture is changed. */ + if (!(surface->flags & SFLAG_DYNLOCK)) + { + if (++surface->lockCount > MAXLOCKCOUNT) + { + TRACE("Surface is mapped regularly, not freeing the system memory copy any more.\n"); + surface->flags |= SFLAG_DYNLOCK; + } + } + surface->surface_ops->surface_map(surface, rect, flags); - locked_rect->Pitch = wined3d_surface_get_pitch(surface); + if (format->flags & WINED3DFMT_FLAG_BROKEN_PITCH) + mapped_rect->row_pitch = surface->resource.width * format->byte_count; + else + mapped_rect->row_pitch = wined3d_surface_get_pitch(surface); if (!rect) { - locked_rect->pBits = surface->resource.allocatedMemory; + mapped_rect->data = surface->resource.allocatedMemory; surface->lockedRect.left = 0; surface->lockedRect.top = 0; surface->lockedRect.right = surface->resource.width; @@ -3471,20 +3783,18 @@ HRESULT CDECL wined3d_surface_map(struct wined3d_surface *surface, } else { - const struct wined3d_format *format = surface->resource.format; - - if ((format->flags & (WINED3DFMT_FLAG_COMPRESSED | WINED3DFMT_FLAG_BROKEN_PITCH)) == WINED3DFMT_FLAG_COMPRESSED) + if ((format->flags & (WINED3DFMT_FLAG_BLOCKS | WINED3DFMT_FLAG_BROKEN_PITCH)) == WINED3DFMT_FLAG_BLOCKS) { /* Compressed textures are block based, so calculate the offset of * the block that contains the top-left pixel of the locked rectangle. */ - locked_rect->pBits = surface->resource.allocatedMemory - + ((rect->top / format->block_height) * locked_rect->Pitch) + mapped_rect->data = surface->resource.allocatedMemory + + ((rect->top / format->block_height) * mapped_rect->row_pitch) + ((rect->left / format->block_width) * format->block_byte_count); } else { - locked_rect->pBits = surface->resource.allocatedMemory - + (locked_rect->Pitch * rect->top) + mapped_rect->data = surface->resource.allocatedMemory + + (mapped_rect->row_pitch * rect->top) + (rect->left * format->byte_count); } surface->lockedRect.left = rect->left; @@ -3494,13 +3804,14 @@ HRESULT CDECL wined3d_surface_map(struct wined3d_surface *surface, } TRACE("Locked rect %s.\n", wine_dbgstr_rect(&surface->lockedRect)); - TRACE("Returning memory %p, pitch %u.\n", locked_rect->pBits, locked_rect->Pitch); + TRACE("Returning memory %p, pitch %u.\n", mapped_rect->data, mapped_rect->row_pitch); return WINED3D_OK; } HRESULT CDECL wined3d_surface_getdc(struct wined3d_surface *surface, HDC *dc) { + struct wined3d_mapped_rect map; HRESULT hr; TRACE("surface %p, dc %p.\n", surface, dc); @@ -3519,9 +3830,35 @@ HRESULT CDECL wined3d_surface_getdc(struct wined3d_surface *surface, HDC *dc) if (surface->flags & SFLAG_LOCKED) return WINED3DERR_INVALIDCALL; - hr = surface->surface_ops->surface_getdc(surface); + /* Create a DIB section if there isn't a dc yet. */ + if (!surface->hDC) + { + if (surface->flags & SFLAG_CLIENT) + { + surface_load_location(surface, SFLAG_INSYSMEM, NULL); + surface_release_client_storage(surface); + } + hr = surface_create_dib_section(surface); + if (FAILED(hr)) + return WINED3DERR_INVALIDCALL; + + /* Use the DIB section from now on if we are not using a PBO. */ + if (!(surface->flags & SFLAG_PBO)) + surface->resource.allocatedMemory = surface->dib.bitmap_data; + } + + /* Map the surface. */ + hr = wined3d_surface_map(surface, &map, NULL, 0); if (FAILED(hr)) + { + ERR("Map failed, hr %#x.\n", hr); return hr; + } + + /* Sync the DIB with the PBO. This can't be done earlier because Map() + * activates the allocatedMemory. */ + if (surface->flags & SFLAG_PBO) + memcpy(surface->dib.bitmap_data, surface->resource.allocatedMemory, surface->resource.size); if (surface->resource.format->id == WINED3DFMT_P8_UINT || surface->resource.format->id == WINED3DFMT_P8_UINT_A8_UNORM) @@ -3582,11 +3919,9 @@ HRESULT CDECL wined3d_surface_releasedc(struct wined3d_surface *surface, HDC dc) return WINEDDERR_NODC; } + /* Copy the contents of the DIB over to the PBO. */ if ((surface->flags & SFLAG_PBO) && surface->resource.allocatedMemory) - { - /* Copy the contents of the DIB over to the PBO. */ - memcpy(surface->resource.allocatedMemory, surface->dib.bitmap_data, surface->dib.bitmap_size); - } + memcpy(surface->resource.allocatedMemory, surface->dib.bitmap_data, surface->resource.size); /* We locked first, so unlock now. */ wined3d_surface_unmap(surface); @@ -3598,37 +3933,37 @@ HRESULT CDECL wined3d_surface_releasedc(struct wined3d_surface *surface, HDC dc) HRESULT CDECL wined3d_surface_flip(struct wined3d_surface *surface, struct wined3d_surface *override, DWORD flags) { - struct wined3d_swapchain *swapchain; - HRESULT hr; - TRACE("surface %p, override %p, flags %#x.\n", surface, override, flags); - if (surface->container.type != WINED3D_CONTAINER_SWAPCHAIN) + if (flags) { - ERR("Flipped surface is not on a swapchain.\n"); + static UINT once; + if (!once++) + FIXME("Ignoring flags %#x.\n", flags); + else + WARN("Ignoring flags %#x.\n", flags); + } + + if (surface->container.type == WINED3D_CONTAINER_SWAPCHAIN) + { + ERR("Not supported on swapchain surfaces.\n"); return WINEDDERR_NOTFLIPPABLE; } - swapchain = surface->container.u.swapchain; - hr = surface->surface_ops->surface_flip(surface, override); - if (FAILED(hr)) - return hr; + /* Flipping is only supported on render targets and overlays. */ + if (!(surface->resource.usage & (WINED3DUSAGE_RENDERTARGET | WINED3DUSAGE_OVERLAY))) + { + WARN("Tried to flip a non-render target, non-overlay surface.\n"); + return WINEDDERR_NOTFLIPPABLE; + } - /* Just overwrite the swapchain presentation interval. This is ok because - * only ddraw apps can call Flip, and only d3d8 and d3d9 applications - * specify the presentation interval. */ - if (!(flags & (WINEDDFLIP_NOVSYNC | WINEDDFLIP_INTERVAL2 | WINEDDFLIP_INTERVAL3 | WINEDDFLIP_INTERVAL4))) - swapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_ONE; - else if (flags & WINEDDFLIP_NOVSYNC) - swapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_IMMEDIATE; - else if (flags & WINEDDFLIP_INTERVAL2) - swapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_TWO; - else if (flags & WINEDDFLIP_INTERVAL3) - swapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_THREE; - else - swapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_FOUR; + flip_surface(surface, override); - return wined3d_swapchain_present(swapchain, NULL, NULL, swapchain->win_handle, NULL, 0); + /* Update overlays if they're visible. */ + if ((surface->resource.usage & WINED3DUSAGE_OVERLAY) && surface->overlay_dest) + return surface_draw_overlay(surface); + + return WINED3D_OK; } /* Do not call while under the GL lock. */ @@ -3647,28 +3982,16 @@ void surface_internal_preload(struct wined3d_surface *surface, enum WINED3DSRGB } else { - struct wined3d_context *context = NULL; + struct wined3d_context *context; TRACE("(%p) : About to load surface\n", surface); - if (!device->isInDraw) context = context_acquire(device, NULL); - - if (surface->resource.format->id == WINED3DFMT_P8_UINT - || surface->resource.format->id == WINED3DFMT_P8_UINT_A8_UNORM) - { - if (palette9_changed(surface)) - { - TRACE("Reloading surface because the d3d8/9 palette was changed\n"); - /* TODO: This is not necessarily needed with hw palettized texture support */ - surface_load_location(surface, SFLAG_INSYSMEM, NULL); - /* Make sure the texture is reloaded because of the palette change, this kills performance though :( */ - surface_modify_location(surface, SFLAG_INTEXTURE, FALSE); - } - } + /* TODO: Use already acquired context when possible. */ + context = context_acquire(device, NULL); surface_load(surface, srgb == SRGB_SRGB ? TRUE : FALSE); - if (surface->resource.pool == WINED3DPOOL_DEFAULT) + if (surface->resource.pool == WINED3D_POOL_DEFAULT) { /* Tell opengl to try and keep this texture in video ram (well mostly) */ GLclampf tmp; @@ -3678,7 +4001,7 @@ void surface_internal_preload(struct wined3d_surface *surface, enum WINED3DSRGB LEAVE_GL(); } - if (context) context_release(context); + context_release(context); } } @@ -3686,13 +4009,21 @@ BOOL surface_init_sysmem(struct wined3d_surface *surface) { if (!surface->resource.allocatedMemory) { - surface->resource.heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, - surface->resource.size + RESOURCE_ALIGNMENT); if (!surface->resource.heapMemory) { - ERR("Out of memory\n"); - return FALSE; + if (!(surface->resource.heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, + surface->resource.size + RESOURCE_ALIGNMENT))) + { + ERR("Failed to allocate memory.\n"); + return FALSE; + } } + else if (!(surface->flags & SFLAG_CLIENT)) + { + ERR("Surface %p has heapMemory %p and flags %#x.\n", + surface, surface->resource.heapMemory, surface->flags); + } + surface->resource.allocatedMemory = (BYTE *)(((ULONG_PTR)surface->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1)); } @@ -3724,15 +4055,6 @@ static void read_from_framebuffer(struct wined3d_surface *surface, const RECT *r GLint skipPix = 0; GLint skipRow = 0; - if(wined3d_settings.rendertargetlock_mode == RTL_DISABLE) { - static BOOL warned = FALSE; - if(!warned) { - ERR("The application tries to lock the render target, but render target locking is disabled\n"); - warned = TRUE; - } - return; - } - context = context_acquire(device, surface); context_apply_blit_state(context, device); gl_info = context->gl_info; @@ -3963,37 +4285,28 @@ static void read_from_framebuffer(struct wined3d_surface *surface, const RECT *r } } -/* Read the framebuffer contents into a texture */ -static void read_from_framebuffer_texture(struct wined3d_surface *surface, BOOL srgb) +/* Read the framebuffer contents into a texture. Note that this function + * doesn't do any kind of flipping. Using this on an onscreen surface will + * result in a flipped D3D texture. */ +void surface_load_fb_texture(struct wined3d_surface *surface, BOOL srgb) { struct wined3d_device *device = surface->resource.device; - const struct wined3d_gl_info *gl_info; struct wined3d_context *context; - if (!surface_is_offscreen(surface)) - { - /* We would need to flip onscreen surfaces, but there's no efficient - * way to do that here. It makes more sense for the caller to - * explicitly go through sysmem. */ - ERR("Not supported for onscreen targets.\n"); - return; - } - - /* Activate the surface to read from. In some situations it isn't the currently active target(e.g. backbuffer - * locking during offscreen rendering). RESOURCELOAD is ok because glCopyTexSubImage2D isn't affected by any - * states in the stateblock, and no driver was found yet that had bugs in that regard. - */ context = context_acquire(device, surface); - gl_info = context->gl_info; + device_invalidate_state(device, STATE_FRAMEBUFFER); - surface_prepare_texture(surface, gl_info, srgb); - surface_bind_and_dirtify(surface, gl_info, srgb); + surface_prepare_texture(surface, context, srgb); + surface_bind_and_dirtify(surface, context, srgb); TRACE("Reading back offscreen render target %p.\n", surface); ENTER_GL(); - glReadBuffer(device->offscreenBuffer); + if (surface_is_offscreen(surface)) + glReadBuffer(device->offscreenBuffer); + else + glReadBuffer(surface_get_gl_buffer(surface)); checkGLcall("glReadBuffer"); glCopyTexSubImage2D(surface->texture_target, surface->texture_level, @@ -4007,7 +4320,7 @@ static void read_from_framebuffer_texture(struct wined3d_surface *surface, BOOL /* Context activation is done by the caller. */ static void surface_prepare_texture_internal(struct wined3d_surface *surface, - const struct wined3d_gl_info *gl_info, BOOL srgb) + struct wined3d_context *context, BOOL srgb) { DWORD alloc_flag = srgb ? SFLAG_SRGBALLOCATED : SFLAG_ALLOCATED; CONVERT_TYPES convert; @@ -4019,13 +4332,13 @@ static void surface_prepare_texture_internal(struct wined3d_surface *surface, if (convert != NO_CONVERSION || format.convert) surface->flags |= SFLAG_CONVERTED; else surface->flags &= ~SFLAG_CONVERTED; - surface_bind_and_dirtify(surface, gl_info, srgb); - surface_allocate_surface(surface, gl_info, &format, srgb); + surface_bind_and_dirtify(surface, context, srgb); + surface_allocate_surface(surface, context->gl_info, &format, srgb); surface->flags |= alloc_flag; } /* Context activation is done by the caller. */ -void surface_prepare_texture(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info, BOOL srgb) +void surface_prepare_texture(struct wined3d_surface *surface, struct wined3d_context *context, BOOL srgb) { if (surface->container.type == WINED3D_CONTAINER_TEXTURE) { @@ -4038,13 +4351,39 @@ void surface_prepare_texture(struct wined3d_surface *surface, const struct wined for (i = 0; i < sub_count; ++i) { struct wined3d_surface *s = surface_from_resource(texture->sub_resources[i]); - surface_prepare_texture_internal(s, gl_info, srgb); + surface_prepare_texture_internal(s, context, srgb); } return; } - surface_prepare_texture_internal(surface, gl_info, srgb); + surface_prepare_texture_internal(surface, context, srgb); +} + +void surface_prepare_rb(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info, BOOL multisample) +{ + if (multisample) + { + if (surface->rb_multisample) + return; + + gl_info->fbo_ops.glGenRenderbuffers(1, &surface->rb_multisample); + gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, surface->rb_multisample); + gl_info->fbo_ops.glRenderbufferStorageMultisample(GL_RENDERBUFFER, surface->resource.multisample_type, + surface->resource.format->glInternal, surface->pow2Width, surface->pow2Height); + TRACE("Created multisample rb %u.\n", surface->rb_multisample); + } + else + { + if (surface->rb_resolved) + return; + + gl_info->fbo_ops.glGenRenderbuffers(1, &surface->rb_resolved); + gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, surface->rb_resolved); + gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, surface->resource.format->glInternal, + surface->pow2Width, surface->pow2Height); + TRACE("Created resolved rb %u.\n", surface->rb_resolved); + } } static void flush_to_framebuffer_drawpixels(struct wined3d_surface *surface, @@ -4122,11 +4461,11 @@ static void flush_to_framebuffer_drawpixels(struct wined3d_surface *surface, context_release(context); } -HRESULT d3dfmt_get_conv(struct wined3d_surface *surface, BOOL need_alpha_ck, +HRESULT d3dfmt_get_conv(const struct wined3d_surface *surface, BOOL need_alpha_ck, BOOL use_texturing, struct wined3d_format *format, CONVERT_TYPES *convert) { BOOL colorkey_active = need_alpha_ck && (surface->CKeyFlags & WINEDDSD_CKSRCBLT); - struct wined3d_device *device = surface->resource.device; + const struct wined3d_device *device = surface->resource.device; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; BOOL blit_supported = FALSE; @@ -4233,13 +4572,27 @@ HRESULT d3dfmt_get_conv(struct wined3d_surface *surface, BOOL need_alpha_ck, break; } + if (*convert != NO_CONVERSION) + { + format->rtInternal = format->glInternal; + format->glGammaInternal = format->glInternal; + } + return WINED3D_OK; } -void d3dfmt_p8_init_palette(struct wined3d_surface *surface, BYTE table[256][4], BOOL colorkey) +static BOOL color_in_range(const struct wined3d_color_key *color_key, DWORD color) { - struct wined3d_device *device = surface->resource.device; - struct wined3d_palette *pal = surface->palette; + /* FIXME: Is this really how color keys are supposed to work? I think it + * makes more sense to compare the individual channels. */ + return color >= color_key->color_space_low_value + && color <= color_key->color_space_high_value; +} + +void d3dfmt_p8_init_palette(const struct wined3d_surface *surface, BYTE table[256][4], BOOL colorkey) +{ + const struct wined3d_device *device = surface->resource.device; + const struct wined3d_palette *pal = surface->palette; BOOL index_in_alpha = FALSE; unsigned int i; @@ -4252,31 +4605,12 @@ void d3dfmt_p8_init_palette(struct wined3d_surface *surface, BYTE table[256][4], if (!pal) { - UINT dxVersion = device->wined3d->dxVersion; - - /* In DirectDraw the palette is a property of the surface, there are no such things as device palettes. */ - if (dxVersion <= 7) + ERR("This code should never get entered for DirectDraw!, expect problems\n"); + if (index_in_alpha) { - ERR("This code should never get entered for DirectDraw!, expect problems\n"); - if (index_in_alpha) - { - /* Guarantees that memory representation remains correct after sysmem<->texture transfers even if - * there's no palette at this time. */ - for (i = 0; i < 256; i++) table[i][3] = i; - } - } - else - { - /* Direct3D >= 8 palette usage style: P8 textures use device palettes, palette entry format is A8R8G8B8, - * alpha is stored in peFlags and may be used by the app if D3DPTEXTURECAPS_ALPHAPALETTE device - * capability flag is present (wine does advertise this capability) */ - for (i = 0; i < 256; ++i) - { - table[i][0] = device->palettes[device->currentPalette][i].peRed; - table[i][1] = device->palettes[device->currentPalette][i].peGreen; - table[i][2] = device->palettes[device->currentPalette][i].peBlue; - table[i][3] = device->palettes[device->currentPalette][i].peFlags; - } + /* Guarantees that memory representation remains correct after sysmem<->texture transfers even if + * there's no palette at this time. */ + for (i = 0; i < 256; i++) table[i][3] = i; } } else @@ -4296,22 +4630,13 @@ void d3dfmt_p8_init_palette(struct wined3d_surface *surface, BYTE table[256][4], * color key itself is passed to glAlphaFunc in other cases the * alpha component of pixels that should be masked away is set to 0. */ if (index_in_alpha) - { table[i][3] = i; - } - else if (colorkey && (i >= surface->SrcBltCKey.dwColorSpaceLowValue) - && (i <= surface->SrcBltCKey.dwColorSpaceHighValue)) - { + else if (colorkey && color_in_range(&surface->src_blt_color_key, i)) table[i][3] = 0x00; - } else if (pal->flags & WINEDDPCAPS_ALPHA) - { table[i][3] = pal->palents[i].peFlags; - } else - { table[i][3] = 0xFF; - } } } } @@ -4377,8 +4702,7 @@ static HRESULT d3dfmt_convert_surface(const BYTE *src, BYTE *dst, UINT pitch, UI for (x = 0; x < width; x++ ) { WORD color = *Source++; *Dest = ((color & 0xFFC0) | ((color & 0x1F) << 1)); - if ((color < surface->SrcBltCKey.dwColorSpaceLowValue) - || (color > surface->SrcBltCKey.dwColorSpaceHighValue)) + if (!color_in_range(&surface->src_blt_color_key, color)) *Dest |= 0x0001; Dest++; } @@ -4399,8 +4723,7 @@ static HRESULT d3dfmt_convert_surface(const BYTE *src, BYTE *dst, UINT pitch, UI for (x = 0; x < width; x++ ) { WORD color = *Source++; *Dest = color; - if ((color < surface->SrcBltCKey.dwColorSpaceLowValue) - || (color > surface->SrcBltCKey.dwColorSpaceHighValue)) + if (!color_in_range(&surface->src_blt_color_key, color)) *Dest |= (1 << 15); else *Dest &= ~(1 << 15); @@ -4421,8 +4744,7 @@ static HRESULT d3dfmt_convert_surface(const BYTE *src, BYTE *dst, UINT pitch, UI for (x = 0; x < width; x++) { DWORD color = ((DWORD)source[0] << 16) + ((DWORD)source[1] << 8) + (DWORD)source[2] ; DWORD dstcolor = color << 8; - if ((color < surface->SrcBltCKey.dwColorSpaceLowValue) - || (color > surface->SrcBltCKey.dwColorSpaceHighValue)) + if (!color_in_range(&surface->src_blt_color_key, color)) dstcolor |= 0xff; *(DWORD*)dest = dstcolor; source += 3; @@ -4443,8 +4765,7 @@ static HRESULT d3dfmt_convert_surface(const BYTE *src, BYTE *dst, UINT pitch, UI for (x = 0; x < width; x++) { DWORD color = 0xffffff & *(const DWORD*)source; DWORD dstcolor = color << 8; - if ((color < surface->SrcBltCKey.dwColorSpaceLowValue) - || (color > surface->SrcBltCKey.dwColorSpaceHighValue)) + if (!color_in_range(&surface->src_blt_color_key, color)) dstcolor |= 0xff; *(DWORD*)dest = dstcolor; source += 4; @@ -4460,35 +4781,6 @@ static HRESULT d3dfmt_convert_surface(const BYTE *src, BYTE *dst, UINT pitch, UI return WINED3D_OK; } -BOOL palette9_changed(struct wined3d_surface *surface) -{ - struct wined3d_device *device = surface->resource.device; - - if (surface->palette || (surface->resource.format->id != WINED3DFMT_P8_UINT - && surface->resource.format->id != WINED3DFMT_P8_UINT_A8_UNORM)) - { - /* If a ddraw-style palette is attached assume no d3d9 palette change. - * Also the palette isn't interesting if the surface format isn't P8 or A8P8 - */ - return FALSE; - } - - if (surface->palette9) - { - if (!memcmp(surface->palette9, device->palettes[device->currentPalette], sizeof(PALETTEENTRY) * 256)) - { - return FALSE; - } - } - else - { - surface->palette9 = HeapAlloc(GetProcessHeap(), 0, sizeof(PALETTEENTRY) * 256); - } - memcpy(surface->palette9, device->palettes[device->currentPalette], sizeof(PALETTEENTRY) * 256); - - return TRUE; -} - void flip_surface(struct wined3d_surface *front, struct wined3d_surface *back) { /* Flip the surface contents */ @@ -4502,16 +4794,9 @@ void flip_surface(struct wined3d_surface *front, struct wined3d_surface *back) /* Flip the DIBsection */ { - HBITMAP tmp; - BOOL hasDib = front->flags & SFLAG_DIBSECTION; - tmp = front->dib.DIBsection; + HBITMAP tmp = front->dib.DIBsection; front->dib.DIBsection = back->dib.DIBsection; back->dib.DIBsection = tmp; - - if (back->flags & SFLAG_DIBSECTION) front->flags |= SFLAG_DIBSECTION; - else front->flags &= ~SFLAG_DIBSECTION; - if (hasDib) back->flags |= SFLAG_DIBSECTION; - else back->flags &= ~SFLAG_DIBSECTION; } /* Flip the surface data */ @@ -4538,14 +4823,6 @@ void flip_surface(struct wined3d_surface *front, struct wined3d_surface *back) back->pbo = tmp_pbo; } - /* client_memory should not be different, but just in case */ - { - BOOL tmp; - tmp = front->dib.client_memory; - front->dib.client_memory = back->dib.client_memory; - back->dib.client_memory = tmp; - } - /* Flip the opengl texture */ { GLuint tmp; @@ -4558,6 +4835,14 @@ void flip_surface(struct wined3d_surface *front, struct wined3d_surface *back) back->texture_name_srgb = front->texture_name_srgb; front->texture_name_srgb = tmp; + tmp = back->rb_multisample; + back->rb_multisample = front->rb_multisample; + front->rb_multisample = tmp; + + tmp = back->rb_resolved; + back->rb_resolved = front->rb_resolved; + front->rb_resolved = tmp; + resource_unload(&back->resource); resource_unload(&front->resource); } @@ -4572,7 +4857,7 @@ void flip_surface(struct wined3d_surface *front, struct wined3d_surface *back) /* Does a direct frame buffer -> texture copy. Stretching is done with single * pixel copy calls. */ static void fb_copy_to_texture_direct(struct wined3d_surface *dst_surface, struct wined3d_surface *src_surface, - const RECT *src_rect, const RECT *dst_rect_in, WINED3DTEXTUREFILTERTYPE Filter) + const RECT *src_rect, const RECT *dst_rect_in, enum wined3d_texture_filter_type filter) { struct wined3d_device *device = dst_surface->resource.device; float xrel, yrel; @@ -4597,8 +4882,7 @@ static void fb_copy_to_texture_direct(struct wined3d_surface *dst_surface, struc ENTER_GL(); /* Bind the target texture */ - glBindTexture(dst_surface->texture_target, dst_surface->texture_name); - checkGLcall("glBindTexture"); + context_bind_texture(context, dst_surface->texture_target, dst_surface->texture_name); if (surface_is_offscreen(src_surface)) { TRACE("Reading from an offscreen target\n"); @@ -4618,11 +4902,10 @@ static void fb_copy_to_texture_direct(struct wined3d_surface *dst_surface, struc { FIXME("Doing a pixel by pixel copy from the framebuffer to a texture, expect major performance issues\n"); - if(Filter != WINED3DTEXF_NONE && Filter != WINED3DTEXF_POINT) { - ERR("Texture filtering not supported in direct blit\n"); - } + if (filter != WINED3D_TEXF_NONE && filter != WINED3D_TEXF_POINT) + ERR("Texture filtering not supported in direct blit.\n"); } - else if ((Filter != WINED3DTEXF_NONE && Filter != WINED3DTEXF_POINT) + else if ((filter != WINED3D_TEXF_NONE && filter != WINED3D_TEXF_POINT) && ((yrel - 1.0f < -eps) || (yrel - 1.0f > eps))) { ERR("Texture filtering not supported in direct blit\n"); @@ -4684,7 +4967,7 @@ static void fb_copy_to_texture_direct(struct wined3d_surface *dst_surface, struc /* Uses the hardware to stretch and flip the image */ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, struct wined3d_surface *src_surface, - const RECT *src_rect, const RECT *dst_rect_in, WINED3DTEXTUREFILTERTYPE Filter) + const RECT *src_rect, const RECT *dst_rect_in, enum wined3d_texture_filter_type filter) { struct wined3d_device *device = dst_surface->resource.device; struct wined3d_swapchain *src_swapchain = NULL; @@ -4732,16 +5015,14 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st if(noBackBufferBackup) { glGenTextures(1, &backup); checkGLcall("glGenTextures"); - glBindTexture(GL_TEXTURE_2D, backup); - checkGLcall("glBindTexture(GL_TEXTURE_2D, backup)"); + context_bind_texture(context, GL_TEXTURE_2D, backup); texture_target = GL_TEXTURE_2D; } else { /* Backup the back buffer and copy the source buffer into a texture to draw an upside down stretched quad. If * we are reading from the back buffer, the backup can be used as source texture */ texture_target = src_surface->texture_target; - glBindTexture(texture_target, src_surface->texture_name); - checkGLcall("glBindTexture(texture_target, src_surface->texture_name)"); + context_bind_texture(context, texture_target, src_surface->texture_name); glEnable(texture_target); checkGLcall("glEnable(texture_target)"); @@ -4781,10 +5062,10 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st /* No issue with overriding these - the sampler is dirty due to blit usage */ glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, - wined3d_gl_mag_filter(magLookup, Filter)); + wined3d_gl_mag_filter(magLookup, filter)); checkGLcall("glTexParameteri"); glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, - wined3d_gl_min_mip_filter(minMipLookup, Filter, WINED3DTEXF_NONE)); + wined3d_gl_min_mip_filter(minMipLookup, filter, WINED3D_TEXF_NONE)); checkGLcall("glTexParameteri"); if (src_surface->container.type == WINED3D_CONTAINER_SWAPCHAIN) @@ -4800,8 +5081,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st glGenTextures(1, &src); checkGLcall("glGenTextures(1, &src)"); - glBindTexture(GL_TEXTURE_2D, src); - checkGLcall("glBindTexture(GL_TEXTURE_2D, src)"); + context_bind_texture(context, GL_TEXTURE_2D, src); /* TODO: Only copy the part that will be read. Use src_rect->left, src_rect->bottom as origin, but with the width watch * out for power of 2 sizes @@ -4887,8 +5167,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st } /* Now read the stretched and upside down image into the destination texture */ - glBindTexture(texture_target, dst_surface->texture_name); - checkGLcall("glBindTexture"); + context_bind_texture(context, texture_target, dst_surface->texture_name); glCopyTexSubImage2D(texture_target, 0, dst_rect.left, dst_rect.top, /* xoffset, yoffset */ @@ -4904,8 +5183,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st glEnable(GL_TEXTURE_2D); texture_target = GL_TEXTURE_2D; } - glBindTexture(GL_TEXTURE_2D, backup); - checkGLcall("glBindTexture(GL_TEXTURE_2D, backup)"); + context_bind_texture(context, GL_TEXTURE_2D, backup); } else { @@ -4915,8 +5193,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st glEnable(src_surface->texture_target); texture_target = src_surface->texture_target; } - glBindTexture(src_surface->texture_target, src_surface->texture_name); - checkGLcall("glBindTexture(src_surface->texture_target, src_surface->texture_name)"); + context_bind_texture(context, src_surface->texture_target, src_surface->texture_name); } glBegin(GL_QUADS); @@ -4968,7 +5245,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st * drawable is limited to the window's client area. The sysmem and texture * copies do have the full screen size. Note that GL has a bottom-left * origin, while D3D has a top-left origin. */ -void surface_translate_drawable_coords(struct wined3d_surface *surface, HWND window, RECT *rect) +void surface_translate_drawable_coords(const struct wined3d_surface *surface, HWND window, RECT *rect) { UINT drawable_height; @@ -4993,137 +5270,8 @@ void surface_translate_drawable_coords(struct wined3d_surface *surface, HWND win rect->bottom = drawable_height - rect->bottom; } -/* blit between surface locations. onscreen on different swapchains is not supported. - * depth / stencil is not supported. */ -static void surface_blt_fbo(struct wined3d_device *device, const WINED3DTEXTUREFILTERTYPE filter, - struct wined3d_surface *src_surface, DWORD src_location, const RECT *src_rect_in, - struct wined3d_surface *dst_surface, DWORD dst_location, const RECT *dst_rect_in) -{ - const struct wined3d_gl_info *gl_info; - struct wined3d_context *context; - RECT src_rect, dst_rect; - GLenum gl_filter; - - TRACE("device %p, filter %s,\n", device, debug_d3dtexturefiltertype(filter)); - TRACE("src_surface %p, src_location %s, src_rect %s,\n", - src_surface, debug_surflocation(src_location), wine_dbgstr_rect(src_rect_in)); - TRACE("dst_surface %p, dst_location %s, dst_rect %s.\n", - dst_surface, debug_surflocation(dst_location), wine_dbgstr_rect(dst_rect_in)); - - src_rect = *src_rect_in; - dst_rect = *dst_rect_in; - - switch (filter) - { - case WINED3DTEXF_LINEAR: - gl_filter = GL_LINEAR; - break; - - default: - FIXME("Unsupported filter mode %s (%#x).\n", debug_d3dtexturefiltertype(filter), filter); - case WINED3DTEXF_NONE: - case WINED3DTEXF_POINT: - gl_filter = GL_NEAREST; - break; - } - - if (src_location == SFLAG_INDRAWABLE && surface_is_offscreen(src_surface)) - src_location = SFLAG_INTEXTURE; - if (dst_location == SFLAG_INDRAWABLE && surface_is_offscreen(dst_surface)) - dst_location = SFLAG_INTEXTURE; - - /* Make sure the locations are up-to-date. Loading the destination - * surface isn't required if the entire surface is overwritten. (And is - * in fact harmful if we're being called by surface_load_location() with - * the purpose of loading the destination surface.) */ - surface_load_location(src_surface, src_location, NULL); - if (!surface_is_full_rect(dst_surface, &dst_rect)) - surface_load_location(dst_surface, dst_location, NULL); - - if (src_location == SFLAG_INDRAWABLE) context = context_acquire(device, src_surface); - else if (dst_location == SFLAG_INDRAWABLE) context = context_acquire(device, dst_surface); - else context = context_acquire(device, NULL); - - if (!context->valid) - { - context_release(context); - WARN("Invalid context, skipping blit.\n"); - return; - } - - gl_info = context->gl_info; - - if (src_location == SFLAG_INDRAWABLE) - { - GLenum buffer = surface_get_gl_buffer(src_surface); - - TRACE("Source surface %p is onscreen.\n", src_surface); - - surface_translate_drawable_coords(src_surface, context->win_handle, &src_rect); - - ENTER_GL(); - context_bind_fbo(context, GL_READ_FRAMEBUFFER, NULL); - glReadBuffer(buffer); - checkGLcall("glReadBuffer()"); - } - else - { - TRACE("Source surface %p is offscreen.\n", src_surface); - ENTER_GL(); - context_apply_fbo_state_blit(context, GL_READ_FRAMEBUFFER, src_surface, NULL, src_location); - glReadBuffer(GL_COLOR_ATTACHMENT0); - checkGLcall("glReadBuffer()"); - } - context_check_fbo_status(context, GL_READ_FRAMEBUFFER); - LEAVE_GL(); - - if (dst_location == SFLAG_INDRAWABLE) - { - GLenum buffer = surface_get_gl_buffer(dst_surface); - - TRACE("Destination surface %p is onscreen.\n", dst_surface); - - surface_translate_drawable_coords(dst_surface, context->win_handle, &dst_rect); - - ENTER_GL(); - context_bind_fbo(context, GL_DRAW_FRAMEBUFFER, NULL); - context_set_draw_buffer(context, buffer); - } - else - { - TRACE("Destination surface %p is offscreen.\n", dst_surface); - - ENTER_GL(); - context_apply_fbo_state_blit(context, GL_DRAW_FRAMEBUFFER, dst_surface, NULL, dst_location); - context_set_draw_buffer(context, GL_COLOR_ATTACHMENT0); - } - context_check_fbo_status(context, GL_DRAW_FRAMEBUFFER); - - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE)); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE1)); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE2)); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE3)); - - glDisable(GL_SCISSOR_TEST); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE)); - - gl_info->fbo_ops.glBlitFramebuffer(src_rect.left, src_rect.top, src_rect.right, src_rect.bottom, - dst_rect.left, dst_rect.top, dst_rect.right, dst_rect.bottom, GL_COLOR_BUFFER_BIT, gl_filter); - checkGLcall("glBlitFramebuffer()"); - - LEAVE_GL(); - - if (wined3d_settings.strict_draw_ordering - || (dst_location == SFLAG_INDRAWABLE - && dst_surface->container.u.swapchain->front_buffer == dst_surface)) - wglFlush(); - - context_release(context); -} - -static void surface_blt_to_drawable(struct wined3d_device *device, - WINED3DTEXTUREFILTERTYPE filter, BOOL color_key, +static void surface_blt_to_drawable(const struct wined3d_device *device, + enum wined3d_texture_filter_type filter, BOOL color_key, struct wined3d_surface *src_surface, const RECT *src_rect_in, struct wined3d_surface *dst_surface, const RECT *dst_rect_in) { @@ -5145,7 +5293,7 @@ static void surface_blt_to_drawable(struct wined3d_device *device, if (!surface_is_offscreen(dst_surface)) surface_translate_drawable_coords(dst_surface, context->win_handle, &dst_rect); - device->blitter->set_shader(device->blit_priv, context->gl_info, src_surface); + device->blitter->set_shader(device->blit_priv, context, src_surface); ENTER_GL(); @@ -5159,7 +5307,7 @@ static void surface_blt_to_drawable(struct wined3d_device *device, * the palette entries. In other cases pixels that should be masked * away have alpha set to 0. */ if (primary_render_target_is_p8(device)) - glAlphaFunc(GL_NOTEQUAL, (float)src_surface->SrcBltCKey.dwColorSpaceLowValue / 256.0f); + glAlphaFunc(GL_NOTEQUAL, (float)src_surface->src_blt_color_key.color_space_low_value / 256.0f); else glAlphaFunc(GL_NOTEQUAL, 0.0f); checkGLcall("glAlphaFunc"); @@ -5170,7 +5318,7 @@ static void surface_blt_to_drawable(struct wined3d_device *device, checkGLcall("glDisable(GL_ALPHA_TEST)"); } - draw_textured_quad(src_surface, &src_rect, &dst_rect, filter); + draw_textured_quad(src_surface, context, &src_rect, &dst_rect, filter); if (color_key) { @@ -5192,7 +5340,7 @@ static void surface_blt_to_drawable(struct wined3d_device *device, } /* Do not call while under the GL lock. */ -HRESULT surface_color_fill(struct wined3d_surface *s, const RECT *rect, const WINED3DCOLORVALUE *color) +HRESULT surface_color_fill(struct wined3d_surface *s, const RECT *rect, const struct wined3d_color *color) { struct wined3d_device *device = s->resource.device; const struct blit_shader *blitter; @@ -5209,21 +5357,20 @@ HRESULT surface_color_fill(struct wined3d_surface *s, const RECT *rect, const WI } /* Do not call while under the GL lock. */ -static HRESULT IWineD3DSurfaceImpl_BltOverride(struct wined3d_surface *dst_surface, const RECT *DestRect, - struct wined3d_surface *src_surface, const RECT *SrcRect, DWORD flags, const WINEDDBLTFX *DDBltFx, - WINED3DTEXTUREFILTERTYPE Filter) +static HRESULT IWineD3DSurfaceImpl_BltOverride(struct wined3d_surface *dst_surface, const RECT *dst_rect, + struct wined3d_surface *src_surface, const RECT *src_rect, DWORD flags, const WINEDDBLTFX *DDBltFx, + enum wined3d_texture_filter_type filter) { struct wined3d_device *device = dst_surface->resource.device; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; struct wined3d_swapchain *srcSwapchain = NULL, *dstSwapchain = NULL; - RECT dst_rect, src_rect; TRACE("dst_surface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, blt_fx %p, filter %s.\n", - dst_surface, wine_dbgstr_rect(DestRect), src_surface, wine_dbgstr_rect(SrcRect), - flags, DDBltFx, debug_d3dtexturefiltertype(Filter)); + dst_surface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect), + flags, DDBltFx, debug_d3dtexturefiltertype(filter)); /* Get the swapchain. One of the surfaces has to be a primary surface */ - if (dst_surface->resource.pool == WINED3DPOOL_SYSTEMMEM) + if (dst_surface->resource.pool == WINED3D_POOL_SYSTEM_MEM) { WARN("Destination is in sysmem, rejecting gl blt\n"); return WINED3DERR_INVALIDCALL; @@ -5234,7 +5381,7 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(struct wined3d_surface *dst_surfa if (src_surface) { - if (src_surface->resource.pool == WINED3DPOOL_SYSTEMMEM) + if (src_surface->resource.pool == WINED3D_POOL_SYSTEM_MEM) { WARN("Src is in sysmem, rejecting gl blt\n"); return WINED3DERR_INVALIDCALL; @@ -5261,114 +5408,19 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(struct wined3d_surface *dst_surfa return WINED3DERR_INVALIDCALL; } - surface_get_rect(dst_surface, DestRect, &dst_rect); - if (src_surface) surface_get_rect(src_surface, SrcRect, &src_rect); - - /* The only case where both surfaces on a swapchain are supported is a back buffer -> front buffer blit on the same swapchain */ - if (dstSwapchain && dstSwapchain == srcSwapchain && dstSwapchain->back_buffers - && dst_surface == dstSwapchain->front_buffer - && src_surface == dstSwapchain->back_buffers[0]) + if (dstSwapchain && dstSwapchain == srcSwapchain) { - /* Half-Life does a Blt from the back buffer to the front buffer, - * Full surface size, no flags... Use present instead - * - * This path will only be entered for d3d7 and ddraw apps, because d3d8/9 offer no way to blit TO the front buffer - */ - - /* Check rects - IWineD3DDevice_Present doesn't handle them */ - while(1) - { - TRACE("Looking if a Present can be done...\n"); - /* Source Rectangle must be full surface */ - if (src_rect.left || src_rect.top - || src_rect.right != src_surface->resource.width - || src_rect.bottom != src_surface->resource.height) - { - TRACE("No, Source rectangle doesn't match\n"); - break; - } - - /* No stretching may occur */ - if(src_rect.right != dst_rect.right - dst_rect.left || - src_rect.bottom != dst_rect.bottom - dst_rect.top) { - TRACE("No, stretching is done\n"); - break; - } - - /* Destination must be full surface or match the clipping rectangle */ - if (dst_surface->clipper && dst_surface->clipper->hWnd) - { - RECT cliprect; - POINT pos[2]; - GetClientRect(dst_surface->clipper->hWnd, &cliprect); - pos[0].x = dst_rect.left; - pos[0].y = dst_rect.top; - pos[1].x = dst_rect.right; - pos[1].y = dst_rect.bottom; - MapWindowPoints(GetDesktopWindow(), dst_surface->clipper->hWnd, pos, 2); - - if(pos[0].x != cliprect.left || pos[0].y != cliprect.top || - pos[1].x != cliprect.right || pos[1].y != cliprect.bottom) - { - TRACE("No, dest rectangle doesn't match(clipper)\n"); - TRACE("Clip rect at %s\n", wine_dbgstr_rect(&cliprect)); - TRACE("Blt dest: %s\n", wine_dbgstr_rect(&dst_rect)); - break; - } - } - else if (dst_rect.left || dst_rect.top - || dst_rect.right != dst_surface->resource.width - || dst_rect.bottom != dst_surface->resource.height) - { - TRACE("No, dest rectangle doesn't match(surface size)\n"); - break; - } - - TRACE("Yes\n"); - - /* These flags are unimportant for the flag check, remove them */ - if (!(flags & ~(WINEDDBLT_DONOTWAIT | WINEDDBLT_WAIT))) - { - WINED3DSWAPEFFECT orig_swap = dstSwapchain->presentParms.SwapEffect; - - /* The idea behind this is that a glReadPixels and a glDrawPixels call - * take very long, while a flip is fast. - * This applies to Half-Life, which does such Blts every time it finished - * a frame, and to Prince of Persia 3D, which uses this to draw at least the main - * menu. This is also used by all apps when they do windowed rendering - * - * The problem is that flipping is not really the same as copying. After a - * Blt the front buffer is a copy of the back buffer, and the back buffer is - * untouched. Therefore it's necessary to override the swap effect - * and to set it back after the flip. - * - * Windowed Direct3D < 7 apps do the same. The D3D7 sdk demos are nice - * testcases. - */ - - dstSwapchain->presentParms.SwapEffect = WINED3DSWAPEFFECT_COPY; - dstSwapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_IMMEDIATE; - - TRACE("Full screen back buffer -> front buffer blt, performing a flip instead.\n"); - wined3d_swapchain_present(dstSwapchain, NULL, NULL, dstSwapchain->win_handle, NULL, 0); - - dstSwapchain->presentParms.SwapEffect = orig_swap; - - return WINED3D_OK; - } - break; - } - - TRACE("Unsupported blit between buffers on the same swapchain\n"); - return WINED3DERR_INVALIDCALL; - } else if(dstSwapchain && dstSwapchain == srcSwapchain) { FIXME("Implement hardware blit between two surfaces on the same swapchain\n"); return WINED3DERR_INVALIDCALL; - } else if(dstSwapchain && srcSwapchain) { + } + + if (dstSwapchain && srcSwapchain) + { FIXME("Implement hardware blit between two different swapchains\n"); return WINED3DERR_INVALIDCALL; } - else if (dstSwapchain) + + if (dstSwapchain) { /* Handled with regular texture -> swapchain blit */ if (src_surface == device->fb.render_targets[0]) @@ -5400,11 +5452,10 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(struct wined3d_surface *dst_surfa /* Destination color key is checked above */ } - if(dst_rect.right - dst_rect.left != src_rect.right - src_rect.left) { + if (dst_rect->right - dst_rect->left != src_rect->right - src_rect->left) stretchx = TRUE; - } else { + else stretchx = FALSE; - } /* Blt is a pretty powerful call, while glCopyTexSubImage2D is not. glCopyTexSubImage cannot * flip the image nor scale it. @@ -5415,28 +5466,17 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(struct wined3d_surface *dst_surfa * than the frame buffer, draw an upside down scaled image onto the fb, read it back and restore the * back buffer. This is slower than reading line per line, thus not used for flipping * -> If the app wants a scaled image with a dest rect that is bigger than the fb, it has to be copied - * pixel by pixel - * - * If EXT_framebuffer_blit is supported that can be used instead. Note that EXT_framebuffer_blit implies - * FBO support, so it doesn't really make sense to try and make it work with different offscreen rendering - * backends. */ - if (fbo_blit_supported(gl_info, WINED3D_BLIT_OP_COLOR_BLIT, - &src_rect, src_surface->resource.usage, src_surface->resource.pool, src_surface->resource.format, - &dst_rect, dst_surface->resource.usage, dst_surface->resource.pool, dst_surface->resource.format)) + * pixel by pixel. */ + if (!stretchx || dst_rect->right - dst_rect->left > src_surface->resource.width + || dst_rect->bottom - dst_rect->top > src_surface->resource.height) { - surface_blt_fbo(device, Filter, - src_surface, SFLAG_INDRAWABLE, &src_rect, - dst_surface, SFLAG_INDRAWABLE, &dst_rect); - surface_modify_location(dst_surface, SFLAG_INDRAWABLE, TRUE); + TRACE("No stretching in x direction, using direct framebuffer -> texture copy.\n"); + fb_copy_to_texture_direct(dst_surface, src_surface, src_rect, dst_rect, filter); } - else if (!stretchx || dst_rect.right - dst_rect.left > src_surface->resource.width - || dst_rect.bottom - dst_rect.top > src_surface->resource.height) + else { - TRACE("No stretching in x direction, using direct framebuffer -> texture copy\n"); - fb_copy_to_texture_direct(dst_surface, src_surface, &src_rect, &dst_rect, Filter); - } else { - TRACE("Using hardware stretching to flip / stretch the texture\n"); - fb_copy_to_texture_hwstretch(dst_surface, src_surface, &src_rect, &dst_rect, Filter); + TRACE("Using hardware stretching to flip / stretch the texture.\n"); + fb_copy_to_texture_hwstretch(dst_surface, src_surface, src_rect, dst_rect, filter); } if (!(dst_surface->flags & SFLAG_DONOTFREE)) @@ -5455,42 +5495,14 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(struct wined3d_surface *dst_surfa else if (src_surface) { /* Blit from offscreen surface to render target */ + struct wined3d_color_key old_blt_key = src_surface->src_blt_color_key; DWORD oldCKeyFlags = src_surface->CKeyFlags; - WINEDDCOLORKEY oldBltCKey = src_surface->SrcBltCKey; TRACE("Blt from surface %p to rendertarget %p\n", src_surface, dst_surface); - if (!(flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE)) - && fbo_blit_supported(gl_info, WINED3D_BLIT_OP_COLOR_BLIT, - &src_rect, src_surface->resource.usage, src_surface->resource.pool, - src_surface->resource.format, - &dst_rect, dst_surface->resource.usage, dst_surface->resource.pool, - dst_surface->resource.format)) - { - TRACE("Using surface_blt_fbo.\n"); - /* The source is always a texture, but never the currently active render target, and the texture - * contents are never upside down. */ - surface_blt_fbo(device, Filter, - src_surface, SFLAG_INDRAWABLE, &src_rect, - dst_surface, SFLAG_INDRAWABLE, &dst_rect); - surface_modify_location(dst_surface, SFLAG_INDRAWABLE, TRUE); - return WINED3D_OK; - } - - if (!(flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE)) - && arbfp_blit.blit_supported(gl_info, WINED3D_BLIT_OP_COLOR_BLIT, - &src_rect, src_surface->resource.usage, src_surface->resource.pool, - src_surface->resource.format, - &dst_rect, dst_surface->resource.usage, dst_surface->resource.pool, - dst_surface->resource.format)) - { - return arbfp_blit_surface(device, src_surface, &src_rect, dst_surface, &dst_rect, - WINED3D_BLIT_OP_COLOR_BLIT, Filter); - } - if (!device->blitter->blit_supported(gl_info, WINED3D_BLIT_OP_COLOR_BLIT, - &src_rect, src_surface->resource.usage, src_surface->resource.pool, src_surface->resource.format, - &dst_rect, dst_surface->resource.usage, dst_surface->resource.pool, dst_surface->resource.format)) + src_rect, src_surface->resource.usage, src_surface->resource.pool, src_surface->resource.format, + dst_rect, dst_surface->resource.usage, dst_surface->resource.pool, dst_surface->resource.format)) { FIXME("Unsupported blit operation falling back to software\n"); return WINED3DERR_INVALIDCALL; @@ -5511,7 +5523,7 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(struct wined3d_surface *dst_surfa { /* Use color key from DDBltFx */ src_surface->CKeyFlags |= WINEDDSD_CKSRCBLT; - src_surface->SrcBltCKey = DDBltFx->ddckSrcColorkey; + src_surface->src_blt_color_key = DDBltFx->ddckSrcColorkey; } else { @@ -5519,33 +5531,17 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(struct wined3d_surface *dst_surfa src_surface->CKeyFlags &= ~WINEDDSD_CKSRCBLT; } - surface_blt_to_drawable(device, Filter, flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE), - src_surface, &src_rect, dst_surface, &dst_rect); + surface_blt_to_drawable(device, filter, flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE), + src_surface, src_rect, dst_surface, dst_rect); /* Restore the color key parameters */ src_surface->CKeyFlags = oldCKeyFlags; - src_surface->SrcBltCKey = oldBltCKey; + src_surface->src_blt_color_key = old_blt_key; - surface_modify_location(dst_surface, SFLAG_INDRAWABLE, TRUE); + surface_modify_location(dst_surface, dst_surface->draw_binding, TRUE); return WINED3D_OK; } - else - { - /* Source-Less Blit to render target */ - if (flags & WINEDDBLT_COLORFILL) - { - WINED3DCOLORVALUE color; - - TRACE("Colorfill\n"); - - /* The color as given in the Blt function is in the surface format. */ - if (!surface_convert_color_to_float(dst_surface, DDBltFx->u5.dwFillColor, &color)) - return WINED3DERR_INVALIDCALL; - - return surface_color_fill(dst_surface, &dst_rect, &color); - } - } /* Default: Fall back to the generic blt. Not an error, a TRACE is enough */ TRACE("Didn't find any usable render target setup for hw blit, falling back to software\n"); @@ -5553,10 +5549,11 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(struct wined3d_surface *dst_surfa } /* GL locking is done by the caller */ -static void surface_depth_blt(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info, - GLuint texture, GLsizei w, GLsizei h, GLenum target) +static void surface_depth_blt(const struct wined3d_surface *surface, struct wined3d_context *context, + GLuint texture, GLint x, GLint y, GLsizei w, GLsizei h, GLenum target) { struct wined3d_device *device = surface->resource.device; + const struct wined3d_gl_info *gl_info = context->gl_info; GLint compare_mode = GL_NONE; struct blt_info info; GLint old_binding = 0; @@ -5573,11 +5570,11 @@ static void surface_depth_blt(struct wined3d_surface *surface, const struct wine glDepthFunc(GL_ALWAYS); glDepthMask(GL_TRUE); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - glViewport(0, surface->pow2Height - h, w, h); + glViewport(x, y, w, h); SetRect(&rect, 0, h, w, 0); surface_get_blt_info(target, &rect, surface->pow2Width, surface->pow2Height, &info); - GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB)); + context_active_texture(context, context->gl_info, 0); glGetIntegerv(info.binding, &old_binding); glBindTexture(info.bind_target, texture); if (gl_info->supported[ARB_SHADOW]) @@ -5613,12 +5610,22 @@ void surface_modify_ds_location(struct wined3d_surface *surface, { TRACE("surface %p, new location %#x, w %u, h %u.\n", surface, location, w, h); - if (location & ~SFLAG_DS_LOCATIONS) + if (location & ~(SFLAG_LOCATIONS | SFLAG_LOST)) FIXME("Invalid location (%#x) specified.\n", location); + if (((surface->flags & SFLAG_INTEXTURE) && !(location & SFLAG_INTEXTURE)) + || (!(surface->flags & SFLAG_INTEXTURE) && (location & SFLAG_INTEXTURE))) + { + if (surface->container.type == WINED3D_CONTAINER_TEXTURE) + { + TRACE("Passing to container.\n"); + wined3d_texture_set_dirty(surface->container.u.texture, TRUE); + } + } + surface->ds_current_size.cx = w; surface->ds_current_size.cy = h; - surface->flags &= ~SFLAG_DS_LOCATIONS; + surface->flags &= ~(SFLAG_LOCATIONS | SFLAG_LOST); surface->flags |= location; } @@ -5626,7 +5633,6 @@ void surface_modify_ds_location(struct wined3d_surface *surface, void surface_load_ds_location(struct wined3d_surface *surface, struct wined3d_context *context, DWORD location) { struct wined3d_device *device = surface->resource.device; - const struct wined3d_gl_info *gl_info = context->gl_info; GLsizei w, h; TRACE("surface %p, new location %#x.\n", surface, location); @@ -5660,13 +5666,32 @@ void surface_load_ds_location(struct wined3d_surface *surface, struct wined3d_co return; } - if (!(surface->flags & SFLAG_DS_LOCATIONS)) + if (surface->flags & SFLAG_LOST) + { + TRACE("Surface was discarded, no need copy data.\n"); + switch (location) + { + case SFLAG_INTEXTURE: + surface_prepare_texture(surface, context, FALSE); + break; + case SFLAG_INRB_MULTISAMPLE: + surface_prepare_rb(surface, context->gl_info, TRUE); + break; + case SFLAG_INDRAWABLE: + /* Nothing to do */ + break; + default: + FIXME("Unhandled location %#x\n", location); + } + surface->flags &= ~SFLAG_LOST; + surface->flags |= location; + surface->ds_current_size.cx = surface->resource.width; + surface->ds_current_size.cy = surface->resource.height; + return; + } + + if (!(surface->flags & SFLAG_LOCATIONS)) { - /* This mostly happens when a depth / stencil is used without being - * cleared first. In principle we could upload from sysmem, or - * explicitly clear before first usage. For the moment there don't - * appear to be a lot of applications depending on this, so a FIXME - * should do. */ FIXME("No up to date depth stencil location.\n"); surface->flags |= location; surface->ds_current_size.cx = surface->resource.width; @@ -5674,7 +5699,7 @@ void surface_load_ds_location(struct wined3d_surface *surface, struct wined3d_co return; } - if (location == SFLAG_DS_OFFSCREEN) + if (location == SFLAG_INTEXTURE) { GLint old_binding = 0; GLenum bind_target; @@ -5683,8 +5708,8 @@ void surface_load_ds_location(struct wined3d_surface *surface, struct wined3d_co * buffer, so the onscreen depth/stencil buffer is potentially smaller * than the offscreen surface. Don't overwrite the offscreen surface * with undefined data. */ - w = min(w, context->swapchain->presentParms.BackBufferWidth); - h = min(h, context->swapchain->presentParms.BackBufferHeight); + w = min(w, context->swapchain->desc.backbuffer_width); + h = min(h, context->swapchain->desc.backbuffer_height); TRACE("Copying onscreen depth buffer to depth texture.\n"); @@ -5697,7 +5722,8 @@ void surface_load_ds_location(struct wined3d_surface *surface, struct wined3d_co /* Note that we use depth_blt here as well, rather than glCopyTexImage2D * directly on the FBO texture. That's because we need to flip. */ - context_bind_fbo(context, GL_FRAMEBUFFER, NULL); + context_apply_fbo_state_blit(context, GL_FRAMEBUFFER, + context->swapchain->front_buffer, NULL, SFLAG_INDRAWABLE); if (surface->texture_target == GL_TEXTURE_RECTANGLE_ARB) { glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &old_binding); @@ -5709,7 +5735,14 @@ void surface_load_ds_location(struct wined3d_surface *surface, struct wined3d_co bind_target = GL_TEXTURE_2D; } glBindTexture(bind_target, device->depth_blt_texture); - glCopyTexImage2D(bind_target, surface->texture_level, surface->resource.format->glInternal, 0, 0, w, h, 0); + /* We use GL_DEPTH_COMPONENT instead of the surface's specific + * internal format, because the internal format might include stencil + * data. In principle we should copy stencil data as well, but unless + * the driver supports stencil export it's hard to do, and doesn't + * seem to be needed in practice. If the hardware doesn't support + * writing stencil data, the glCopyTexImage2D() call might trigger + * software fallbacks. */ + glCopyTexImage2D(bind_target, 0, GL_DEPTH_COMPONENT, 0, 0, w, h, 0); glTexParameteri(bind_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(bind_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(bind_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -5718,51 +5751,34 @@ void surface_load_ds_location(struct wined3d_surface *surface, struct wined3d_co glTexParameteri(bind_target, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE); glBindTexture(bind_target, old_binding); - /* Setup the destination */ - if (!device->depth_blt_rb) - { - gl_info->fbo_ops.glGenRenderbuffers(1, &device->depth_blt_rb); - checkGLcall("glGenRenderbuffersEXT"); - } - if (device->depth_blt_rb_w != w || device->depth_blt_rb_h != h) - { - gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, device->depth_blt_rb); - checkGLcall("glBindRenderbufferEXT"); - gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, w, h); - checkGLcall("glRenderbufferStorageEXT"); - device->depth_blt_rb_w = w; - device->depth_blt_rb_h = h; - } - - context_bind_fbo(context, GL_FRAMEBUFFER, &context->dst_fbo); - gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, device->depth_blt_rb); - checkGLcall("glFramebufferRenderbufferEXT"); - context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER, surface, FALSE); + context_apply_fbo_state_blit(context, GL_FRAMEBUFFER, + NULL, surface, SFLAG_INTEXTURE); + context_set_draw_buffer(context, GL_NONE); + glReadBuffer(GL_NONE); /* Do the actual blit */ - surface_depth_blt(surface, gl_info, device->depth_blt_texture, w, h, bind_target); + surface_depth_blt(surface, context, device->depth_blt_texture, 0, 0, w, h, bind_target); checkGLcall("depth_blt"); - if (context->current_fbo) context_bind_fbo(context, GL_FRAMEBUFFER, &context->current_fbo->id); - else context_bind_fbo(context, GL_FRAMEBUFFER, NULL); + context_invalidate_state(context, STATE_FRAMEBUFFER); LEAVE_GL(); if (wined3d_settings.strict_draw_ordering) wglFlush(); /* Flush to ensure ordering across contexts. */ } - else if (location == SFLAG_DS_ONSCREEN) + else if (location == SFLAG_INDRAWABLE) { TRACE("Copying depth texture to onscreen depth buffer.\n"); ENTER_GL(); - context_bind_fbo(context, GL_FRAMEBUFFER, NULL); - surface_depth_blt(surface, gl_info, surface->texture_name, - w, h, surface->texture_target); + context_apply_fbo_state_blit(context, GL_FRAMEBUFFER, + context->swapchain->front_buffer, NULL, SFLAG_INDRAWABLE); + surface_depth_blt(surface, context, surface->texture_name, + 0, surface->pow2Height - h, w, h, surface->texture_target); checkGLcall("depth_blt"); - if (context->current_fbo) context_bind_fbo(context, GL_FRAMEBUFFER, &context->current_fbo->id); + context_invalidate_state(context, STATE_FRAMEBUFFER); LEAVE_GL(); @@ -5778,37 +5794,27 @@ void surface_load_ds_location(struct wined3d_surface *surface, struct wined3d_co surface->ds_current_size.cy = surface->resource.height; } -void surface_modify_location(struct wined3d_surface *surface, DWORD flag, BOOL persistent) +void surface_modify_location(struct wined3d_surface *surface, DWORD location, BOOL persistent) { const struct wined3d_gl_info *gl_info = &surface->resource.device->adapter->gl_info; struct wined3d_surface *overlay; TRACE("surface %p, location %s, persistent %#x.\n", - surface, debug_surflocation(flag), persistent); + surface, debug_surflocation(location), persistent); - if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) - { - if (surface_is_offscreen(surface)) - { - /* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets. */ - if (flag & (SFLAG_INTEXTURE | SFLAG_INDRAWABLE)) flag |= (SFLAG_INTEXTURE | SFLAG_INDRAWABLE); - } - else - { - TRACE("Surface %p is an onscreen surface.\n", surface); - } - } + if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && surface_is_offscreen(surface) + && !(surface->resource.usage & WINED3DUSAGE_DEPTHSTENCIL) + && (location & SFLAG_INDRAWABLE)) + ERR("Trying to invalidate the SFLAG_INDRAWABLE location of an offscreen surface.\n"); - if (flag & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX) + if (location & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX) && gl_info->supported[EXT_TEXTURE_SRGB_DECODE]) - { - flag |= (SFLAG_INTEXTURE | SFLAG_INSRGBTEX); - } + location |= (SFLAG_INTEXTURE | SFLAG_INSRGBTEX); if (persistent) { - if (((surface->flags & SFLAG_INTEXTURE) && !(flag & SFLAG_INTEXTURE)) - || ((surface->flags & SFLAG_INSRGBTEX) && !(flag & SFLAG_INSRGBTEX))) + if (((surface->flags & SFLAG_INTEXTURE) && !(location & SFLAG_INTEXTURE)) + || ((surface->flags & SFLAG_INSRGBTEX) && !(location & SFLAG_INSRGBTEX))) { if (surface->container.type == WINED3D_CONTAINER_TEXTURE) { @@ -5817,20 +5823,20 @@ void surface_modify_location(struct wined3d_surface *surface, DWORD flag, BOOL p } } surface->flags &= ~SFLAG_LOCATIONS; - surface->flags |= flag; + surface->flags |= location; /* Redraw emulated overlays, if any */ - if (flag & SFLAG_INDRAWABLE && !list_empty(&surface->overlays)) + if (location & SFLAG_INDRAWABLE && !list_empty(&surface->overlays)) { LIST_FOR_EACH_ENTRY(overlay, &surface->overlays, struct wined3d_surface, overlay_entry) { - overlay->surface_ops->surface_draw_overlay(overlay); + surface_draw_overlay(overlay); } } } else { - if ((surface->flags & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX)) && (flag & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX))) + if ((surface->flags & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX)) && (location & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX))) { if (surface->container.type == WINED3D_CONTAINER_TEXTURE) { @@ -5838,7 +5844,7 @@ void surface_modify_location(struct wined3d_surface *surface, DWORD flag, BOOL p wined3d_texture_set_dirty(surface->container.u.texture, TRUE); } } - surface->flags &= ~flag; + surface->flags &= ~location; } if (!(surface->flags & SFLAG_LOCATIONS)) @@ -5857,6 +5863,8 @@ static DWORD resource_access_from_location(DWORD location) case SFLAG_INDRAWABLE: case SFLAG_INSRGBTEX: case SFLAG_INTEXTURE: + case SFLAG_INRB_MULTISAMPLE: + case SFLAG_INRB_RESOLVED: return WINED3D_RESOURCE_ACCESS_GPU; default: @@ -5865,65 +5873,356 @@ static DWORD resource_access_from_location(DWORD location) } } -HRESULT surface_load_location(struct wined3d_surface *surface, DWORD flag, const RECT *rect) +static void surface_load_sysmem(struct wined3d_surface *surface, + const struct wined3d_gl_info *gl_info, const RECT *rect) +{ + surface_prepare_system_memory(surface); + + if (surface->flags & (SFLAG_INRB_MULTISAMPLE | SFLAG_INRB_RESOLVED)) + surface_load_location(surface, SFLAG_INTEXTURE, NULL); + + /* Download the surface to system memory. */ + if (surface->flags & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX)) + { + struct wined3d_device *device = surface->resource.device; + struct wined3d_context *context; + + /* TODO: Use already acquired context when possible. */ + context = context_acquire(device, NULL); + + surface_bind_and_dirtify(surface, context, !(surface->flags & SFLAG_INTEXTURE)); + surface_download_data(surface, gl_info); + + context_release(context); + + return; + } + + if (surface->flags & SFLAG_INDRAWABLE) + { + read_from_framebuffer(surface, rect, surface->resource.allocatedMemory, + wined3d_surface_get_pitch(surface)); + return; + } + + FIXME("Can't load surface %p with location flags %#x into sysmem.\n", + surface, surface->flags & SFLAG_LOCATIONS); +} + +static HRESULT surface_load_drawable(struct wined3d_surface *surface, + const struct wined3d_gl_info *gl_info, const RECT *rect) +{ + struct wined3d_device *device = surface->resource.device; + struct wined3d_format format; + CONVERT_TYPES convert; + UINT byte_count; + BYTE *mem; + + if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && surface_is_offscreen(surface)) + { + ERR("Trying to load offscreen surface into SFLAG_INDRAWABLE.\n"); + return WINED3DERR_INVALIDCALL; + } + + if (wined3d_settings.rendertargetlock_mode == RTL_READTEX) + surface_load_location(surface, SFLAG_INTEXTURE, NULL); + + if (surface->flags & SFLAG_INTEXTURE) + { + RECT r; + + surface_get_rect(surface, rect, &r); + surface_blt_to_drawable(device, WINED3D_TEXF_POINT, FALSE, surface, &r, surface, &r); + + return WINED3D_OK; + } + + if ((surface->flags & SFLAG_LOCATIONS) == SFLAG_INSRGBTEX) + { + /* This needs colorspace conversion from sRGB to RGB. We take the slow + * path through sysmem. */ + surface_load_location(surface, SFLAG_INSYSMEM, rect); + } + + d3dfmt_get_conv(surface, FALSE, FALSE, &format, &convert); + + /* Don't use PBOs for converted surfaces. During PBO conversion we look at + * SFLAG_CONVERTED but it isn't set (yet) in all cases where it is getting + * called. */ + if ((convert != NO_CONVERSION) && (surface->flags & SFLAG_PBO)) + { + struct wined3d_context *context; + + TRACE("Removing the pbo attached to surface %p.\n", surface); + + /* TODO: Use already acquired context when possible. */ + context = context_acquire(device, NULL); + + surface_remove_pbo(surface, gl_info); + + context_release(context); + } + + if ((convert != NO_CONVERSION) && surface->resource.allocatedMemory) + { + UINT height = surface->resource.height; + UINT width = surface->resource.width; + UINT src_pitch, dst_pitch; + + byte_count = format.conv_byte_count; + src_pitch = wined3d_surface_get_pitch(surface); + + /* Stick to the alignment for the converted surface too, makes it + * easier to load the surface. */ + dst_pitch = width * byte_count; + dst_pitch = (dst_pitch + device->surface_alignment - 1) & ~(device->surface_alignment - 1); + + if (!(mem = HeapAlloc(GetProcessHeap(), 0, dst_pitch * height))) + { + ERR("Out of memory (%u).\n", dst_pitch * height); + return E_OUTOFMEMORY; + } + + d3dfmt_convert_surface(surface->resource.allocatedMemory, mem, + src_pitch, width, height, dst_pitch, convert, surface); + + surface->flags |= SFLAG_CONVERTED; + } + else + { + surface->flags &= ~SFLAG_CONVERTED; + mem = surface->resource.allocatedMemory; + byte_count = format.byte_count; + } + + flush_to_framebuffer_drawpixels(surface, rect, format.glFormat, format.glType, byte_count, mem); + + /* Don't delete PBO memory. */ + if ((mem != surface->resource.allocatedMemory) && !(surface->flags & SFLAG_PBO)) + HeapFree(GetProcessHeap(), 0, mem); + + return WINED3D_OK; +} + +static HRESULT surface_load_texture(struct wined3d_surface *surface, + const struct wined3d_gl_info *gl_info, const RECT *rect, BOOL srgb) +{ + RECT src_rect = {0, 0, surface->resource.width, surface->resource.height}; + struct wined3d_device *device = surface->resource.device; + struct wined3d_context *context; + UINT width, src_pitch, dst_pitch; + struct wined3d_bo_address data; + struct wined3d_format format; + POINT dst_point = {0, 0}; + CONVERT_TYPES convert; + BYTE *mem; + + if (wined3d_settings.offscreen_rendering_mode != ORM_FBO + && surface_is_offscreen(surface) + && (surface->flags & SFLAG_INDRAWABLE)) + { + surface_load_fb_texture(surface, srgb); + + return WINED3D_OK; + } + + if (surface->flags & (SFLAG_INSRGBTEX | SFLAG_INTEXTURE) + && (surface->resource.format->flags & WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB) + && fbo_blit_supported(gl_info, WINED3D_BLIT_OP_COLOR_BLIT, + NULL, surface->resource.usage, surface->resource.pool, surface->resource.format, + NULL, surface->resource.usage, surface->resource.pool, surface->resource.format)) + { + if (srgb) + surface_blt_fbo(device, WINED3D_TEXF_POINT, surface, SFLAG_INTEXTURE, + &src_rect, surface, SFLAG_INSRGBTEX, &src_rect); + else + surface_blt_fbo(device, WINED3D_TEXF_POINT, surface, SFLAG_INSRGBTEX, + &src_rect, surface, SFLAG_INTEXTURE, &src_rect); + + return WINED3D_OK; + } + + if (surface->flags & (SFLAG_INRB_MULTISAMPLE | SFLAG_INRB_RESOLVED) + && (!srgb || (surface->resource.format->flags & WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB)) + && fbo_blit_supported(gl_info, WINED3D_BLIT_OP_COLOR_BLIT, + NULL, surface->resource.usage, surface->resource.pool, surface->resource.format, + NULL, surface->resource.usage, surface->resource.pool, surface->resource.format)) + { + DWORD src_location = surface->flags & SFLAG_INRB_RESOLVED ? SFLAG_INRB_RESOLVED : SFLAG_INRB_MULTISAMPLE; + DWORD dst_location = srgb ? SFLAG_INSRGBTEX : SFLAG_INTEXTURE; + RECT rect = {0, 0, surface->resource.width, surface->resource.height}; + + surface_blt_fbo(device, WINED3D_TEXF_POINT, surface, src_location, + &rect, surface, dst_location, &rect); + + return WINED3D_OK; + } + + /* Upload from system memory */ + + d3dfmt_get_conv(surface, TRUE /* We need color keying */, + TRUE /* We will use textures */, &format, &convert); + + if (srgb) + { + if ((surface->flags & (SFLAG_INTEXTURE | SFLAG_INSYSMEM)) == SFLAG_INTEXTURE) + { + /* Performance warning... */ + FIXME("Downloading RGB surface %p to reload it as sRGB.\n", surface); + surface_load_location(surface, SFLAG_INSYSMEM, rect); + } + } + else + { + if ((surface->flags & (SFLAG_INSRGBTEX | SFLAG_INSYSMEM)) == SFLAG_INSRGBTEX) + { + /* Performance warning... */ + FIXME("Downloading sRGB surface %p to reload it as RGB.\n", surface); + surface_load_location(surface, SFLAG_INSYSMEM, rect); + } + } + + if (!(surface->flags & SFLAG_INSYSMEM)) + { + WARN("Trying to load a texture from sysmem, but SFLAG_INSYSMEM is not set.\n"); + /* Lets hope we get it from somewhere... */ + surface_load_location(surface, SFLAG_INSYSMEM, rect); + } + + /* TODO: Use already acquired context when possible. */ + context = context_acquire(device, NULL); + + surface_prepare_texture(surface, context, srgb); + surface_bind_and_dirtify(surface, context, srgb); + + if (surface->CKeyFlags & WINEDDSD_CKSRCBLT) + { + surface->flags |= SFLAG_GLCKEY; + surface->gl_color_key = surface->src_blt_color_key; + } + else surface->flags &= ~SFLAG_GLCKEY; + + width = surface->resource.width; + src_pitch = wined3d_surface_get_pitch(surface); + + /* Don't use PBOs for converted surfaces. During PBO conversion we look at + * SFLAG_CONVERTED but it isn't set (yet) in all cases it is getting + * called. */ + if ((convert != NO_CONVERSION || format.convert) && (surface->flags & SFLAG_PBO)) + { + TRACE("Removing the pbo attached to surface %p.\n", surface); + surface_remove_pbo(surface, gl_info); + } + + if (format.convert) + { + /* This code is entered for texture formats which need a fixup. */ + UINT height = surface->resource.height; + + /* Stick to the alignment for the converted surface too, makes it easier to load the surface */ + dst_pitch = width * format.conv_byte_count; + dst_pitch = (dst_pitch + device->surface_alignment - 1) & ~(device->surface_alignment - 1); + + if (!(mem = HeapAlloc(GetProcessHeap(), 0, dst_pitch * height))) + { + ERR("Out of memory (%u).\n", dst_pitch * height); + context_release(context); + return E_OUTOFMEMORY; + } + format.convert(surface->resource.allocatedMemory, mem, src_pitch, width, height); + format.byte_count = format.conv_byte_count; + src_pitch = dst_pitch; + } + else if (convert != NO_CONVERSION && surface->resource.allocatedMemory) + { + /* This code is only entered for color keying fixups */ + UINT height = surface->resource.height; + + /* Stick to the alignment for the converted surface too, makes it easier to load the surface */ + dst_pitch = width * format.conv_byte_count; + dst_pitch = (dst_pitch + device->surface_alignment - 1) & ~(device->surface_alignment - 1); + + if (!(mem = HeapAlloc(GetProcessHeap(), 0, dst_pitch * height))) + { + ERR("Out of memory (%u).\n", dst_pitch * height); + context_release(context); + return E_OUTOFMEMORY; + } + d3dfmt_convert_surface(surface->resource.allocatedMemory, mem, src_pitch, + width, height, dst_pitch, convert, surface); + format.byte_count = format.conv_byte_count; + src_pitch = dst_pitch; + } + else + { + mem = surface->resource.allocatedMemory; + } + + data.buffer_object = surface->flags & SFLAG_PBO ? surface->pbo : 0; + data.addr = mem; + surface_upload_data(surface, gl_info, &format, &src_rect, src_pitch, &dst_point, srgb, &data); + + context_release(context); + + /* Don't delete PBO memory. */ + if ((mem != surface->resource.allocatedMemory) && !(surface->flags & SFLAG_PBO)) + HeapFree(GetProcessHeap(), 0, mem); + + return WINED3D_OK; +} + +static void surface_multisample_resolve(struct wined3d_surface *surface) +{ + RECT rect = {0, 0, surface->resource.width, surface->resource.height}; + + if (!(surface->flags & SFLAG_INRB_MULTISAMPLE)) + ERR("Trying to resolve multisampled surface %p, but location SFLAG_INRB_MULTISAMPLE not current.\n", surface); + + surface_blt_fbo(surface->resource.device, WINED3D_TEXF_POINT, + surface, SFLAG_INRB_MULTISAMPLE, &rect, surface, SFLAG_INRB_RESOLVED, &rect); +} + +HRESULT surface_load_location(struct wined3d_surface *surface, DWORD location, const RECT *rect) { struct wined3d_device *device = surface->resource.device; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; - BOOL drawable_read_ok = surface_is_offscreen(surface); - struct wined3d_format format; - CONVERT_TYPES convert; - int width, pitch, outpitch; - BYTE *mem; - BOOL in_fbo = FALSE; + HRESULT hr; - TRACE("surface %p, location %s, rect %s.\n", surface, debug_surflocation(flag), wine_dbgstr_rect(rect)); + TRACE("surface %p, location %s, rect %s.\n", surface, debug_surflocation(location), wine_dbgstr_rect(rect)); if (surface->resource.usage & WINED3DUSAGE_DEPTHSTENCIL) { - if (flag == SFLAG_INTEXTURE) + if (location == SFLAG_INTEXTURE) { struct wined3d_context *context = context_acquire(device, NULL); - surface_load_ds_location(surface, context, SFLAG_DS_OFFSCREEN); + surface_load_ds_location(surface, context, location); context_release(context); return WINED3D_OK; } else { - FIXME("Unimplemented location %s for depth/stencil buffers.\n", debug_surflocation(flag)); + FIXME("Unimplemented location %s for depth/stencil buffers.\n", debug_surflocation(location)); return WINED3DERR_INVALIDCALL; } } - if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) - { - if (surface_is_offscreen(surface)) - { - /* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets. - * Prefer SFLAG_INTEXTURE. */ - if (flag == SFLAG_INDRAWABLE) flag = SFLAG_INTEXTURE; - drawable_read_ok = FALSE; - in_fbo = TRUE; - } - else - { - TRACE("Surface %p is an onscreen surface.\n", surface); - } - } + if (location == SFLAG_INSRGBTEX && gl_info->supported[EXT_TEXTURE_SRGB_DECODE]) + location = SFLAG_INTEXTURE; - if (flag == SFLAG_INSRGBTEX && gl_info->supported[EXT_TEXTURE_SRGB_DECODE]) + if (surface->flags & location) { - flag = SFLAG_INTEXTURE; - } + TRACE("Location already up to date.\n"); + + if (location == SFLAG_INSYSMEM && !(surface->flags & SFLAG_PBO) + && surface_need_pbo(surface, gl_info)) + surface_load_pbo(surface, gl_info); - if (surface->flags & flag) - { - TRACE("Location already up to date\n"); return WINED3D_OK; } if (WARN_ON(d3d_surface)) { - DWORD required_access = resource_access_from_location(flag); + DWORD required_access = resource_access_from_location(location); if ((surface->resource.access_flags & required_access) != required_access) WARN("Operation requires %#x access, but surface only has %#x.\n", required_access, surface->resource.access_flags); @@ -5936,259 +6235,40 @@ HRESULT surface_load_location(struct wined3d_surface *surface, DWORD flag, const return WINED3DERR_DEVICELOST; } - if (flag == SFLAG_INSYSMEM) + switch (location) { - surface_prepare_system_memory(surface); + case SFLAG_INSYSMEM: + surface_load_sysmem(surface, gl_info, rect); + break; - /* Download the surface to system memory */ - if (surface->flags & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX)) - { - struct wined3d_context *context = NULL; + case SFLAG_INDRAWABLE: + if (FAILED(hr = surface_load_drawable(surface, gl_info, rect))) + return hr; + break; - if (!device->isInDraw) context = context_acquire(device, NULL); + case SFLAG_INRB_RESOLVED: + surface_multisample_resolve(surface); + break; - surface_bind_and_dirtify(surface, gl_info, !(surface->flags & SFLAG_INTEXTURE)); - surface_download_data(surface, gl_info); + case SFLAG_INTEXTURE: + case SFLAG_INSRGBTEX: + if (FAILED(hr = surface_load_texture(surface, gl_info, rect, location == SFLAG_INSRGBTEX))) + return hr; + break; - if (context) context_release(context); - } - else - { - /* Note: It might be faster to download into a texture first. */ - read_from_framebuffer(surface, rect, surface->resource.allocatedMemory, - wined3d_surface_get_pitch(surface)); - } - } - else if (flag == SFLAG_INDRAWABLE) - { - if (wined3d_settings.rendertargetlock_mode == RTL_READTEX) - surface_load_location(surface, SFLAG_INTEXTURE, NULL); - - if (surface->flags & SFLAG_INTEXTURE) - { - RECT r; - - surface_get_rect(surface, rect, &r); - surface_blt_to_drawable(device, WINED3DTEXF_POINT, FALSE, surface, &r, surface, &r); - } - else - { - int byte_count; - if ((surface->flags & SFLAG_LOCATIONS) == SFLAG_INSRGBTEX) - { - /* This needs a shader to convert the srgb data sampled from the GL texture into RGB - * values, otherwise we get incorrect values in the target. For now go the slow way - * via a system memory copy - */ - surface_load_location(surface, SFLAG_INSYSMEM, rect); - } - - d3dfmt_get_conv(surface, FALSE /* We need color keying */, - FALSE /* We won't use textures */, &format, &convert); - - /* The width is in 'length' not in bytes */ - width = surface->resource.width; - pitch = wined3d_surface_get_pitch(surface); - - /* Don't use PBOs for converted surfaces. During PBO conversion we look at SFLAG_CONVERTED - * but it isn't set (yet) in all cases it is getting called. */ - if ((convert != NO_CONVERSION) && (surface->flags & SFLAG_PBO)) - { - struct wined3d_context *context = NULL; - - TRACE("Removing the pbo attached to surface %p.\n", surface); - - if (!device->isInDraw) context = context_acquire(device, NULL); - surface_remove_pbo(surface, gl_info); - if (context) context_release(context); - } - - if ((convert != NO_CONVERSION) && surface->resource.allocatedMemory) - { - int height = surface->resource.height; - byte_count = format.conv_byte_count; - - /* Stick to the alignment for the converted surface too, makes it easier to load the surface */ - outpitch = width * byte_count; - outpitch = (outpitch + device->surface_alignment - 1) & ~(device->surface_alignment - 1); - - mem = HeapAlloc(GetProcessHeap(), 0, outpitch * height); - if(!mem) { - ERR("Out of memory %d, %d!\n", outpitch, height); - return WINED3DERR_OUTOFVIDEOMEMORY; - } - d3dfmt_convert_surface(surface->resource.allocatedMemory, mem, pitch, - width, height, outpitch, convert, surface); - - surface->flags |= SFLAG_CONVERTED; - } - else - { - surface->flags &= ~SFLAG_CONVERTED; - mem = surface->resource.allocatedMemory; - byte_count = format.byte_count; - } - - flush_to_framebuffer_drawpixels(surface, rect, format.glFormat, format.glType, byte_count, mem); - - /* Don't delete PBO memory */ - if ((mem != surface->resource.allocatedMemory) && !(surface->flags & SFLAG_PBO)) - HeapFree(GetProcessHeap(), 0, mem); - } - } - else /* if(flag & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX)) */ - { - const DWORD attach_flags = WINED3DFMT_FLAG_FBO_ATTACHABLE | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB; - - if (drawable_read_ok && (surface->flags & SFLAG_INDRAWABLE)) - { - read_from_framebuffer_texture(surface, flag == SFLAG_INSRGBTEX); - } - else if (surface->flags & (SFLAG_INSRGBTEX | SFLAG_INTEXTURE) - && (surface->resource.format->flags & attach_flags) == attach_flags - && fbo_blit_supported(gl_info, WINED3D_BLIT_OP_COLOR_BLIT, - NULL, surface->resource.usage, surface->resource.pool, surface->resource.format, - NULL, surface->resource.usage, surface->resource.pool, surface->resource.format)) - { - DWORD src_location = flag == SFLAG_INSRGBTEX ? SFLAG_INTEXTURE : SFLAG_INSRGBTEX; - RECT rect = {0, 0, surface->resource.width, surface->resource.height}; - - surface_blt_fbo(surface->resource.device, WINED3DTEXF_POINT, - surface, src_location, &rect, surface, flag, &rect); - } - else - { - /* Upload from system memory */ - BOOL srgb = flag == SFLAG_INSRGBTEX; - struct wined3d_context *context = NULL; - - d3dfmt_get_conv(surface, TRUE /* We need color keying */, - TRUE /* We will use textures */, &format, &convert); - - if (srgb) - { - if ((surface->flags & (SFLAG_INTEXTURE | SFLAG_INSYSMEM)) == SFLAG_INTEXTURE) - { - /* Performance warning... */ - FIXME("Downloading RGB surface %p to reload it as sRGB.\n", surface); - surface_load_location(surface, SFLAG_INSYSMEM, rect); - } - } - else - { - if ((surface->flags & (SFLAG_INSRGBTEX | SFLAG_INSYSMEM)) == SFLAG_INSRGBTEX) - { - /* Performance warning... */ - FIXME("Downloading sRGB surface %p to reload it as RGB.\n", surface); - surface_load_location(surface, SFLAG_INSYSMEM, rect); - } - } - if (!(surface->flags & SFLAG_INSYSMEM)) - { - WARN("Trying to load a texture from sysmem, but SFLAG_INSYSMEM is not set.\n"); - /* Lets hope we get it from somewhere... */ - surface_load_location(surface, SFLAG_INSYSMEM, rect); - } - - if (!device->isInDraw) context = context_acquire(device, NULL); - - surface_prepare_texture(surface, gl_info, srgb); - surface_bind_and_dirtify(surface, gl_info, srgb); - - if (surface->CKeyFlags & WINEDDSD_CKSRCBLT) - { - surface->flags |= SFLAG_GLCKEY; - surface->glCKey = surface->SrcBltCKey; - } - else surface->flags &= ~SFLAG_GLCKEY; - - /* The width is in 'length' not in bytes */ - width = surface->resource.width; - pitch = wined3d_surface_get_pitch(surface); - - /* Don't use PBOs for converted surfaces. During PBO conversion we look at SFLAG_CONVERTED - * but it isn't set (yet) in all cases it is getting called. */ - if ((convert != NO_CONVERSION || format.convert) && (surface->flags & SFLAG_PBO)) - { - TRACE("Removing the pbo attached to surface %p.\n", surface); - surface_remove_pbo(surface, gl_info); - } - - if (format.convert) - { - /* This code is entered for texture formats which need a fixup. */ - UINT height = surface->resource.height; - - /* Stick to the alignment for the converted surface too, makes it easier to load the surface */ - outpitch = width * format.conv_byte_count; - outpitch = (outpitch + device->surface_alignment - 1) & ~(device->surface_alignment - 1); - - mem = HeapAlloc(GetProcessHeap(), 0, outpitch * height); - if(!mem) { - ERR("Out of memory %d, %d!\n", outpitch, height); - if (context) context_release(context); - return WINED3DERR_OUTOFVIDEOMEMORY; - } - format.convert(surface->resource.allocatedMemory, mem, pitch, width, height); - } - else if (convert != NO_CONVERSION && surface->resource.allocatedMemory) - { - /* This code is only entered for color keying fixups */ - UINT height = surface->resource.height; - - /* Stick to the alignment for the converted surface too, makes it easier to load the surface */ - outpitch = width * format.conv_byte_count; - outpitch = (outpitch + device->surface_alignment - 1) & ~(device->surface_alignment - 1); - - mem = HeapAlloc(GetProcessHeap(), 0, outpitch * height); - if(!mem) { - ERR("Out of memory %d, %d!\n", outpitch, height); - if (context) context_release(context); - return WINED3DERR_OUTOFVIDEOMEMORY; - } - d3dfmt_convert_surface(surface->resource.allocatedMemory, mem, pitch, - width, height, outpitch, convert, surface); - } - else - { - mem = surface->resource.allocatedMemory; - } - - /* Make sure the correct pitch is used */ - ENTER_GL(); - glPixelStorei(GL_UNPACK_ROW_LENGTH, width); - LEAVE_GL(); - - if (mem || (surface->flags & SFLAG_PBO)) - surface_upload_data(surface, gl_info, &format, srgb, mem); - - /* Restore the default pitch */ - ENTER_GL(); - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - LEAVE_GL(); - - if (context) context_release(context); - - /* Don't delete PBO memory */ - if ((mem != surface->resource.allocatedMemory) && !(surface->flags & SFLAG_PBO)) - HeapFree(GetProcessHeap(), 0, mem); - } + default: + ERR("Don't know how to handle location %#x.\n", location); + break; } if (!rect) { - surface->flags |= flag; + surface->flags |= location; - if (flag != SFLAG_INSYSMEM && (surface->flags & SFLAG_INSYSMEM)) + if (location != SFLAG_INSYSMEM && (surface->flags & SFLAG_INSYSMEM)) surface_evict_sysmem(surface); } - if (in_fbo && (surface->flags & (SFLAG_INTEXTURE | SFLAG_INDRAWABLE))) - { - /* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets. */ - surface->flags |= (SFLAG_INTEXTURE | SFLAG_INDRAWABLE); - } - if (surface->flags & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX) && gl_info->supported[EXT_TEXTURE_SRGB_DECODE]) { @@ -6198,7 +6278,7 @@ HRESULT surface_load_location(struct wined3d_surface *surface, DWORD flag, const return WINED3D_OK; } -BOOL surface_is_offscreen(struct wined3d_surface *surface) +BOOL surface_is_offscreen(const struct wined3d_surface *surface) { struct wined3d_swapchain *swapchain = surface->container.u.swapchain; @@ -6219,7 +6299,7 @@ static void ffp_blit_free(struct wined3d_device *device) { } /* This function is used in case of 8bit paletted textures using GL_EXT_paletted_texture */ /* Context activation is done by the caller. */ -static void ffp_blit_p8_upload_palette(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info) +static void ffp_blit_p8_upload_palette(const struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info) { BYTE table[256][4]; BOOL colorkey_active = (surface->CKeyFlags & WINEDDSD_CKSRCBLT) ? TRUE : FALSE; @@ -6233,15 +6313,16 @@ static void ffp_blit_p8_upload_palette(struct wined3d_surface *surface, const st } /* Context activation is done by the caller. */ -static HRESULT ffp_blit_set(void *blit_priv, const struct wined3d_gl_info *gl_info, struct wined3d_surface *surface) +static HRESULT ffp_blit_set(void *blit_priv, struct wined3d_context *context, const struct wined3d_surface *surface) { enum complex_fixup fixup = get_complex_fixup(surface->resource.format->color_fixup); /* When EXT_PALETTED_TEXTURE is around, palette conversion is done by the GPU * else the surface is converted in software at upload time in LoadLocation. */ - if(fixup == COMPLEX_FIXUP_P8 && gl_info->supported[EXT_PALETTED_TEXTURE]) - ffp_blit_p8_upload_palette(surface, gl_info); + if (!(surface->flags & SFLAG_CONVERTED) && fixup == COMPLEX_FIXUP_P8 + && context->gl_info->supported[EXT_PALETTED_TEXTURE]) + ffp_blit_p8_upload_palette(surface, context->gl_info); ENTER_GL(); glEnable(surface->texture_target); @@ -6270,14 +6351,17 @@ static void ffp_blit_unset(const struct wined3d_gl_info *gl_info) } static BOOL ffp_blit_supported(const struct wined3d_gl_info *gl_info, enum wined3d_blit_op blit_op, - const RECT *src_rect, DWORD src_usage, WINED3DPOOL src_pool, const struct wined3d_format *src_format, - const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool, const struct wined3d_format *dst_format) + const RECT *src_rect, DWORD src_usage, enum wined3d_pool src_pool, const struct wined3d_format *src_format, + const RECT *dst_rect, DWORD dst_usage, enum wined3d_pool dst_pool, const struct wined3d_format *dst_format) { enum complex_fixup src_fixup; switch (blit_op) { case WINED3D_BLIT_OP_COLOR_BLIT: + if (src_pool == WINED3D_POOL_SYSTEM_MEM || dst_pool == WINED3D_POOL_SYSTEM_MEM) + return FALSE; + src_fixup = get_complex_fixup(src_format->color_fixup); if (TRACE_ON(d3d_surface) && TRACE_ON(d3d)) { @@ -6308,12 +6392,23 @@ static BOOL ffp_blit_supported(const struct wined3d_gl_info *gl_info, enum wined return FALSE; case WINED3D_BLIT_OP_COLOR_FILL: - if (!(dst_usage & WINED3DUSAGE_RENDERTARGET)) + if (dst_pool == WINED3D_POOL_SYSTEM_MEM) + return FALSE; + + if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) + { + if (!((dst_format->flags & WINED3DFMT_FLAG_FBO_ATTACHABLE) || (dst_usage & WINED3DUSAGE_RENDERTARGET))) + return FALSE; + } + else if (!(dst_usage & WINED3DUSAGE_RENDERTARGET)) { TRACE("Color fill not supported\n"); return FALSE; } + /* FIXME: We should reject color fills on formats with fixups, + * but this would break P8 color fills for example. */ + return TRUE; case WINED3D_BLIT_OP_DEPTH_FILL: @@ -6327,11 +6422,12 @@ static BOOL ffp_blit_supported(const struct wined3d_gl_info *gl_info, enum wined /* Do not call while under the GL lock. */ static HRESULT ffp_blit_color_fill(struct wined3d_device *device, struct wined3d_surface *dst_surface, - const RECT *dst_rect, const WINED3DCOLORVALUE *color) + const RECT *dst_rect, const struct wined3d_color *color) { const RECT draw_rect = {0, 0, dst_surface->resource.width, dst_surface->resource.height}; + struct wined3d_fb_state fb = {&dst_surface, NULL}; - return device_clear_render_targets(device, 1, &dst_surface, NULL, + return device_clear_render_targets(device, 1, &fb, 1, dst_rect, &draw_rect, WINED3DCLEAR_TARGET, color, 0.0f, 0); } @@ -6340,8 +6436,9 @@ static HRESULT ffp_blit_depth_fill(struct wined3d_device *device, struct wined3d_surface *surface, const RECT *rect, float depth) { const RECT draw_rect = {0, 0, surface->resource.width, surface->resource.height}; + struct wined3d_fb_state fb = {NULL, surface}; - return device_clear_render_targets(device, 0, NULL, surface, + return device_clear_render_targets(device, 0, &fb, 1, rect, &draw_rect, WINED3DCLEAR_ZBUFFER, 0, depth, 0); } @@ -6366,7 +6463,7 @@ static void cpu_blit_free(struct wined3d_device *device) } /* Context activation is done by the caller. */ -static HRESULT cpu_blit_set(void *blit_priv, const struct wined3d_gl_info *gl_info, struct wined3d_surface *surface) +static HRESULT cpu_blit_set(void *blit_priv, struct wined3d_context *context, const struct wined3d_surface *surface) { return WINED3D_OK; } @@ -6377,8 +6474,8 @@ static void cpu_blit_unset(const struct wined3d_gl_info *gl_info) } static BOOL cpu_blit_supported(const struct wined3d_gl_info *gl_info, enum wined3d_blit_op blit_op, - const RECT *src_rect, DWORD src_usage, WINED3DPOOL src_pool, const struct wined3d_format *src_format, - const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool, const struct wined3d_format *dst_format) + const RECT *src_rect, DWORD src_usage, enum wined3d_pool src_pool, const struct wined3d_format *src_format, + const RECT *dst_rect, DWORD dst_usage, enum wined3d_pool dst_pool, const struct wined3d_format *dst_format) { if (blit_op == WINED3D_BLIT_OP_COLOR_FILL) { @@ -6388,14 +6485,116 @@ static BOOL cpu_blit_supported(const struct wined3d_gl_info *gl_info, enum wined return FALSE; } +static HRESULT surface_cpu_blt_compressed(const BYTE *src_data, BYTE *dst_data, + UINT src_pitch, UINT dst_pitch, UINT update_w, UINT update_h, + const struct wined3d_format *format, DWORD flags, const WINEDDBLTFX *fx) +{ + UINT row_block_count; + const BYTE *src_row; + BYTE *dst_row; + UINT x, y; + + src_row = src_data; + dst_row = dst_data; + + row_block_count = (update_w + format->block_width - 1) / format->block_width; + + if (!flags) + { + for (y = 0; y < update_h; y += format->block_height) + { + memcpy(dst_row, src_row, row_block_count * format->block_byte_count); + src_row += src_pitch; + dst_row += dst_pitch; + } + + return WINED3D_OK; + } + + if (flags == WINEDDBLT_DDFX && fx->dwDDFX == WINEDDBLTFX_MIRRORUPDOWN) + { + src_row += (((update_h / format->block_height) - 1) * src_pitch); + + switch (format->id) + { + case WINED3DFMT_DXT1: + for (y = 0; y < update_h; y += format->block_height) + { + struct block + { + WORD color[2]; + BYTE control_row[4]; + }; + + const struct block *s = (const struct block *)src_row; + struct block *d = (struct block *)dst_row; + + for (x = 0; x < row_block_count; ++x) + { + d[x].color[0] = s[x].color[0]; + d[x].color[1] = s[x].color[1]; + d[x].control_row[0] = s[x].control_row[3]; + d[x].control_row[1] = s[x].control_row[2]; + d[x].control_row[2] = s[x].control_row[1]; + d[x].control_row[3] = s[x].control_row[0]; + } + src_row -= src_pitch; + dst_row += dst_pitch; + } + return WINED3D_OK; + + case WINED3DFMT_DXT3: + for (y = 0; y < update_h; y += format->block_height) + { + struct block + { + WORD alpha_row[4]; + WORD color[2]; + BYTE control_row[4]; + }; + + const struct block *s = (const struct block *)src_row; + struct block *d = (struct block *)dst_row; + + for (x = 0; x < row_block_count; ++x) + { + d[x].alpha_row[0] = s[x].alpha_row[3]; + d[x].alpha_row[1] = s[x].alpha_row[2]; + d[x].alpha_row[2] = s[x].alpha_row[1]; + d[x].alpha_row[3] = s[x].alpha_row[0]; + d[x].color[0] = s[x].color[0]; + d[x].color[1] = s[x].color[1]; + d[x].control_row[0] = s[x].control_row[3]; + d[x].control_row[1] = s[x].control_row[2]; + d[x].control_row[2] = s[x].control_row[1]; + d[x].control_row[3] = s[x].control_row[0]; + } + src_row -= src_pitch; + dst_row += dst_pitch; + } + return WINED3D_OK; + + default: + FIXME("Compressed flip not implemented for format %s.\n", + debug_d3dformat(format->id)); + return E_NOTIMPL; + } + } + + FIXME("Unsupported blit on compressed surface (format %s, flags %#x, DDFX %#x).\n", + debug_d3dformat(format->id), flags, flags & WINEDDBLT_DDFX ? fx->dwDDFX : 0); + + return E_NOTIMPL; +} + static HRESULT surface_cpu_blt(struct wined3d_surface *dst_surface, const RECT *dst_rect, struct wined3d_surface *src_surface, const RECT *src_rect, DWORD flags, - const WINEDDBLTFX *fx, WINED3DTEXTUREFILTERTYPE filter) + const WINEDDBLTFX *fx, enum wined3d_texture_filter_type filter) { int bpp, srcheight, srcwidth, dstheight, dstwidth, width; const struct wined3d_format *src_format, *dst_format; struct wined3d_surface *orig_src = src_surface; - WINED3DLOCKED_RECT dlock, slock; + struct wined3d_mapped_rect dst_map, src_map; HRESULT hr = WINED3D_OK; const BYTE *sbuf; RECT xdst,xsrc; @@ -6406,156 +6605,83 @@ static HRESULT surface_cpu_blt(struct wined3d_surface *dst_surface, const RECT * dst_surface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect), flags, fx, debug_d3dtexturefiltertype(filter)); - if ((dst_surface->flags & SFLAG_LOCKED) || (src_surface && (src_surface->flags & SFLAG_LOCKED))) - { - WARN("Surface is busy, returning WINEDDERR_SURFACEBUSY\n"); - return WINEDDERR_SURFACEBUSY; - } + xsrc = *src_rect; - /* First check for the validity of source / destination rectangles. - * This was verified using a test application and by MSDN. */ - if (src_rect) + if (!src_surface) { - if (src_surface) + RECT full_rect; + + full_rect.left = 0; + full_rect.top = 0; + full_rect.right = dst_surface->resource.width; + full_rect.bottom = dst_surface->resource.height; + IntersectRect(&xdst, &full_rect, dst_rect); + } + else + { + BOOL clip_horiz, clip_vert; + + xdst = *dst_rect; + clip_horiz = xdst.left < 0 || xdst.right > (int)dst_surface->resource.width; + clip_vert = xdst.top < 0 || xdst.bottom > (int)dst_surface->resource.height; + + if (clip_vert || clip_horiz) { - if (src_rect->right < src_rect->left || src_rect->bottom < src_rect->top - || src_rect->left > src_surface->resource.width || src_rect->left < 0 - || src_rect->top > src_surface->resource.height || src_rect->top < 0 - || src_rect->right > src_surface->resource.width || src_rect->right < 0 - || src_rect->bottom > src_surface->resource.height || src_rect->bottom < 0) + /* Now check if this is a special case or not... */ + if ((flags & WINEDDBLT_DDFX) + || (clip_horiz && xdst.right - xdst.left != xsrc.right - xsrc.left) + || (clip_vert && xdst.bottom - xdst.top != xsrc.bottom - xsrc.top)) { - WARN("Application gave us bad source rectangle for Blt.\n"); - return WINEDDERR_INVALIDRECT; + WARN("Out of screen rectangle in special case. Not handled right now.\n"); + return WINED3D_OK; } - if (!src_rect->right || !src_rect->bottom - || src_rect->left == (int)src_surface->resource.width - || src_rect->top == (int)src_surface->resource.height) + if (clip_horiz) { - TRACE("Nothing to be done.\n"); + if (xdst.left < 0) + { + xsrc.left -= xdst.left; + xdst.left = 0; + } + if (xdst.right > dst_surface->resource.width) + { + xsrc.right -= (xdst.right - (int)dst_surface->resource.width); + xdst.right = (int)dst_surface->resource.width; + } + } + + if (clip_vert) + { + if (xdst.top < 0) + { + xsrc.top -= xdst.top; + xdst.top = 0; + } + if (xdst.bottom > dst_surface->resource.height) + { + xsrc.bottom -= (xdst.bottom - (int)dst_surface->resource.height); + xdst.bottom = (int)dst_surface->resource.height; + } + } + + /* And check if after clipping something is still to be done... */ + if ((xdst.right <= 0) || (xdst.bottom <= 0) + || (xdst.left >= (int)dst_surface->resource.width) + || (xdst.top >= (int)dst_surface->resource.height) + || (xsrc.right <= 0) || (xsrc.bottom <= 0) + || (xsrc.left >= (int)src_surface->resource.width) + || (xsrc.top >= (int)src_surface->resource.height)) + { + TRACE("Nothing to be done after clipping.\n"); return WINED3D_OK; } } - - xsrc = *src_rect; - } - else if (src_surface) - { - xsrc.left = 0; - xsrc.top = 0; - xsrc.right = src_surface->resource.width; - xsrc.bottom = src_surface->resource.height; - } - else - { - memset(&xsrc, 0, sizeof(xsrc)); - } - - if (dst_rect) - { - /* For the Destination rect, it can be out of bounds on the condition - * that a clipper is set for the given surface. */ - if (!dst_surface->clipper && (dst_rect->right < dst_rect->left || dst_rect->bottom < dst_rect->top - || dst_rect->left > dst_surface->resource.width || dst_rect->left < 0 - || dst_rect->top > dst_surface->resource.height || dst_rect->top < 0 - || dst_rect->right > dst_surface->resource.width || dst_rect->right < 0 - || dst_rect->bottom > dst_surface->resource.height || dst_rect->bottom < 0)) - { - WARN("Application gave us bad destination rectangle for Blt without a clipper set.\n"); - return WINEDDERR_INVALIDRECT; - } - - if (dst_rect->right <= 0 || dst_rect->bottom <= 0 - || dst_rect->left >= (int)dst_surface->resource.width - || dst_rect->top >= (int)dst_surface->resource.height) - { - TRACE("Nothing to be done.\n"); - return WINED3D_OK; - } - - if (!src_surface) - { - RECT full_rect; - - full_rect.left = 0; - full_rect.top = 0; - full_rect.right = dst_surface->resource.width; - full_rect.bottom = dst_surface->resource.height; - IntersectRect(&xdst, &full_rect, dst_rect); - } - else - { - BOOL clip_horiz, clip_vert; - - xdst = *dst_rect; - clip_horiz = xdst.left < 0 || xdst.right > (int)dst_surface->resource.width; - clip_vert = xdst.top < 0 || xdst.bottom > (int)dst_surface->resource.height; - - if (clip_vert || clip_horiz) - { - /* Now check if this is a special case or not... */ - if ((flags & WINEDDBLT_DDFX) - || (clip_horiz && xdst.right - xdst.left != xsrc.right - xsrc.left) - || (clip_vert && xdst.bottom - xdst.top != xsrc.bottom - xsrc.top)) - { - WARN("Out of screen rectangle in special case. Not handled right now.\n"); - return WINED3D_OK; - } - - if (clip_horiz) - { - if (xdst.left < 0) - { - xsrc.left -= xdst.left; - xdst.left = 0; - } - if (xdst.right > dst_surface->resource.width) - { - xsrc.right -= (xdst.right - (int)dst_surface->resource.width); - xdst.right = (int)dst_surface->resource.width; - } - } - - if (clip_vert) - { - if (xdst.top < 0) - { - xsrc.top -= xdst.top; - xdst.top = 0; - } - if (xdst.bottom > dst_surface->resource.height) - { - xsrc.bottom -= (xdst.bottom - (int)dst_surface->resource.height); - xdst.bottom = (int)dst_surface->resource.height; - } - } - - /* And check if after clipping something is still to be done... */ - if ((xdst.right <= 0) || (xdst.bottom <= 0) - || (xdst.left >= (int)dst_surface->resource.width) - || (xdst.top >= (int)dst_surface->resource.height) - || (xsrc.right <= 0) || (xsrc.bottom <= 0) - || (xsrc.left >= (int)src_surface->resource.width) - || (xsrc.top >= (int)src_surface->resource.height)) - { - TRACE("Nothing to be done after clipping.\n"); - return WINED3D_OK; - } - } - } - } - else - { - xdst.left = 0; - xdst.top = 0; - xdst.right = dst_surface->resource.width; - xdst.bottom = dst_surface->resource.height; } if (src_surface == dst_surface) { - wined3d_surface_map(dst_surface, &dlock, NULL, 0); - slock = dlock; + wined3d_surface_map(dst_surface, &dst_map, NULL, 0); + src_map = dst_map; src_format = dst_surface->resource.format; dst_format = src_format; } @@ -6574,7 +6700,7 @@ static HRESULT surface_cpu_blt(struct wined3d_surface *dst_surface, const RECT * goto release; } } - wined3d_surface_map(src_surface, &slock, NULL, WINED3DLOCK_READONLY); + wined3d_surface_map(src_surface, &src_map, NULL, WINED3DLOCK_READONLY); src_format = src_surface->resource.format; } else @@ -6582,20 +6708,9 @@ static HRESULT surface_cpu_blt(struct wined3d_surface *dst_surface, const RECT * src_format = dst_format; } if (dst_rect) - wined3d_surface_map(dst_surface, &dlock, &xdst, 0); + wined3d_surface_map(dst_surface, &dst_map, &xdst, 0); else - wined3d_surface_map(dst_surface, &dlock, NULL, 0); - } - - if (!fx || !(fx->dwDDFX)) flags &= ~WINEDDBLT_DDFX; - - if (src_format->flags & dst_format->flags & WINED3DFMT_FLAG_FOURCC) - { - if (!dst_rect || src_surface == dst_surface) - { - memcpy(dlock.pBits, slock.pBits, dst_surface->resource.size); - goto release; - } + wined3d_surface_map(dst_surface, &dst_map, NULL, 0); } bpp = dst_surface->resource.format->byte_count; @@ -6605,37 +6720,46 @@ static HRESULT surface_cpu_blt(struct wined3d_surface *dst_surface, const RECT * dstwidth = xdst.right - xdst.left; width = (xdst.right - xdst.left) * bpp; - if (dst_rect && src_surface != dst_surface) - dbuf = dlock.pBits; - else - dbuf = (BYTE*)dlock.pBits+(xdst.top*dlock.Pitch)+(xdst.left*bpp); + if (src_format->flags & dst_format->flags & WINED3DFMT_FLAG_BLOCKS) + { + TRACE("%s -> %s copy.\n", debug_d3dformat(src_format->id), debug_d3dformat(dst_format->id)); - if (flags & WINEDDBLT_WAIT) - { - flags &= ~WINEDDBLT_WAIT; - } - if (flags & WINEDDBLT_ASYNC) - { - static BOOL displayed = FALSE; - if (!displayed) - FIXME("Can't handle WINEDDBLT_ASYNC flag right now.\n"); - displayed = TRUE; - flags &= ~WINEDDBLT_ASYNC; - } - if (flags & WINEDDBLT_DONOTWAIT) - { - /* WINEDDBLT_DONOTWAIT appeared in DX7 */ - static BOOL displayed = FALSE; - if (!displayed) - FIXME("Can't handle WINEDDBLT_DONOTWAIT flag right now.\n"); - displayed = TRUE; - flags &= ~WINEDDBLT_DONOTWAIT; + if (src_surface == dst_surface) + { + FIXME("Only plain blits supported on compressed surfaces.\n"); + hr = E_NOTIMPL; + goto release; + } + + if (srcheight != dstheight || srcwidth != dstwidth) + { + WARN("Stretching not supported on compressed surfaces.\n"); + hr = WINED3DERR_INVALIDCALL; + goto release; + } + + if (srcwidth & (src_format->block_width - 1) || srcheight & (src_format->block_height - 1)) + { + WARN("Rectangle not block-aligned.\n"); + hr = WINED3DERR_INVALIDCALL; + goto release; + } + + hr = surface_cpu_blt_compressed(src_map.data, dst_map.data, + src_map.row_pitch, dst_map.row_pitch, dstwidth, dstheight, + src_format, flags, fx); + goto release; } + if (dst_rect && src_surface != dst_surface) + dbuf = dst_map.data; + else + dbuf = (BYTE *)dst_map.data + (xdst.top * dst_map.row_pitch) + (xdst.left * bpp); + /* First, all the 'source-less' blits */ if (flags & WINEDDBLT_COLORFILL) { - hr = _Blt_ColorFill(dbuf, dstwidth, dstheight, bpp, dlock.Pitch, fx->u5.dwFillColor); + hr = _Blt_ColorFill(dbuf, dstwidth, dstheight, bpp, dst_map.row_pitch, fx->u5.dwFillColor); flags &= ~WINEDDBLT_COLORFILL; } @@ -6649,12 +6773,12 @@ static HRESULT surface_cpu_blt(struct wined3d_surface *dst_surface, const RECT * switch (fx->dwROP) { case BLACKNESS: - hr = _Blt_ColorFill(dbuf,dstwidth,dstheight,bpp,dlock.Pitch,0); + hr = _Blt_ColorFill(dbuf, dstwidth, dstheight, bpp, dst_map.row_pitch, 0); break; case 0xAA0029: /* No-op */ break; case WHITENESS: - hr = _Blt_ColorFill(dbuf,dstwidth,dstheight,bpp,dlock.Pitch,~0); + hr = _Blt_ColorFill(dbuf, dstwidth, dstheight, bpp, dst_map.row_pitch, ~0U); break; case SRCCOPY: /* Well, we do that below? */ break; @@ -6677,14 +6801,14 @@ static HRESULT surface_cpu_blt(struct wined3d_surface *dst_surface, const RECT * if (!dstwidth || !dstheight) /* Hmm... stupid program? */ goto release; - if (filter != WINED3DTEXF_NONE && filter != WINED3DTEXF_POINT + if (filter != WINED3D_TEXF_NONE && filter != WINED3D_TEXF_POINT && (srcwidth != dstwidth || srcheight != dstheight)) { /* Can happen when d3d9 apps do a StretchRect() call which isn't handled in GL. */ FIXME("Filter %s not supported in software blit.\n", debug_d3dtexturefiltertype(filter)); } - sbase = (BYTE*)slock.pBits+(xsrc.top*slock.Pitch)+xsrc.left*bpp; + sbase = (BYTE *)src_map.data + (xsrc.top * src_map.row_pitch) + xsrc.left * bpp; xinc = (srcwidth << 16) / dstwidth; yinc = (srcheight << 16) / dstheight; @@ -6707,19 +6831,19 @@ static HRESULT surface_cpu_blt(struct wined3d_surface *dst_surface, const RECT * for (y = 0; y < dstheight; ++y) { memcpy(dbuf, sbuf, width); - sbuf += slock.Pitch; - dbuf += dlock.Pitch; + sbuf += src_map.row_pitch; + dbuf += dst_map.row_pitch; } } else if (xdst.top > xsrc.top) { /* Copy from bottom upwards. */ - sbuf += (slock.Pitch*dstheight); - dbuf += (dlock.Pitch*dstheight); + sbuf += src_map.row_pitch * dstheight; + dbuf += dst_map.row_pitch * dstheight; for (y = 0; y < dstheight; ++y) { - sbuf -= slock.Pitch; - dbuf -= dlock.Pitch; + sbuf -= src_map.row_pitch; + dbuf -= dst_map.row_pitch; memcpy(dbuf, sbuf, width); } } @@ -6729,8 +6853,8 @@ static HRESULT surface_cpu_blt(struct wined3d_surface *dst_surface, const RECT * for (y = 0; y < dstheight; ++y) { memmove(dbuf, sbuf, width); - sbuf += slock.Pitch; - dbuf += dlock.Pitch; + sbuf += src_map.row_pitch; + dbuf += dst_map.row_pitch; } } } @@ -6739,9 +6863,9 @@ static HRESULT surface_cpu_blt(struct wined3d_surface *dst_surface, const RECT * /* Stretching in y direction only. */ for (y = sy = 0; y < dstheight; ++y, sy += yinc) { - sbuf = sbase + (sy >> 16) * slock.Pitch; + sbuf = sbase + (sy >> 16) * src_map.row_pitch; memcpy(dbuf, sbuf, width); - dbuf += dlock.Pitch; + dbuf += dst_map.row_pitch; } } } @@ -6751,13 +6875,13 @@ static HRESULT surface_cpu_blt(struct wined3d_surface *dst_surface, const RECT * int last_sy = -1; for (y = sy = 0; y < dstheight; ++y, sy += yinc) { - sbuf = sbase + (sy >> 16) * slock.Pitch; + sbuf = sbase + (sy >> 16) * src_map.row_pitch; if ((sy >> 16) == (last_sy >> 16)) { /* This source row is the same as last source row - * Copy the already stretched row. */ - memcpy(dbuf, dbuf - dlock.Pitch, width); + memcpy(dbuf, dbuf - dst_map.row_pitch, width); } else { @@ -6804,14 +6928,14 @@ do { \ } #undef STRETCH_ROW } - dbuf += dlock.Pitch; + dbuf += dst_map.row_pitch; last_sy = sy; } } } else { - LONG dstyinc = dlock.Pitch, dstxinc = bpp; + LONG dstyinc = dst_map.row_pitch, dstxinc = bpp; DWORD keylow = 0xFFFFFFFF, keyhigh = 0, keymask = 0xFFFFFFFF; DWORD destkeylow = 0x0, destkeyhigh = 0xFFFFFFFF, destkeymask = 0xFFFFFFFF; if (flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYDEST | WINEDDBLT_KEYSRCOVERRIDE | WINEDDBLT_KEYDESTOVERRIDE)) @@ -6819,25 +6943,25 @@ do { \ /* The color keying flags are checked for correctness in ddraw */ if (flags & WINEDDBLT_KEYSRC) { - keylow = src_surface->SrcBltCKey.dwColorSpaceLowValue; - keyhigh = src_surface->SrcBltCKey.dwColorSpaceHighValue; + keylow = src_surface->src_blt_color_key.color_space_low_value; + keyhigh = src_surface->src_blt_color_key.color_space_high_value; } else if (flags & WINEDDBLT_KEYSRCOVERRIDE) { - keylow = fx->ddckSrcColorkey.dwColorSpaceLowValue; - keyhigh = fx->ddckSrcColorkey.dwColorSpaceHighValue; + keylow = fx->ddckSrcColorkey.color_space_low_value; + keyhigh = fx->ddckSrcColorkey.color_space_high_value; } if (flags & WINEDDBLT_KEYDEST) { /* Destination color keys are taken from the source surface! */ - destkeylow = src_surface->DestBltCKey.dwColorSpaceLowValue; - destkeyhigh = src_surface->DestBltCKey.dwColorSpaceHighValue; + destkeylow = src_surface->dst_blt_color_key.color_space_low_value; + destkeyhigh = src_surface->dst_blt_color_key.color_space_high_value; } else if (flags & WINEDDBLT_KEYDESTOVERRIDE) { - destkeylow = fx->ddckDestColorkey.dwColorSpaceLowValue; - destkeyhigh = fx->ddckDestColorkey.dwColorSpaceHighValue; + destkeylow = fx->ddckDestColorkey.color_space_low_value; + destkeyhigh = fx->ddckDestColorkey.color_space_high_value; } if (bpp == 1) @@ -6859,7 +6983,7 @@ do { \ LONG tmpxy; dTopLeft = dbuf; dTopRight = dbuf + ((dstwidth - 1) * bpp); - dBottomLeft = dTopLeft + ((dstheight - 1) * dlock.Pitch); + dBottomLeft = dTopLeft + ((dstheight - 1) * dst_map.row_pitch); dBottomRight = dBottomLeft + ((dstwidth - 1) * bpp); if (fx->dwDDFX & WINEDDBLTFX_ARITHSTRETCHY) @@ -6942,7 +7066,7 @@ do { \ type *d = (type *)dbuf, *dx, tmp; \ for (y = sy = 0; y < dstheight; ++y, sy += yinc) \ { \ - s = (const type *)(sbase + (sy >> 16) * slock.Pitch); \ + s = (const type *)(sbase + (sy >> 16) * src_map.row_pitch); \ dx = d; \ for (x = sx = 0; x < dstwidth; ++x, sx += xinc) \ { \ @@ -6975,7 +7099,7 @@ do { \ BYTE *d = dbuf, *dx; for (y = sy = 0; y < dstheight; ++y, sy += yinc) { - sbuf = sbase + (sy >> 16) * slock.Pitch; + sbuf = sbase + (sy >> 16) * src_map.row_pitch; dx = d; for (x = sx = 0; x < dstwidth; ++x, sx+= xinc) { @@ -7023,289 +7147,18 @@ release: return hr; } -static HRESULT surface_cpu_bltfast(struct wined3d_surface *dst_surface, DWORD dst_x, DWORD dst_y, - struct wined3d_surface *src_surface, const RECT *src_rect, DWORD trans) -{ - const struct wined3d_format *src_format, *dst_format; - RECT lock_src, lock_dst, lock_union; - WINED3DLOCKED_RECT dlock, slock; - HRESULT hr = WINED3D_OK; - int bpp, w, h, x, y; - const BYTE *sbuf; - BYTE *dbuf; - RECT rsrc2; - - TRACE("dst_surface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n", - dst_surface, dst_x, dst_y, src_surface, wine_dbgstr_rect(src_rect), trans); - - if ((dst_surface->flags & SFLAG_LOCKED) || (src_surface->flags & SFLAG_LOCKED)) - { - WARN(" Surface is busy, returning DDERR_SURFACEBUSY\n"); - return WINEDDERR_SURFACEBUSY; - } - - if (!src_rect) - { - WARN("src_rect is NULL!\n"); - rsrc2.left = 0; - rsrc2.top = 0; - rsrc2.right = src_surface->resource.width; - rsrc2.bottom = src_surface->resource.height; - src_rect = &rsrc2; - } - - /* Check source rect for validity. Copied from normal Blt. Fixes Baldur's Gate. */ - if ((src_rect->bottom > src_surface->resource.height) || (src_rect->bottom < 0) - || (src_rect->top > src_surface->resource.height) || (src_rect->top < 0) - || (src_rect->left > src_surface->resource.width) || (src_rect->left < 0) - || (src_rect->right > src_surface->resource.width) || (src_rect->right < 0) - || (src_rect->right < src_rect->left) || (src_rect->bottom < src_rect->top)) - { - WARN("Application gave us bad source rectangle for BltFast.\n"); - return WINEDDERR_INVALIDRECT; - } - - h = src_rect->bottom - src_rect->top; - if (h > dst_surface->resource.height - dst_y) - h = dst_surface->resource.height - dst_y; - if (h > src_surface->resource.height - src_rect->top) - h = src_surface->resource.height - src_rect->top; - if (h <= 0) - return WINEDDERR_INVALIDRECT; - - w = src_rect->right - src_rect->left; - if (w > dst_surface->resource.width - dst_x) - w = dst_surface->resource.width - dst_x; - if (w > src_surface->resource.width - src_rect->left) - w = src_surface->resource.width - src_rect->left; - if (w <= 0) - return WINEDDERR_INVALIDRECT; - - /* Now compute the locking rectangle... */ - lock_src.left = src_rect->left; - lock_src.top = src_rect->top; - lock_src.right = lock_src.left + w; - lock_src.bottom = lock_src.top + h; - - lock_dst.left = dst_x; - lock_dst.top = dst_y; - lock_dst.right = dst_x + w; - lock_dst.bottom = dst_y + h; - - bpp = dst_surface->resource.format->byte_count; - - /* We need to lock the surfaces, or we won't get refreshes when done. */ - if (src_surface == dst_surface) - { - int pitch; - - UnionRect(&lock_union, &lock_src, &lock_dst); - - /* Lock the union of the two rectangles. */ - hr = wined3d_surface_map(dst_surface, &dlock, &lock_union, 0); - if (FAILED(hr)) - goto error; - - pitch = dlock.Pitch; - slock.Pitch = dlock.Pitch; - - /* Since slock was originally copied from this surface's description, we can just reuse it. */ - sbuf = dst_surface->resource.allocatedMemory + lock_src.top * pitch + lock_src.left * bpp; - dbuf = dst_surface->resource.allocatedMemory + lock_dst.top * pitch + lock_dst.left * bpp; - src_format = src_surface->resource.format; - dst_format = src_format; - } - else - { - hr = wined3d_surface_map(src_surface, &slock, &lock_src, WINED3DLOCK_READONLY); - if (FAILED(hr)) - goto error; - hr = wined3d_surface_map(dst_surface, &dlock, &lock_dst, 0); - if (FAILED(hr)) - goto error; - - sbuf = slock.pBits; - dbuf = dlock.pBits; - TRACE("Dst is at %p, Src is at %p.\n", dbuf, sbuf); - - src_format = src_surface->resource.format; - dst_format = dst_surface->resource.format; - } - - /* Handle compressed surfaces first... */ - if (src_format->flags & dst_format->flags & WINED3DFMT_FLAG_COMPRESSED) - { - UINT row_block_count; - - TRACE("compressed -> compressed copy\n"); - if (trans) - FIXME("trans arg not supported when a compressed surface is involved\n"); - if (dst_x || dst_y) - FIXME("offset for destination surface is not supported\n"); - if (src_surface->resource.format->id != dst_surface->resource.format->id) - { - FIXME("compressed -> compressed copy only supported for the same type of surface\n"); - hr = WINED3DERR_WRONGTEXTUREFORMAT; - goto error; - } - - row_block_count = (w + dst_format->block_width - 1) / dst_format->block_width; - for (y = 0; y < h; y += dst_format->block_height) - { - memcpy(dbuf, sbuf, row_block_count * dst_format->block_byte_count); - dbuf += dlock.Pitch; - sbuf += slock.Pitch; - } - - goto error; - } - if ((src_format->flags & WINED3DFMT_FLAG_COMPRESSED) && !(dst_format->flags & WINED3DFMT_FLAG_COMPRESSED)) - { - /* TODO: Use the libtxc_dxtn.so shared library to do software - * decompression. */ - ERR("Software decompression not supported.\n"); - goto error; - } - - if (trans & (WINEDDBLTFAST_SRCCOLORKEY | WINEDDBLTFAST_DESTCOLORKEY)) - { - DWORD keylow, keyhigh; - DWORD mask = src_surface->resource.format->red_mask - | src_surface->resource.format->green_mask - | src_surface->resource.format->blue_mask; - - /* For some 8-bit formats like L8 and P8 color masks don't make sense */ - if (!mask && bpp == 1) - mask = 0xff; - - TRACE("Color keyed copy.\n"); - if (trans & WINEDDBLTFAST_SRCCOLORKEY) - { - keylow = src_surface->SrcBltCKey.dwColorSpaceLowValue; - keyhigh = src_surface->SrcBltCKey.dwColorSpaceHighValue; - } - else - { - /* I'm not sure if this is correct. */ - FIXME("WINEDDBLTFAST_DESTCOLORKEY not fully supported yet.\n"); - keylow = dst_surface->DestBltCKey.dwColorSpaceLowValue; - keyhigh = dst_surface->DestBltCKey.dwColorSpaceHighValue; - } - -#define COPYBOX_COLORKEY(type) \ -do { \ - const type *s = (const type *)sbuf; \ - type *d = (type *)dbuf; \ - type tmp; \ - for (y = 0; y < h; y++) \ - { \ - for (x = 0; x < w; x++) \ - { \ - tmp = s[x]; \ - if ((tmp & mask) < keylow || (tmp & mask) > keyhigh) d[x] = tmp; \ - } \ - s = (const type *)((const BYTE *)s + slock.Pitch); \ - d = (type *)((BYTE *)d + dlock.Pitch); \ - } \ -} while(0) - - switch (bpp) - { - case 1: - COPYBOX_COLORKEY(BYTE); - break; - case 2: - COPYBOX_COLORKEY(WORD); - break; - case 4: - COPYBOX_COLORKEY(DWORD); - break; - case 3: - { - const BYTE *s; - DWORD tmp; - BYTE *d; - s = sbuf; - d = dbuf; - for (y = 0; y < h; ++y) - { - for (x = 0; x < w * 3; x += 3) - { - tmp = (DWORD)s[x] + ((DWORD)s[x + 1] << 8) + ((DWORD)s[x + 2] << 16); - if (tmp < keylow || tmp > keyhigh) - { - d[x + 0] = s[x + 0]; - d[x + 1] = s[x + 1]; - d[x + 2] = s[x + 2]; - } - } - s += slock.Pitch; - d += dlock.Pitch; - } - break; - } - default: - FIXME("Source color key blitting not supported for bpp %u.\n", bpp * 8); - hr = WINED3DERR_NOTAVAILABLE; - goto error; - } -#undef COPYBOX_COLORKEY - TRACE("Copy done.\n"); - } - else - { - int width = w * bpp; - INT sbufpitch, dbufpitch; - - TRACE("No color key copy.\n"); - /* Handle overlapping surfaces. */ - if (sbuf < dbuf) - { - sbuf += (h - 1) * slock.Pitch; - dbuf += (h - 1) * dlock.Pitch; - sbufpitch = -slock.Pitch; - dbufpitch = -dlock.Pitch; - } - else - { - sbufpitch = slock.Pitch; - dbufpitch = dlock.Pitch; - } - for (y = 0; y < h; ++y) - { - /* This is pretty easy, a line for line memcpy. */ - memmove(dbuf, sbuf, width); - sbuf += sbufpitch; - dbuf += dbufpitch; - } - TRACE("Copy done.\n"); - } - -error: - if (src_surface == dst_surface) - { - wined3d_surface_unmap(dst_surface); - } - else - { - wined3d_surface_unmap(dst_surface); - wined3d_surface_unmap(src_surface); - } - - return hr; -} - /* Do not call while under the GL lock. */ static HRESULT cpu_blit_color_fill(struct wined3d_device *device, struct wined3d_surface *dst_surface, - const RECT *dst_rect, const WINED3DCOLORVALUE *color) + const RECT *dst_rect, const struct wined3d_color *color) { + static const RECT src_rect; WINEDDBLTFX BltFx; memset(&BltFx, 0, sizeof(BltFx)); BltFx.dwSize = sizeof(BltFx); - BltFx.u5.dwFillColor = wined3d_format_convert_from_float(dst_surface->resource.format, color); - return wined3d_surface_blt(dst_surface, dst_rect, NULL, NULL, - WINEDDBLT_COLORFILL, &BltFx, WINED3DTEXF_POINT); + BltFx.u5.dwFillColor = wined3d_format_convert_from_float(dst_surface, color); + return surface_cpu_blt(dst_surface, dst_rect, NULL, &src_rect, + WINEDDBLT_COLORFILL, &BltFx, WINED3D_TEXF_POINT); } /* Do not call while under the GL lock. */ @@ -7327,12 +7180,13 @@ const struct blit_shader cpu_blit = { }; static HRESULT surface_init(struct wined3d_surface *surface, WINED3DSURFTYPE surface_type, UINT alignment, - UINT width, UINT height, UINT level, BOOL lockable, BOOL discard, WINED3DMULTISAMPLE_TYPE multisample_type, + UINT width, UINT height, UINT level, enum wined3d_multisample_type multisample_type, UINT multisample_quality, struct wined3d_device *device, DWORD usage, enum wined3d_format_id format_id, - WINED3DPOOL pool, void *parent, const struct wined3d_parent_ops *parent_ops) + enum wined3d_pool pool, DWORD flags, void *parent, const struct wined3d_parent_ops *parent_ops) { const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; const struct wined3d_format *format = wined3d_get_format(gl_info, format_id); + BOOL lockable = flags & WINED3D_SURFACE_MAPPABLE; unsigned int resource_size; HRESULT hr; @@ -7348,7 +7202,7 @@ static HRESULT surface_init(struct wined3d_surface *surface, WINED3DSURFTYPE sur * Levels need to be checked too, since they all affect what can be done. */ switch (pool) { - case WINED3DPOOL_SCRATCH: + case WINED3D_POOL_SCRATCH: if (!lockable) { FIXME("Called with a pool of SCRATCH and a lockable of FALSE " @@ -7357,17 +7211,17 @@ static HRESULT surface_init(struct wined3d_surface *surface, WINED3DSURFTYPE sur } break; - case WINED3DPOOL_SYSTEMMEM: + case WINED3D_POOL_SYSTEM_MEM: if (!lockable) FIXME("Called with a pool of SYSTEMMEM and a lockable of FALSE, this is acceptable but unexpected.\n"); break; - case WINED3DPOOL_MANAGED: + case WINED3D_POOL_MANAGED: if (usage & WINED3DUSAGE_DYNAMIC) FIXME("Called with a pool of MANAGED and a usage of DYNAMIC which are mutually exclusive.\n"); break; - case WINED3DPOOL_DEFAULT: + case WINED3D_POOL_DEFAULT: if (lockable && !(usage & (WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_RENDERTARGET | WINED3DUSAGE_DEPTHSTENCIL))) WARN("Creating a lockable surface with a POOL of DEFAULT, that doesn't specify DYNAMIC usage.\n"); break; @@ -7377,7 +7231,7 @@ static HRESULT surface_init(struct wined3d_surface *surface, WINED3DSURFTYPE sur break; }; - if (usage & WINED3DUSAGE_RENDERTARGET && pool != WINED3DPOOL_DEFAULT) + if (usage & WINED3DUSAGE_RENDERTARGET && pool != WINED3D_POOL_DEFAULT) FIXME("Trying to create a render target that isn't in the default pool.\n"); /* FIXME: Check that the format is supported by the device. */ @@ -7403,7 +7257,7 @@ static HRESULT surface_init(struct wined3d_surface *surface, WINED3DSURFTYPE sur return WINED3DERR_INVALIDCALL; } - hr = resource_init(&surface->resource, device, WINED3DRTYPE_SURFACE, format, + hr = resource_init(&surface->resource, device, WINED3D_RTYPE_SURFACE, format, multisample_type, multisample_quality, usage, pool, width, height, 1, resource_size, parent, parent_ops, &surface_resource_ops); if (FAILED(hr)) @@ -7420,8 +7274,10 @@ static HRESULT surface_init(struct wined3d_surface *surface, WINED3DSURFTYPE sur /* Flags */ surface->flags = SFLAG_NORMCOORD; /* Default to normalized coords. */ - if (discard) + if (flags & WINED3D_SURFACE_DISCARD) surface->flags |= SFLAG_DISCARD; + if (flags & WINED3D_SURFACE_PIN_SYSMEM) + surface->flags |= SFLAG_PIN_SYSMEM; if (lockable || format_id == WINED3DFMT_D16_LOCKABLE) surface->flags |= SFLAG_LOCKABLE; /* I'm not sure if this qualifies as a hack or as an optimization. It @@ -7446,26 +7302,37 @@ static HRESULT surface_init(struct wined3d_surface *surface, WINED3DSURFTYPE sur if (FAILED(hr)) { ERR("Private setup failed, returning %#x\n", hr); - surface->surface_ops->surface_cleanup(surface); + surface_cleanup(surface); return hr; } + /* Similar to lockable rendertargets above, creating the DIB section + * during surface initialization prevents the sysmem pointer from changing + * after a wined3d_surface_getdc() call. */ + if ((usage & WINED3DUSAGE_OWNDC) && !surface->hDC + && SUCCEEDED(surface_create_dib_section(surface))) + { + HeapFree(GetProcessHeap(), 0, surface->resource.heapMemory); + surface->resource.heapMemory = NULL; + surface->resource.allocatedMemory = surface->dib.bitmap_data; + } + return hr; } HRESULT CDECL wined3d_surface_create(struct wined3d_device *device, UINT width, UINT height, - enum wined3d_format_id format_id, BOOL lockable, BOOL discard, UINT level, DWORD usage, WINED3DPOOL pool, - WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, WINED3DSURFTYPE surface_type, - void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_surface **surface) + enum wined3d_format_id format_id, UINT level, DWORD usage, enum wined3d_pool pool, + enum wined3d_multisample_type multisample_type, DWORD multisample_quality, WINED3DSURFTYPE surface_type, + DWORD flags, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_surface **surface) { struct wined3d_surface *object; HRESULT hr; - TRACE("device %p, width %u, height %u, format %s, lockable %#x, discard %#x, level %u\n", - device, width, height, debug_d3dformat(format_id), lockable, discard, level); + TRACE("device %p, width %u, height %u, format %s, level %u\n", + device, width, height, debug_d3dformat(format_id), level); TRACE("surface %p, usage %s (%#x), pool %s, multisample_type %#x, multisample_quality %u\n", surface, debug_d3dusage(usage), usage, debug_d3dpool(pool), multisample_type, multisample_quality); - TRACE("surface_type %#x, parent %p, parent_ops %p.\n", surface_type, parent, parent_ops); + TRACE("surface_type %#x, flags %#x, parent %p, parent_ops %p.\n", surface_type, flags, parent, parent_ops); if (surface_type == SURFACE_OPENGL && !device->adapter) { @@ -7480,8 +7347,8 @@ HRESULT CDECL wined3d_surface_create(struct wined3d_device *device, UINT width, return WINED3DERR_OUTOFVIDEOMEMORY; } - hr = surface_init(object, surface_type, device->surface_alignment, width, height, level, lockable, - discard, multisample_type, multisample_quality, device, usage, format_id, pool, parent, parent_ops); + hr = surface_init(object, surface_type, device->surface_alignment, width, height, level, + multisample_type, multisample_quality, device, usage, format_id, pool, flags, parent, parent_ops); if (FAILED(hr)) { WARN("Failed to initialize surface, returning %#x.\n", hr); diff --git a/reactos/dll/directx/wine/wined3d/swapchain.c b/reactos/dll/directx/wine/wined3d/swapchain.c index 0b32eca0a91..de31fd3b52e 100644 --- a/reactos/dll/directx/wine/wined3d/swapchain.c +++ b/reactos/dll/directx/wine/wined3d/swapchain.c @@ -29,7 +29,7 @@ WINE_DECLARE_DEBUG_CHANNEL(fps); /* Do not call while under the GL lock. */ static void swapchain_cleanup(struct wined3d_swapchain *swapchain) { - WINED3DDISPLAYMODE mode; + struct wined3d_display_mode mode; UINT i; TRACE("Destroying swapchain %p.\n", swapchain); @@ -48,7 +48,7 @@ static void swapchain_cleanup(struct wined3d_swapchain *swapchain) if (swapchain->back_buffers) { - i = swapchain->presentParms.BackBufferCount; + i = swapchain->desc.backbuffer_count; while (i--) { @@ -72,12 +72,12 @@ static void swapchain_cleanup(struct wined3d_swapchain *swapchain) * desktop resolution. In case of d3d7 this will be a NOP because ddraw * sets the resolution before starting up Direct3D, thus orig_width and * orig_height will be equal to the modes in the presentation params. */ - if (!swapchain->presentParms.Windowed && swapchain->presentParms.AutoRestoreDisplayMode) + if (!swapchain->desc.windowed && swapchain->desc.auto_restore_display_mode) { - mode.Width = swapchain->orig_width; - mode.Height = swapchain->orig_height; - mode.RefreshRate = 0; - mode.Format = swapchain->orig_fmt; + mode.width = swapchain->orig_width; + mode.height = swapchain->orig_height; + mode.refresh_rate = 0; + mode.format_id = swapchain->orig_fmt; wined3d_device_set_display_mode(swapchain->device, 0, &mode); } @@ -154,20 +154,27 @@ HRESULT CDECL wined3d_swapchain_present(struct wined3d_swapchain *swapchain, HRESULT CDECL wined3d_swapchain_get_front_buffer_data(const struct wined3d_swapchain *swapchain, struct wined3d_surface *dst_surface) { - POINT offset = {0, 0}; + struct wined3d_surface *src_surface; + RECT src_rect, dst_rect; TRACE("swapchain %p, dst_surface %p.\n", swapchain, dst_surface); - if (swapchain->presentParms.Windowed) - MapWindowPoints(swapchain->win_handle, NULL, &offset, 1); + src_surface = swapchain->front_buffer; + SetRect(&src_rect, 0, 0, src_surface->resource.width, src_surface->resource.height); + dst_rect = src_rect; - wined3d_surface_bltfast(dst_surface, offset.x, offset.y, swapchain->front_buffer, NULL, 0); + if (swapchain->desc.windowed) + { + MapWindowPoints(swapchain->win_handle, NULL, (POINT *)&dst_rect, 2); + FIXME("Using destination rect %s in windowed mode, this is likely wrong.\n", + wine_dbgstr_rect(&dst_rect)); + } - return WINED3D_OK; + return wined3d_surface_blt(dst_surface, &dst_rect, src_surface, &src_rect, 0, NULL, WINED3D_TEXF_POINT); } HRESULT CDECL wined3d_swapchain_get_back_buffer(const struct wined3d_swapchain *swapchain, - UINT back_buffer_idx, WINED3DBACKBUFFER_TYPE type, struct wined3d_surface **back_buffer) + UINT back_buffer_idx, enum wined3d_backbuffer_type type, struct wined3d_surface **back_buffer) { TRACE("swapchain %p, back_buffer_idx %u, type %#x, back_buffer %p.\n", swapchain, back_buffer_idx, type, back_buffer); @@ -177,7 +184,7 @@ HRESULT CDECL wined3d_swapchain_get_back_buffer(const struct wined3d_swapchain * * NULL). We need this because this function is called from * stateblock_init_default_state() to get the default scissorrect * dimensions. */ - if (!swapchain->back_buffers || back_buffer_idx >= swapchain->presentParms.BackBufferCount) + if (!swapchain->back_buffers || back_buffer_idx >= swapchain->desc.backbuffer_count) { WARN("Invalid back buffer index.\n"); /* Native d3d9 doesn't set NULL here, just as wine's d3d9. But set it @@ -196,7 +203,7 @@ HRESULT CDECL wined3d_swapchain_get_back_buffer(const struct wined3d_swapchain * } HRESULT CDECL wined3d_swapchain_get_raster_status(const struct wined3d_swapchain *swapchain, - WINED3DRASTER_STATUS *raster_status) + struct wined3d_raster_status *raster_status) { static BOOL warned; /* No OpenGL equivalent */ @@ -214,7 +221,8 @@ HRESULT CDECL wined3d_swapchain_get_raster_status(const struct wined3d_swapchain return WINED3DERR_INVALIDCALL; } -HRESULT CDECL wined3d_swapchain_get_display_mode(const struct wined3d_swapchain *swapchain, WINED3DDISPLAYMODE *mode) +HRESULT CDECL wined3d_swapchain_get_display_mode(const struct wined3d_swapchain *swapchain, + struct wined3d_display_mode *mode) { HRESULT hr; @@ -223,7 +231,7 @@ HRESULT CDECL wined3d_swapchain_get_display_mode(const struct wined3d_swapchain hr = wined3d_get_adapter_display_mode(swapchain->device->wined3d, swapchain->device->adapter->ordinal, mode); TRACE("Returning w %u, h %u, refresh rate %u, format %s.\n", - mode->Width, mode->Height, mode->RefreshRate, debug_d3dformat(mode->Format)); + mode->width, mode->height, mode->refresh_rate, debug_d3dformat(mode->format_id)); return hr; } @@ -235,18 +243,18 @@ struct wined3d_device * CDECL wined3d_swapchain_get_device(const struct wined3d_ return swapchain->device; } -HRESULT CDECL wined3d_swapchain_get_present_parameters(const struct wined3d_swapchain *swapchain, - WINED3DPRESENT_PARAMETERS *present_parameters) +HRESULT CDECL wined3d_swapchain_get_desc(const struct wined3d_swapchain *swapchain, + struct wined3d_swapchain_desc *desc) { - TRACE("swapchain %p, present_parameters %p.\n", swapchain, present_parameters); + TRACE("swapchain %p, desc %p.\n", swapchain, desc); - *present_parameters = swapchain->presentParms; + *desc = swapchain->desc; return WINED3D_OK; } HRESULT CDECL wined3d_swapchain_set_gamma_ramp(const struct wined3d_swapchain *swapchain, - DWORD flags, const WINED3DGAMMARAMP *ramp) + DWORD flags, const struct wined3d_gamma_ramp *ramp) { HDC dc; @@ -263,7 +271,7 @@ HRESULT CDECL wined3d_swapchain_set_gamma_ramp(const struct wined3d_swapchain *s } HRESULT CDECL wined3d_swapchain_get_gamma_ramp(const struct wined3d_swapchain *swapchain, - WINED3DGAMMARAMP *ramp) + struct wined3d_gamma_ramp *ramp) { HDC dc; @@ -277,11 +285,10 @@ HRESULT CDECL wined3d_swapchain_get_gamma_ramp(const struct wined3d_swapchain *s } /* A GL context is provided by the caller */ -static void swapchain_blit(struct wined3d_swapchain *swapchain, +static void swapchain_blit(const struct wined3d_swapchain *swapchain, struct wined3d_context *context, const RECT *src_rect, const RECT *dst_rect) { struct wined3d_surface *backbuffer = swapchain->back_buffers[0]; - struct wined3d_device *device = swapchain->device; UINT src_w = src_rect->right - src_rect->left; UINT src_h = src_rect->bottom - src_rect->top; GLenum gl_filter; @@ -302,22 +309,31 @@ static void swapchain_blit(struct wined3d_swapchain *swapchain, if (gl_info->fbo_ops.glBlitFramebuffer && is_identity_fixup(backbuffer->resource.format->color_fixup)) { + DWORD location = SFLAG_INTEXTURE; + + if (backbuffer->resource.multisample_type) + { + location = SFLAG_INRB_RESOLVED; + surface_load_location(backbuffer, location, NULL); + } + ENTER_GL(); - context_apply_fbo_state_blit(context, GL_READ_FRAMEBUFFER, backbuffer, NULL, SFLAG_INTEXTURE); + context_apply_fbo_state_blit(context, GL_READ_FRAMEBUFFER, backbuffer, NULL, location); glReadBuffer(GL_COLOR_ATTACHMENT0); context_check_fbo_status(context, GL_READ_FRAMEBUFFER); - context_bind_fbo(context, GL_DRAW_FRAMEBUFFER, NULL); + context_apply_fbo_state_blit(context, GL_DRAW_FRAMEBUFFER, swapchain->front_buffer, NULL, SFLAG_INDRAWABLE); context_set_draw_buffer(context, GL_BACK); + context_invalidate_state(context, STATE_FRAMEBUFFER); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE)); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE1)); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE2)); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE3)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3)); glDisable(GL_SCISSOR_TEST); - IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE)); + context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE)); /* Note that the texture is upside down */ gl_info->fbo_ops.glBlitFramebuffer(src_rect->left, src_rect->top, src_rect->right, src_rect->bottom, @@ -328,6 +344,7 @@ static void swapchain_blit(struct wined3d_swapchain *swapchain, } else { + struct wined3d_device *device = swapchain->device; struct wined3d_context *context2; float tex_left = src_rect->left; float tex_top = src_rect->top; @@ -349,12 +366,11 @@ static void swapchain_blit(struct wined3d_swapchain *swapchain, gl_filter = GL_NEAREST; ENTER_GL(); - context_bind_fbo(context2, GL_FRAMEBUFFER, NULL); + context_apply_fbo_state_blit(context2, GL_FRAMEBUFFER, swapchain->front_buffer, NULL, SFLAG_INDRAWABLE); - /* Set up the texture. The surface is not in a IWineD3D*Texture container, - * so there are no d3d texture settings to dirtify - */ - device->blitter->set_shader(device->blit_priv, context2->gl_info, backbuffer); + /* Set up the texture. The surface is not in a wined3d_texture + * container, so there are no D3D texture settings to dirtify. */ + device->blitter->set_shader(device->blit_priv, context2, backbuffer); glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MIN_FILTER, gl_filter); glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MAG_FILTER, gl_filter); @@ -443,9 +459,9 @@ static HRESULT swapchain_gl_present(struct wined3d_swapchain *swapchain, const R memset(&cursor, 0, sizeof(cursor)); cursor.resource.ref = 1; cursor.resource.device = swapchain->device; - cursor.resource.pool = WINED3DPOOL_SCRATCH; + cursor.resource.pool = WINED3D_POOL_SCRATCH; cursor.resource.format = wined3d_get_format(gl_info, WINED3DFMT_B8G8R8A8_UNORM); - cursor.resource.resourceType = WINED3DRTYPE_SURFACE; + cursor.resource.type = WINED3D_RTYPE_SURFACE; cursor.texture_name = swapchain->device->cursorTexture; cursor.texture_target = GL_TEXTURE_2D; cursor.texture_level = 0; @@ -459,17 +475,20 @@ static HRESULT swapchain_gl_present(struct wined3d_swapchain *swapchain, const R /* DDBLT_KEYSRC will cause BltOverride to enable the alpha test with GL_NOTEQUAL, 0.0, * which is exactly what we want :-) */ - if (swapchain->presentParms.Windowed) - MapWindowPoints(NULL, swapchain->win_handle, (LPPOINT)&destRect, 2); + if (swapchain->desc.windowed) + MapWindowPoints(NULL, swapchain->win_handle, (POINT *)&destRect, 2); wined3d_surface_blt(swapchain->back_buffers[0], &destRect, - &cursor, NULL, WINEDDBLT_KEYSRC, NULL, WINED3DTEXF_POINT); + &cursor, NULL, WINEDDBLT_KEYSRC, NULL, WINED3D_TEXF_POINT); } if (swapchain->device->logo_surface) { + struct wined3d_surface *src_surface = swapchain->device->logo_surface; + RECT rect = {0, 0, src_surface->resource.width, src_surface->resource.height}; + /* Blit the logo into the upper left corner of the drawable. */ - wined3d_surface_bltfast(swapchain->back_buffers[0], 0, 0, - swapchain->device->logo_surface, NULL, WINEDDBLTFAST_SRCCOLORKEY); + wined3d_surface_blt(swapchain->back_buffers[0], &rect, src_surface, &rect, + WINEDDBLT_KEYSRC, NULL, WINED3D_TEXF_POINT); } TRACE("Presenting HDC %p.\n", context->hdc); @@ -480,8 +499,8 @@ static HRESULT swapchain_gl_present(struct wined3d_swapchain *swapchain, const R { src_rect = *src_rect_in; if (!render_to_fbo && (src_rect.left || src_rect.top - || src_rect.right != swapchain->presentParms.BackBufferWidth - || src_rect.bottom != swapchain->presentParms.BackBufferHeight)) + || src_rect.right != swapchain->desc.backbuffer_width + || src_rect.bottom != swapchain->desc.backbuffer_height)) { render_to_fbo = TRUE; } @@ -490,8 +509,8 @@ static HRESULT swapchain_gl_present(struct wined3d_swapchain *swapchain, const R { src_rect.left = 0; src_rect.top = 0; - src_rect.right = swapchain->presentParms.BackBufferWidth; - src_rect.bottom = swapchain->presentParms.BackBufferHeight; + src_rect.right = swapchain->desc.backbuffer_width; + src_rect.bottom = swapchain->desc.backbuffer_height; } if (dst_rect_in) @@ -500,11 +519,9 @@ static HRESULT swapchain_gl_present(struct wined3d_swapchain *swapchain, const R GetClientRect(swapchain->win_handle, &dst_rect); if (!render_to_fbo && (dst_rect.left || dst_rect.top - || dst_rect.right != swapchain->presentParms.BackBufferWidth - || dst_rect.bottom != swapchain->presentParms.BackBufferHeight)) - { + || dst_rect.right != swapchain->desc.backbuffer_width + || dst_rect.bottom != swapchain->desc.backbuffer_height)) render_to_fbo = TRUE; - } /* Rendering to a window of different size, presenting partial rectangles, * or rendering to a different window needs help from FBO_blit or a textured @@ -518,6 +535,7 @@ static HRESULT swapchain_gl_present(struct wined3d_swapchain *swapchain, const R surface_load_location(swapchain->back_buffers[0], SFLAG_INTEXTURE, NULL); surface_modify_location(swapchain->back_buffers[0], SFLAG_INDRAWABLE, FALSE); swapchain->render_to_fbo = TRUE; + swapchain_update_draw_bindings(swapchain); } if (swapchain->render_to_fbo) @@ -528,8 +546,8 @@ static HRESULT swapchain_gl_present(struct wined3d_swapchain *swapchain, const R * * The DISCARD swap effect is ok as well since any backbuffer content is allowed after * the swap. */ - if (swapchain->presentParms.SwapEffect == WINED3DSWAPEFFECT_FLIP) - FIXME("Render-to-fbo with WINED3DSWAPEFFECT_FLIP\n"); + if (swapchain->desc.swap_effect == WINED3D_SWAP_EFFECT_FLIP) + FIXME("Render-to-fbo with WINED3D_SWAP_EFFECT_FLIP\n"); swapchain_blit(swapchain, context, &src_rect, &dst_rect); } @@ -570,12 +588,14 @@ static HRESULT swapchain_gl_present(struct wined3d_swapchain *swapchain, const R * bug shows up much more than it does on Windows, and the players see single pixels * with wrong colors. * (The Max Payne bug has been confirmed on Windows with the debug runtime) */ - if (FALSE && swapchain->presentParms.SwapEffect == WINED3DSWAPEFFECT_DISCARD) + if (FALSE && swapchain->desc.swap_effect == WINED3D_SWAP_EFFECT_DISCARD) { + static const struct wined3d_color cyan = {0.0f, 1.0f, 1.0f, 1.0f}; + TRACE("Clearing the color buffer with cyan color\n"); wined3d_device_clear(swapchain->device, 0, NULL, - WINED3DCLEAR_TARGET, 0xff00ffff, 1.0f, 0); + WINED3DCLEAR_TARGET, &cyan, 1.0f, 0); } if (!swapchain->render_to_fbo && ((swapchain->front_buffer->flags & SFLAG_INSYSMEM) @@ -612,16 +632,16 @@ static HRESULT swapchain_gl_present(struct wined3d_swapchain *swapchain, const R * If the swapeffect is COPY, the content remains the same. If it is FLIP however, * the texture / sysmem copy needs to be reloaded from the drawable */ - if (swapchain->presentParms.SwapEffect == WINED3DSWAPEFFECT_FLIP) - surface_modify_location(swapchain->back_buffers[0], SFLAG_INDRAWABLE, TRUE); + if (swapchain->desc.swap_effect == WINED3D_SWAP_EFFECT_FLIP) + surface_modify_location(swapchain->back_buffers[0], swapchain->back_buffers[0]->draw_binding, TRUE); } if (fb->depth_stencil) { - if (swapchain->presentParms.Flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL + if (swapchain->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL || fb->depth_stencil->flags & SFLAG_DISCARD) { - surface_modify_ds_location(fb->depth_stencil, SFLAG_DS_DISCARDED, + surface_modify_ds_location(fb->depth_stencil, SFLAG_LOST, fb->depth_stencil->resource.width, fb->depth_stencil->resource.height); if (fb->depth_stencil == swapchain->device->onscreen_depth_stencil) @@ -644,9 +664,9 @@ static const struct wined3d_swapchain_ops swapchain_gl_ops = }; /* Helper function that blits the front buffer contents to the target window. */ -void x11_copy_to_screen(struct wined3d_swapchain *swapchain, const RECT *rect) +void x11_copy_to_screen(const struct wined3d_swapchain *swapchain, const RECT *rect) { - struct wined3d_surface *front; + const struct wined3d_surface *front; POINT offset = {0, 0}; HDC src_dc, dst_dc; RECT draw_rect; @@ -658,6 +678,9 @@ void x11_copy_to_screen(struct wined3d_swapchain *swapchain, const RECT *rect) if (!(front->resource.usage & WINED3DUSAGE_RENDERTARGET)) return; + if (front->flags & SFLAG_LOCKED) + ERR("Trying to blit a mapped surface.\n"); + TRACE("Copying surface %p to screen.\n", front); src_dc = front->hDC; @@ -666,53 +689,18 @@ void x11_copy_to_screen(struct wined3d_swapchain *swapchain, const RECT *rect) /* Front buffer coordinates are screen coordinates. Map them to the * destination window if not fullscreened. */ - if (swapchain->presentParms.Windowed) + if (swapchain->desc.windowed) ClientToScreen(window, &offset); TRACE("offset %s.\n", wine_dbgstr_point(&offset)); -#if 0 - /* FIXME: This doesn't work... if users really want to run - * X in 8bpp, then we need to call directly into display.drv - * (or Wine's equivalent), and force a private colormap - * without default entries. */ - if (front->palette) - { - SelectPalette(dst_dc, front->palette->hpal, FALSE); - RealizePalette(dst_dc); /* sends messages => deadlocks */ - } -#endif - draw_rect.left = 0; draw_rect.right = front->resource.width; draw_rect.top = 0; draw_rect.bottom = front->resource.height; -#if 0 - /* TODO: Support clippers. */ - if (front->clipper) - { - RECT xrc; - HWND hwnd = ((IWineD3DClipperImpl *)front->clipper)->hWnd; - if (hwnd && GetClientRect(hwnd,&xrc)) - { - OffsetRect(&xrc, offset.x, offset.y); - IntersectRect(&draw_rect, &draw_rect, &xrc); - } - } -#endif - - if (!rect) - { - /* Only use this if the caller did not pass a rectangle, since - * due to double locking this could be the wrong one... */ - if (front->lockedRect.left != front->lockedRect.right) - IntersectRect(&draw_rect, &draw_rect, &front->lockedRect); - } - else - { + if (rect) IntersectRect(&draw_rect, &draw_rect, rect); - } BitBlt(dst_dc, draw_rect.left - offset.x, draw_rect.top - offset.y, draw_rect.right - draw_rect.left, draw_rect.bottom - draw_rect.top, @@ -768,14 +756,6 @@ static HRESULT swapchain_gdi_present(struct wined3d_swapchain *swapchain, const ERR("GDI Surface %p has heap memory allocated.\n", back); } - /* Client_memory should not be different, but just in case. */ - { - BOOL tmp; - tmp = front->dib.client_memory; - front->dib.client_memory = back->dib.client_memory; - back->dib.client_memory = tmp; - } - /* FPS support */ if (TRACE_ON(fps)) { @@ -803,28 +783,65 @@ static const struct wined3d_swapchain_ops swapchain_gdi_ops = swapchain_gdi_present, }; +void swapchain_update_render_to_fbo(struct wined3d_swapchain *swapchain) +{ + RECT client_rect; + + if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) + return; + + if (!swapchain->desc.backbuffer_count) + { + TRACE("Single buffered rendering.\n"); + swapchain->render_to_fbo = FALSE; + return; + } + + GetClientRect(swapchain->win_handle, &client_rect); + + TRACE("Backbuffer %ux%u, window %ux%u.\n", + swapchain->desc.backbuffer_width, + swapchain->desc.backbuffer_height, + client_rect.right, client_rect.bottom); + TRACE("Multisample type %#x, quality %#x.\n", + swapchain->desc.multisample_type, + swapchain->desc.multisample_quality); + + if (!wined3d_settings.always_offscreen && !swapchain->desc.multisample_type + && swapchain->desc.backbuffer_width == client_rect.right + && swapchain->desc.backbuffer_height == client_rect.bottom) + { + TRACE("Backbuffer dimensions match window dimensions, rendering onscreen.\n"); + swapchain->render_to_fbo = FALSE; + return; + } + + TRACE("Rendering to FBO.\n"); + swapchain->render_to_fbo = TRUE; +} + /* Do not call while under the GL lock. */ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, WINED3DSURFTYPE surface_type, - struct wined3d_device *device, WINED3DPRESENT_PARAMETERS *present_parameters, + struct wined3d_device *device, struct wined3d_swapchain_desc *desc, void *parent, const struct wined3d_parent_ops *parent_ops) { const struct wined3d_adapter *adapter = device->adapter; const struct wined3d_format *format; + struct wined3d_display_mode mode; BOOL displaymode_set = FALSE; - WINED3DDISPLAYMODE mode; RECT client_rect; HWND window; HRESULT hr; UINT i; - if (present_parameters->BackBufferCount > WINED3DPRESENT_BACK_BUFFER_MAX) + if (desc->backbuffer_count > WINED3DPRESENT_BACK_BUFFER_MAX) { FIXME("The application requested %u back buffers, this is not supported.\n", - present_parameters->BackBufferCount); + desc->backbuffer_count); return WINED3DERR_INVALIDCALL; } - if (present_parameters->BackBufferCount > 1) + if (desc->backbuffer_count > 1) { FIXME("The application requested more than one back buffer, this is not properly supported.\n" "Please configure the application to use double buffering (1 back buffer) if possible.\n"); @@ -840,12 +857,12 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, WINED3DSURFTY swapchain->swapchain_ops = &swapchain_gl_ops; break; - case SURFACE_UNKNOWN: - FIXME("Caller tried to create a SURFACE_UNKNOWN swapchain.\n"); + default: + ERR("Invalid surface type %#x.\n", surface_type); return WINED3DERR_INVALIDCALL; } - window = present_parameters->hDeviceWindow ? present_parameters->hDeviceWindow : device->createParms.hFocusWindow; + window = desc->device_window ? desc->device_window : device->create_parms.focus_window; swapchain->device = device; swapchain->parent = parent; @@ -855,54 +872,43 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, WINED3DSURFTY swapchain->device_window = window; wined3d_get_adapter_display_mode(device->wined3d, adapter->ordinal, &mode); - swapchain->orig_width = mode.Width; - swapchain->orig_height = mode.Height; - swapchain->orig_fmt = mode.Format; - format = wined3d_get_format(&adapter->gl_info, mode.Format); + swapchain->orig_width = mode.width; + swapchain->orig_height = mode.height; + swapchain->orig_fmt = mode.format_id; + format = wined3d_get_format(&adapter->gl_info, mode.format_id); GetClientRect(window, &client_rect); - if (present_parameters->Windowed - && (!present_parameters->BackBufferWidth || !present_parameters->BackBufferHeight - || present_parameters->BackBufferFormat == WINED3DFMT_UNKNOWN)) + if (desc->windowed + && (!desc->backbuffer_width || !desc->backbuffer_height + || desc->backbuffer_format == WINED3DFMT_UNKNOWN)) { - if (!present_parameters->BackBufferWidth) + if (!desc->backbuffer_width) { - present_parameters->BackBufferWidth = client_rect.right; - TRACE("Updating width to %u.\n", present_parameters->BackBufferWidth); + desc->backbuffer_width = client_rect.right; + TRACE("Updating width to %u.\n", desc->backbuffer_width); } - if (!present_parameters->BackBufferHeight) + if (!desc->backbuffer_height) { - present_parameters->BackBufferHeight = client_rect.bottom; - TRACE("Updating height to %u.\n", present_parameters->BackBufferHeight); + desc->backbuffer_height = client_rect.bottom; + TRACE("Updating height to %u.\n", desc->backbuffer_height); } - if (present_parameters->BackBufferFormat == WINED3DFMT_UNKNOWN) + if (desc->backbuffer_format == WINED3DFMT_UNKNOWN) { - present_parameters->BackBufferFormat = swapchain->orig_fmt; + desc->backbuffer_format = swapchain->orig_fmt; TRACE("Updating format to %s.\n", debug_d3dformat(swapchain->orig_fmt)); } } - swapchain->presentParms = *present_parameters; - - if (wined3d_settings.offscreen_rendering_mode == ORM_FBO - && present_parameters->BackBufferCount - && (present_parameters->BackBufferWidth != client_rect.right - || present_parameters->BackBufferHeight != client_rect.bottom)) - { - TRACE("Rendering to FBO. Backbuffer %ux%u, window %ux%u.\n", - present_parameters->BackBufferWidth, - present_parameters->BackBufferHeight, - client_rect.right, client_rect.bottom); - swapchain->render_to_fbo = TRUE; - } + swapchain->desc = *desc; + swapchain_update_render_to_fbo(swapchain); TRACE("Creating front buffer.\n"); hr = device->device_parent->ops->create_rendertarget(device->device_parent, parent, - swapchain->presentParms.BackBufferWidth, swapchain->presentParms.BackBufferHeight, - swapchain->presentParms.BackBufferFormat, swapchain->presentParms.MultiSampleType, - swapchain->presentParms.MultiSampleQuality, TRUE /* Lockable */, + swapchain->desc.backbuffer_width, swapchain->desc.backbuffer_height, + swapchain->desc.backbuffer_format, swapchain->desc.multisample_type, + swapchain->desc.multisample_quality, TRUE /* Lockable */, &swapchain->front_buffer); if (FAILED(hr)) { @@ -920,15 +926,15 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, WINED3DSURFTY * so we should really check to see if there is a fullscreen swapchain * already. Does a single head count as full screen? */ - if (!present_parameters->Windowed) + if (!desc->windowed) { - WINED3DDISPLAYMODE mode; + struct wined3d_display_mode mode; /* Change the display settings */ - mode.Width = present_parameters->BackBufferWidth; - mode.Height = present_parameters->BackBufferHeight; - mode.Format = present_parameters->BackBufferFormat; - mode.RefreshRate = present_parameters->FullScreen_RefreshRateInHz; + mode.width = desc->backbuffer_width; + mode.height = desc->backbuffer_height; + mode.format_id = desc->backbuffer_format; + mode.refresh_rate = desc->refresh_rate; hr = wined3d_device_set_display_mode(device, 0, &mode); if (FAILED(hr)) @@ -952,7 +958,7 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, WINED3DSURFTY const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; - swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(swapchain->context)); + swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain->context)); if (!swapchain->context) { ERR("Failed to create the context array.\n"); @@ -988,18 +994,19 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, WINED3DSURFTY goto err; } - if (!present_parameters->EnableAutoDepthStencil - || swapchain->presentParms.AutoDepthStencilFormat != swapchain->ds_format->id) + if (wined3d_settings.offscreen_rendering_mode != ORM_FBO + && (!desc->enable_auto_depth_stencil + || swapchain->desc.auto_depth_stencil_format != swapchain->ds_format->id)) { FIXME("Add OpenGL context recreation support to context_validate_onscreen_formats\n"); } context_release(swapchain->context[0]); } - if (swapchain->presentParms.BackBufferCount > 0) + if (swapchain->desc.backbuffer_count > 0) { swapchain->back_buffers = HeapAlloc(GetProcessHeap(), 0, - sizeof(*swapchain->back_buffers) * swapchain->presentParms.BackBufferCount); + sizeof(*swapchain->back_buffers) * swapchain->desc.backbuffer_count); if (!swapchain->back_buffers) { ERR("Failed to allocate backbuffer array memory.\n"); @@ -1007,13 +1014,13 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, WINED3DSURFTY goto err; } - for (i = 0; i < swapchain->presentParms.BackBufferCount; ++i) + for (i = 0; i < swapchain->desc.backbuffer_count; ++i) { TRACE("Creating back buffer %u.\n", i); hr = device->device_parent->ops->create_rendertarget(device->device_parent, parent, - swapchain->presentParms.BackBufferWidth, swapchain->presentParms.BackBufferHeight, - swapchain->presentParms.BackBufferFormat, swapchain->presentParms.MultiSampleType, - swapchain->presentParms.MultiSampleQuality, TRUE /* Lockable */, + swapchain->desc.backbuffer_width, swapchain->desc.backbuffer_height, + swapchain->desc.backbuffer_format, swapchain->desc.multisample_type, + swapchain->desc.multisample_quality, TRUE /* Lockable */, &swapchain->back_buffers[i]); if (FAILED(hr)) { @@ -1026,15 +1033,15 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, WINED3DSURFTY } /* Swapchains share the depth/stencil buffer, so only create a single depthstencil surface. */ - if (present_parameters->EnableAutoDepthStencil && surface_type == SURFACE_OPENGL) + if (desc->enable_auto_depth_stencil && surface_type == SURFACE_OPENGL) { TRACE("Creating depth/stencil buffer.\n"); if (!device->auto_depth_stencil) { hr = device->device_parent->ops->create_depth_stencil(device->device_parent, - swapchain->presentParms.BackBufferWidth, swapchain->presentParms.BackBufferHeight, - swapchain->presentParms.AutoDepthStencilFormat, swapchain->presentParms.MultiSampleType, - swapchain->presentParms.MultiSampleQuality, FALSE /* FIXME: Discard */, + swapchain->desc.backbuffer_width, swapchain->desc.backbuffer_height, + swapchain->desc.auto_depth_stencil_format, swapchain->desc.multisample_type, + swapchain->desc.multisample_quality, FALSE /* FIXME: Discard */, &device->auto_depth_stencil); if (FAILED(hr)) { @@ -1069,10 +1076,13 @@ err: if (swapchain->back_buffers) { - for (i = 0; i < swapchain->presentParms.BackBufferCount; ++i) + for (i = 0; i < swapchain->desc.backbuffer_count; ++i) { if (swapchain->back_buffers[i]) + { + surface_set_container(swapchain->back_buffers[i], WINED3D_CONTAINER_NONE, NULL); wined3d_surface_decref(swapchain->back_buffers[i]); + } } HeapFree(GetProcessHeap(), 0, swapchain->back_buffers); } @@ -1089,22 +1099,25 @@ err: } if (swapchain->front_buffer) + { + surface_set_container(swapchain->front_buffer, WINED3D_CONTAINER_NONE, NULL); wined3d_surface_decref(swapchain->front_buffer); + } return hr; } /* Do not call while under the GL lock. */ HRESULT CDECL wined3d_swapchain_create(struct wined3d_device *device, - WINED3DPRESENT_PARAMETERS *present_parameters, WINED3DSURFTYPE surface_type, + struct wined3d_swapchain_desc *desc, WINED3DSURFTYPE surface_type, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_swapchain **swapchain) { struct wined3d_swapchain *object; HRESULT hr; - TRACE("device %p, present_parameters %p, swapchain %p, parent %p, surface_type %#x.\n", - device, present_parameters, swapchain, parent, surface_type); + TRACE("device %p, desc %p, swapchain %p, parent %p, surface_type %#x.\n", + device, desc, swapchain, parent, surface_type); object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); if (!object) @@ -1113,7 +1126,7 @@ HRESULT CDECL wined3d_swapchain_create(struct wined3d_device *device, return E_OUTOFMEMORY; } - hr = swapchain_init(object, surface_type, device, present_parameters, parent, parent_ops); + hr = swapchain_init(object, surface_type, device, desc, parent, parent_ops); if (FAILED(hr)) { WARN("Failed to initialize swapchain, hr %#x.\n", hr); @@ -1158,6 +1171,17 @@ static struct wined3d_context *swapchain_create_context(struct wined3d_swapchain return ctx; } +void swapchain_destroy_contexts(struct wined3d_swapchain *swapchain) +{ + unsigned int i; + + for (i = 0; i < swapchain->num_contexts; ++i) + { + context_destroy(swapchain->device, swapchain->context[i]); + } + swapchain->num_contexts = 0; +} + struct wined3d_context *swapchain_get_context(struct wined3d_swapchain *swapchain) { DWORD tid = GetCurrentThreadId(); @@ -1173,10 +1197,47 @@ struct wined3d_context *swapchain_get_context(struct wined3d_swapchain *swapchai return swapchain_create_context(swapchain); } -void get_drawable_size_swapchain(struct wined3d_context *context, UINT *width, UINT *height) +void get_drawable_size_swapchain(const struct wined3d_context *context, UINT *width, UINT *height) { /* The drawable size of an onscreen drawable is the surface size. * (Actually: The window size, but the surface is created in window size) */ *width = context->current_rt->resource.width; *height = context->current_rt->resource.height; } + +HDC swapchain_get_backup_dc(struct wined3d_swapchain *swapchain) +{ + if (!swapchain->backup_dc) + { + TRACE("Creating the backup window for swapchain %p.\n", swapchain); + + if (!(swapchain->backup_wnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window", + WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL))) + { + ERR("Failed to create a window.\n"); + return NULL; + } + + if (!(swapchain->backup_dc = GetDC(swapchain->backup_wnd))) + { + ERR("Failed to get a DC.\n"); + DestroyWindow(swapchain->backup_wnd); + swapchain->backup_wnd = NULL; + return NULL; + } + } + + return swapchain->backup_dc; +} + +void swapchain_update_draw_bindings(struct wined3d_swapchain *swapchain) +{ + UINT i; + + surface_update_draw_binding(swapchain->front_buffer); + + for (i = 0; i < swapchain->desc.backbuffer_count; ++i) + { + surface_update_draw_binding(swapchain->back_buffers[i]); + } +} diff --git a/reactos/dll/directx/wine/wined3d/texture.c b/reactos/dll/directx/wine/wined3d/texture.c index 34801b8e510..cc7edb0244b 100644 --- a/reactos/dll/directx/wine/wined3d/texture.c +++ b/reactos/dll/directx/wine/wined3d/texture.c @@ -26,14 +26,14 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture); static HRESULT wined3d_texture_init(struct wined3d_texture *texture, const struct wined3d_texture_ops *texture_ops, - UINT layer_count, UINT level_count, WINED3DRESOURCETYPE resource_type, struct wined3d_device *device, - DWORD usage, const struct wined3d_format *format, WINED3DPOOL pool, void *parent, + UINT layer_count, UINT level_count, enum wined3d_resource_type resource_type, struct wined3d_device *device, + DWORD usage, const struct wined3d_format *format, enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops, const struct wined3d_resource_ops *resource_ops) { HRESULT hr; hr = resource_init(&texture->resource, device, resource_type, format, - WINED3DMULTISAMPLE_NONE, 0, usage, pool, 0, 0, 0, 0, + WINED3D_MULTISAMPLE_NONE, 0, usage, pool, 0, 0, 0, 0, parent, parent_ops, resource_ops); if (FAILED(hr)) { @@ -53,7 +53,7 @@ static HRESULT wined3d_texture_init(struct wined3d_texture *texture, const struc texture->layer_count = layer_count; texture->level_count = level_count; - texture->filter_type = (usage & WINED3DUSAGE_AUTOGENMIPMAP) ? WINED3DTEXF_LINEAR : WINED3DTEXF_NONE; + texture->filter_type = (usage & WINED3DUSAGE_AUTOGENMIPMAP) ? WINED3D_TEXF_LINEAR : WINED3D_TEXF_NONE; texture->lod = 0; texture->texture_rgb.dirty = TRUE; texture->texture_srgb.dirty = TRUE; @@ -133,14 +133,14 @@ void wined3d_texture_set_dirty(struct wined3d_texture *texture, BOOL dirty) /* Context activation is done by the caller. */ static HRESULT wined3d_texture_bind(struct wined3d_texture *texture, - const struct wined3d_gl_info *gl_info, BOOL srgb, BOOL *set_surface_desc) + struct wined3d_context *context, BOOL srgb, BOOL *set_surface_desc) { struct gl_texture *gl_tex; BOOL new_texture = FALSE; HRESULT hr = WINED3D_OK; GLenum target; - TRACE("texture %p, srgb %#x, set_surface_desc %p.\n", texture, srgb, set_surface_desc); + TRACE("texture %p, context %p, srgb %#x, set_surface_desc %p.\n", texture, context, srgb, set_surface_desc); /* sRGB mode cache for preload() calls outside drawprim. */ if (srgb) @@ -148,7 +148,7 @@ static HRESULT wined3d_texture_bind(struct wined3d_texture *texture, else texture->flags &= ~WINED3D_TEXTURE_IS_SRGB; - gl_tex = wined3d_texture_get_gl_texture(texture, gl_info, srgb); + gl_tex = wined3d_texture_get_gl_texture(texture, context->gl_info, srgb); target = texture->target; ENTER_GL(); @@ -159,7 +159,7 @@ static HRESULT wined3d_texture_bind(struct wined3d_texture *texture, glGenTextures(1, &gl_tex->name); checkGLcall("glGenTextures"); TRACE("Generated texture %d.\n", gl_tex->name); - if (texture->resource.pool == WINED3DPOOL_DEFAULT) + if (texture->resource.pool == WINED3D_POOL_DEFAULT) { /* Tell OpenGL to try and keep this texture in video ram (well mostly). */ GLclampf tmp = 0.9f; @@ -167,16 +167,16 @@ static HRESULT wined3d_texture_bind(struct wined3d_texture *texture, } /* Initialise the state of the texture object to the OpenGL defaults, * not the D3D defaults. */ - gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_WRAP; - gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_WRAP; - gl_tex->states[WINED3DTEXSTA_ADDRESSW] = WINED3DTADDRESS_WRAP; + gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3D_TADDRESS_WRAP; + gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3D_TADDRESS_WRAP; + gl_tex->states[WINED3DTEXSTA_ADDRESSW] = WINED3D_TADDRESS_WRAP; gl_tex->states[WINED3DTEXSTA_BORDERCOLOR] = 0; - gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_LINEAR; - gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT; /* GL_NEAREST_MIPMAP_LINEAR */ - gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_LINEAR; /* GL_NEAREST_MIPMAP_LINEAR */ + gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3D_TEXF_LINEAR; + gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3D_TEXF_POINT; /* GL_NEAREST_MIPMAP_LINEAR */ + gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3D_TEXF_LINEAR; /* GL_NEAREST_MIPMAP_LINEAR */ gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] = 0; gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] = 1; - if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE]) + if (context->gl_info->supported[EXT_TEXTURE_SRGB_DECODE]) gl_tex->states[WINED3DTEXSTA_SRGBTEXTURE] = TRUE; else gl_tex->states[WINED3DTEXSTA_SRGBTEXTURE] = srgb; @@ -189,8 +189,7 @@ static HRESULT wined3d_texture_bind(struct wined3d_texture *texture, /* This means double binding the texture at creation, but keeps * the code simpler all in all, and the run-time path free from * additional checks. */ - glBindTexture(target, gl_tex->name); - checkGLcall("glBindTexture"); + context_bind_texture(context, target, gl_tex->name); glTexParameteri(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); checkGLcall("glTexParameteri(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE)"); } @@ -202,8 +201,7 @@ static HRESULT wined3d_texture_bind(struct wined3d_texture *texture, if (gl_tex->name) { - glBindTexture(target, gl_tex->name); - checkGLcall("glBindTexture"); + context_bind_texture(context, target, gl_tex->name); if (new_texture) { /* For a new texture we have to set the texture levels after @@ -239,22 +237,22 @@ static HRESULT wined3d_texture_bind(struct wined3d_texture *texture, /* GL locking is done by the caller */ static void apply_wrap(const struct wined3d_gl_info *gl_info, GLenum target, - WINED3DTEXTUREADDRESS d3d_wrap, GLenum param, BOOL cond_np2) + enum wined3d_texture_address d3d_wrap, GLenum param, BOOL cond_np2) { GLint gl_wrap; - if (d3d_wrap < WINED3DTADDRESS_WRAP || d3d_wrap > WINED3DTADDRESS_MIRRORONCE) + if (d3d_wrap < WINED3D_TADDRESS_WRAP || d3d_wrap > WINED3D_TADDRESS_MIRROR_ONCE) { - FIXME("Unrecognized or unsupported WINED3DTEXTUREADDRESS %#x.\n", d3d_wrap); + FIXME("Unrecognized or unsupported texture address mode %#x.\n", d3d_wrap); return; } /* Cubemaps are always set to clamp, regardless of the sampler state. */ if (target == GL_TEXTURE_CUBE_MAP_ARB - || (cond_np2 && d3d_wrap == WINED3DTADDRESS_WRAP)) + || (cond_np2 && d3d_wrap == WINED3D_TADDRESS_WRAP)) gl_wrap = GL_CLAMP_TO_EDGE; else - gl_wrap = gl_info->wrap_lookup[d3d_wrap - WINED3DTADDRESS_WRAP]; + gl_wrap = gl_info->wrap_lookup[d3d_wrap - WINED3D_TADDRESS_WRAP]; TRACE("Setting param %#x to %#x for target %#x.\n", param, gl_wrap, target); glTexParameteri(target, param, gl_wrap); @@ -279,32 +277,32 @@ void wined3d_texture_apply_state_changes(struct wined3d_texture *texture, /* This function relies on the correct texture being bound and loaded. */ - if (sampler_states[WINED3DSAMP_ADDRESSU] != gl_tex->states[WINED3DTEXSTA_ADDRESSU]) + if (sampler_states[WINED3D_SAMP_ADDRESS_U] != gl_tex->states[WINED3DTEXSTA_ADDRESSU]) { - state = sampler_states[WINED3DSAMP_ADDRESSU]; + state = sampler_states[WINED3D_SAMP_ADDRESS_U]; apply_wrap(gl_info, target, state, GL_TEXTURE_WRAP_S, cond_np2); gl_tex->states[WINED3DTEXSTA_ADDRESSU] = state; } - if (sampler_states[WINED3DSAMP_ADDRESSV] != gl_tex->states[WINED3DTEXSTA_ADDRESSV]) + if (sampler_states[WINED3D_SAMP_ADDRESS_V] != gl_tex->states[WINED3DTEXSTA_ADDRESSV]) { - state = sampler_states[WINED3DSAMP_ADDRESSV]; + state = sampler_states[WINED3D_SAMP_ADDRESS_V]; apply_wrap(gl_info, target, state, GL_TEXTURE_WRAP_T, cond_np2); gl_tex->states[WINED3DTEXSTA_ADDRESSV] = state; } - if (sampler_states[WINED3DSAMP_ADDRESSW] != gl_tex->states[WINED3DTEXSTA_ADDRESSW]) + if (sampler_states[WINED3D_SAMP_ADDRESS_W] != gl_tex->states[WINED3DTEXSTA_ADDRESSW]) { - state = sampler_states[WINED3DSAMP_ADDRESSW]; + state = sampler_states[WINED3D_SAMP_ADDRESS_W]; apply_wrap(gl_info, target, state, GL_TEXTURE_WRAP_R, cond_np2); gl_tex->states[WINED3DTEXSTA_ADDRESSW] = state; } - if (sampler_states[WINED3DSAMP_BORDERCOLOR] != gl_tex->states[WINED3DTEXSTA_BORDERCOLOR]) + if (sampler_states[WINED3D_SAMP_BORDER_COLOR] != gl_tex->states[WINED3DTEXSTA_BORDERCOLOR]) { float col[4]; - state = sampler_states[WINED3DSAMP_BORDERCOLOR]; + state = sampler_states[WINED3D_SAMP_BORDER_COLOR]; D3DCOLORTOGLFLOAT4(state, col); TRACE("Setting border color for %#x to %#x.\n", target, state); glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, &col[0]); @@ -312,52 +310,52 @@ void wined3d_texture_apply_state_changes(struct wined3d_texture *texture, gl_tex->states[WINED3DTEXSTA_BORDERCOLOR] = state; } - if (sampler_states[WINED3DSAMP_MAGFILTER] != gl_tex->states[WINED3DTEXSTA_MAGFILTER]) + if (sampler_states[WINED3D_SAMP_MAG_FILTER] != gl_tex->states[WINED3DTEXSTA_MAGFILTER]) { GLint gl_value; - state = sampler_states[WINED3DSAMP_MAGFILTER]; - if (state > WINED3DTEXF_ANISOTROPIC) + state = sampler_states[WINED3D_SAMP_MAG_FILTER]; + if (state > WINED3D_TEXF_ANISOTROPIC) FIXME("Unrecognized or unsupported MAGFILTER* value %d.\n", state); gl_value = wined3d_gl_mag_filter(texture->mag_lookup, - min(max(state, WINED3DTEXF_POINT), WINED3DTEXF_LINEAR)); + min(max(state, WINED3D_TEXF_POINT), WINED3D_TEXF_LINEAR)); TRACE("ValueMAG=%#x setting MAGFILTER to %#x.\n", state, gl_value); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, gl_value); gl_tex->states[WINED3DTEXSTA_MAGFILTER] = state; } - if ((sampler_states[WINED3DSAMP_MINFILTER] != gl_tex->states[WINED3DTEXSTA_MINFILTER] - || sampler_states[WINED3DSAMP_MIPFILTER] != gl_tex->states[WINED3DTEXSTA_MIPFILTER] - || sampler_states[WINED3DSAMP_MAXMIPLEVEL] != gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL])) + if ((sampler_states[WINED3D_SAMP_MIN_FILTER] != gl_tex->states[WINED3DTEXSTA_MINFILTER] + || sampler_states[WINED3D_SAMP_MIP_FILTER] != gl_tex->states[WINED3DTEXSTA_MIPFILTER] + || sampler_states[WINED3D_SAMP_MAX_MIP_LEVEL] != gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL])) { GLint gl_value; - gl_tex->states[WINED3DTEXSTA_MIPFILTER] = sampler_states[WINED3DSAMP_MIPFILTER]; - gl_tex->states[WINED3DTEXSTA_MINFILTER] = sampler_states[WINED3DSAMP_MINFILTER]; - gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] = sampler_states[WINED3DSAMP_MAXMIPLEVEL]; + gl_tex->states[WINED3DTEXSTA_MIPFILTER] = sampler_states[WINED3D_SAMP_MIP_FILTER]; + gl_tex->states[WINED3DTEXSTA_MINFILTER] = sampler_states[WINED3D_SAMP_MIN_FILTER]; + gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] = sampler_states[WINED3D_SAMP_MAX_MIP_LEVEL]; - if (gl_tex->states[WINED3DTEXSTA_MINFILTER] > WINED3DTEXF_ANISOTROPIC - || gl_tex->states[WINED3DTEXSTA_MIPFILTER] > WINED3DTEXF_ANISOTROPIC) + if (gl_tex->states[WINED3DTEXSTA_MINFILTER] > WINED3D_TEXF_ANISOTROPIC + || gl_tex->states[WINED3DTEXSTA_MIPFILTER] > WINED3D_TEXF_ANISOTROPIC) { - FIXME("Unrecognized or unsupported D3DSAMP_MINFILTER value %#x D3DSAMP_MIPFILTER value %#x.\n", + FIXME("Unrecognized or unsupported MIN_FILTER value %#x MIP_FILTER value %#x.\n", gl_tex->states[WINED3DTEXSTA_MINFILTER], gl_tex->states[WINED3DTEXSTA_MIPFILTER]); } gl_value = wined3d_gl_min_mip_filter(texture->min_mip_lookup, - min(max(sampler_states[WINED3DSAMP_MINFILTER], WINED3DTEXF_POINT), WINED3DTEXF_LINEAR), - min(max(sampler_states[WINED3DSAMP_MIPFILTER], WINED3DTEXF_NONE), WINED3DTEXF_LINEAR)); + min(max(sampler_states[WINED3D_SAMP_MIN_FILTER], WINED3D_TEXF_POINT), WINED3D_TEXF_LINEAR), + min(max(sampler_states[WINED3D_SAMP_MIP_FILTER], WINED3D_TEXF_NONE), WINED3D_TEXF_LINEAR)); TRACE("ValueMIN=%#x, ValueMIP=%#x, setting MINFILTER to %#x.\n", - sampler_states[WINED3DSAMP_MINFILTER], - sampler_states[WINED3DSAMP_MIPFILTER], gl_value); + sampler_states[WINED3D_SAMP_MIN_FILTER], + sampler_states[WINED3D_SAMP_MIP_FILTER], gl_value); glTexParameteri(target, GL_TEXTURE_MIN_FILTER, gl_value); checkGLcall("glTexParameter GL_TEXTURE_MIN_FILTER, ..."); if (!cond_np2) { - if (gl_tex->states[WINED3DTEXSTA_MIPFILTER] == WINED3DTEXF_NONE) + if (gl_tex->states[WINED3DTEXSTA_MIPFILTER] == WINED3D_TEXF_NONE) gl_value = texture->lod; else if (gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] >= texture->level_count) gl_value = texture->level_count - 1; @@ -367,21 +365,21 @@ void wined3d_texture_apply_state_changes(struct wined3d_texture *texture, else gl_value = gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL]; - /* Note that WINED3DSAMP_MAXMIPLEVEL specifies the largest mipmap + /* Note that WINED3D_SAMP_MAX_MIP_LEVEL specifies the largest mipmap * (default 0), while GL_TEXTURE_MAX_LEVEL specifies the smallest - * mimap used (default 1000). So WINED3DSAMP_MAXMIPLEVEL + * mimap used (default 1000). So WINED3D_SAMP_MAX_MIP_LEVEL * corresponds to GL_TEXTURE_BASE_LEVEL. */ glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, gl_value); } } - if ((gl_tex->states[WINED3DTEXSTA_MAGFILTER] != WINED3DTEXF_ANISOTROPIC - && gl_tex->states[WINED3DTEXSTA_MINFILTER] != WINED3DTEXF_ANISOTROPIC - && gl_tex->states[WINED3DTEXSTA_MIPFILTER] != WINED3DTEXF_ANISOTROPIC) + if ((gl_tex->states[WINED3DTEXSTA_MAGFILTER] != WINED3D_TEXF_ANISOTROPIC + && gl_tex->states[WINED3DTEXSTA_MINFILTER] != WINED3D_TEXF_ANISOTROPIC + && gl_tex->states[WINED3DTEXSTA_MIPFILTER] != WINED3D_TEXF_ANISOTROPIC) || cond_np2) aniso = 1; else - aniso = sampler_states[WINED3DSAMP_MAXANISOTROPY]; + aniso = sampler_states[WINED3D_SAMP_MAX_ANISOTROPY]; if (gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] != aniso) { @@ -398,11 +396,12 @@ void wined3d_texture_apply_state_changes(struct wined3d_texture *texture, } /* These should always be the same unless EXT_texture_sRGB_decode is supported. */ - if (sampler_states[WINED3DSAMP_SRGBTEXTURE] != gl_tex->states[WINED3DTEXSTA_SRGBTEXTURE]) + if (sampler_states[WINED3D_SAMP_SRGB_TEXTURE] != gl_tex->states[WINED3DTEXSTA_SRGBTEXTURE]) { glTexParameteri(target, GL_TEXTURE_SRGB_DECODE_EXT, - sampler_states[WINED3DSAMP_SRGBTEXTURE] ? GL_DECODE_EXT : GL_SKIP_DECODE_EXT); + sampler_states[WINED3D_SAMP_SRGB_TEXTURE] ? GL_DECODE_EXT : GL_SKIP_DECODE_EXT); checkGLcall("glTexParameteri(GL_TEXTURE_SRGB_DECODE_EXT)"); + gl_tex->states[WINED3DTEXSTA_SRGBTEXTURE] = sampler_states[WINED3D_SAMP_SRGB_TEXTURE]; } if (!(texture->resource.format->flags & WINED3DFMT_FLAG_SHADOW) @@ -450,21 +449,11 @@ ULONG CDECL wined3d_texture_decref(struct wined3d_texture *texture) return refcount; } -HRESULT CDECL wined3d_texture_set_private_data(struct wined3d_texture *texture, - REFGUID guid, const void *data, DWORD data_size, DWORD flags) +struct wined3d_resource * CDECL wined3d_texture_get_resource(struct wined3d_texture *texture) { - return resource_set_private_data(&texture->resource, guid, data, data_size, flags); -} + TRACE("texture %p.\n", texture); -HRESULT CDECL wined3d_texture_get_private_data(const struct wined3d_texture *texture, - REFGUID guid, void *data, DWORD *data_size) -{ - return resource_get_private_data(&texture->resource, guid, data, data_size); -} - -HRESULT CDECL wined3d_texture_free_private_data(struct wined3d_texture *texture, REFGUID guid) -{ - return resource_free_private_data(&texture->resource, guid); + return &texture->resource; } DWORD CDECL wined3d_texture_set_priority(struct wined3d_texture *texture, DWORD priority) @@ -483,13 +472,6 @@ void CDECL wined3d_texture_preload(struct wined3d_texture *texture) texture->texture_ops->texture_preload(texture, SRGB_ANY); } -WINED3DRESOURCETYPE CDECL wined3d_texture_get_type(const struct wined3d_texture *texture) -{ - TRACE("texture %p.\n", texture); - - return texture->resource.resourceType; -} - void * CDECL wined3d_texture_get_parent(const struct wined3d_texture *texture) { TRACE("texture %p.\n", texture); @@ -505,7 +487,7 @@ DWORD CDECL wined3d_texture_set_lod(struct wined3d_texture *texture, DWORD lod) /* The d3d9:texture test shows that SetLOD is ignored on non-managed * textures. The call always returns 0, and GetLOD always returns 0. */ - if (texture->resource.pool != WINED3DPOOL_MANAGED) + if (texture->resource.pool != WINED3D_POOL_MANAGED) { TRACE("Ignoring SetLOD on %s texture, returning 0.\n", debug_d3dpool(texture->resource.pool)); return 0; @@ -521,7 +503,7 @@ DWORD CDECL wined3d_texture_set_lod(struct wined3d_texture *texture, DWORD lod) texture->texture_rgb.states[WINED3DTEXSTA_MAXMIPLEVEL] = ~0U; texture->texture_srgb.states[WINED3DTEXSTA_MAXMIPLEVEL] = ~0U; if (texture->bind_count) - IWineD3DDeviceImpl_MarkStateDirty(texture->resource.device, STATE_SAMPLER(texture->sampler)); + device_invalidate_state(texture->resource.device, STATE_SAMPLER(texture->sampler)); } return old; @@ -542,7 +524,7 @@ DWORD CDECL wined3d_texture_get_level_count(const struct wined3d_texture *textur } HRESULT CDECL wined3d_texture_set_autogen_filter_type(struct wined3d_texture *texture, - WINED3DTEXTUREFILTERTYPE filter_type) + enum wined3d_texture_filter_type filter_type) { FIXME("texture %p, filter_type %s stub!\n", texture, debug_d3dtexturefiltertype(filter_type)); @@ -557,7 +539,7 @@ HRESULT CDECL wined3d_texture_set_autogen_filter_type(struct wined3d_texture *te return WINED3D_OK; } -WINED3DTEXTUREFILTERTYPE CDECL wined3d_texture_get_autogen_filter_type(const struct wined3d_texture *texture) +enum wined3d_texture_filter_type CDECL wined3d_texture_get_autogen_filter_type(const struct wined3d_texture *texture) { TRACE("texture %p.\n", texture); @@ -587,7 +569,7 @@ struct wined3d_resource * CDECL wined3d_texture_get_sub_resource(struct wined3d_ } HRESULT CDECL wined3d_texture_add_dirty_region(struct wined3d_texture *texture, - UINT layer, const WINED3DBOX *dirty_region) + UINT layer, const struct wined3d_box *dirty_region) { struct wined3d_resource *sub_resource; @@ -607,23 +589,23 @@ HRESULT CDECL wined3d_texture_add_dirty_region(struct wined3d_texture *texture, /* Context activation is done by the caller. */ static HRESULT texture2d_bind(struct wined3d_texture *texture, - const struct wined3d_gl_info *gl_info, BOOL srgb) + struct wined3d_context *context, BOOL srgb) { BOOL set_gl_texture_desc; HRESULT hr; - TRACE("texture %p, gl_info %p, srgb %#x.\n", texture, gl_info, srgb); + TRACE("texture %p, context %p, srgb %#x.\n", texture, context, srgb); - hr = wined3d_texture_bind(texture, gl_info, srgb, &set_gl_texture_desc); + hr = wined3d_texture_bind(texture, context, srgb, &set_gl_texture_desc); if (set_gl_texture_desc && SUCCEEDED(hr)) { UINT sub_count = texture->level_count * texture->layer_count; - BOOL srgb_tex = !gl_info->supported[EXT_TEXTURE_SRGB_DECODE] + BOOL srgb_tex = !context->gl_info->supported[EXT_TEXTURE_SRGB_DECODE] && (texture->flags & WINED3D_TEXTURE_IS_SRGB); struct gl_texture *gl_tex; UINT i; - gl_tex = wined3d_texture_get_gl_texture(texture, gl_info, srgb_tex); + gl_tex = wined3d_texture_get_gl_texture(texture, context->gl_info, srgb_tex); for (i = 0; i < sub_count; ++i) { @@ -653,18 +635,18 @@ static HRESULT texture2d_bind(struct wined3d_texture *texture, glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); checkGLcall("glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)"); LEAVE_GL(); - gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_CLAMP; - gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_CLAMP; - gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT; - gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT; - gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE; + gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3D_TADDRESS_CLAMP; + gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3D_TADDRESS_CLAMP; + gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3D_TEXF_POINT; + gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3D_TEXF_POINT; + gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3D_TEXF_NONE; } } return hr; } -static BOOL texture_srgb_mode(struct wined3d_texture *texture, enum WINED3DSRGB srgb) +static BOOL texture_srgb_mode(const struct wined3d_texture *texture, enum WINED3DSRGB srgb) { switch (srgb) { @@ -702,25 +684,6 @@ static void texture2d_preload(struct wined3d_texture *texture, enum WINED3DSRGB context = context_acquire(device, NULL); } - if (texture->resource.format->id == WINED3DFMT_P8_UINT - || texture->resource.format->id == WINED3DFMT_P8_UINT_A8_UNORM) - { - for (i = 0; i < sub_count; ++i) - { - struct wined3d_surface *surface = surface_from_resource(texture->sub_resources[i]); - - if (palette9_changed(surface)) - { - TRACE("Reloading surface %p because the d3d8/9 palette was changed.\n", surface); - /* TODO: This is not necessarily needed with hw palettized texture support. */ - surface_load_location(surface, SFLAG_INSYSMEM, NULL); - /* Make sure the texture is reloaded because of the palette - * change, this kills performance though :( */ - surface_modify_location(surface, SFLAG_INTEXTURE, FALSE); - } - } - } - if (gl_tex->dirty) { /* Reload the surfaces if the texture is marked dirty. */ @@ -741,7 +704,7 @@ static void texture2d_preload(struct wined3d_texture *texture, enum WINED3DSRGB } static void texture2d_sub_resource_add_dirty_region(struct wined3d_resource *sub_resource, - const WINED3DBOX *dirty_region) + const struct wined3d_box *dirty_region) { surface_add_dirty_rect(surface_from_resource(sub_resource), dirty_region); } @@ -795,7 +758,7 @@ static const struct wined3d_resource_ops texture2d_resource_ops = }; static HRESULT cubetexture_init(struct wined3d_texture *texture, UINT edge_length, UINT levels, - struct wined3d_device *device, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool, + struct wined3d_device *device, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops) { const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; @@ -813,7 +776,7 @@ static HRESULT cubetexture_init(struct wined3d_texture *texture, UINT edge_lengt return WINED3DERR_INVALIDCALL; } - if (!gl_info->supported[ARB_TEXTURE_CUBE_MAP] && pool != WINED3DPOOL_SCRATCH) + if (!gl_info->supported[ARB_TEXTURE_CUBE_MAP] && pool != WINED3D_POOL_SCRATCH) { WARN("(%p) : Tried to create not supported cube texture.\n", texture); return WINED3DERR_INVALIDCALL; @@ -843,7 +806,7 @@ static HRESULT cubetexture_init(struct wined3d_texture *texture, UINT edge_lengt } hr = wined3d_texture_init(texture, &texture2d_ops, 6, levels, - WINED3DRTYPE_CUBETEXTURE, device, usage, format, pool, + WINED3D_RTYPE_CUBE_TEXTURE, device, usage, format, pool, parent, parent_ops, &texture2d_resource_ops); if (FAILED(hr)) { @@ -914,7 +877,7 @@ static HRESULT cubetexture_init(struct wined3d_texture *texture, UINT edge_lengt } static HRESULT texture_init(struct wined3d_texture *texture, UINT width, UINT height, UINT levels, - struct wined3d_device *device, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool, + struct wined3d_device *device, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops) { const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; @@ -980,7 +943,7 @@ static HRESULT texture_init(struct wined3d_texture *texture, UINT width, UINT he } hr = wined3d_texture_init(texture, &texture2d_ops, 1, levels, - WINED3DRTYPE_TEXTURE, device, usage, format, pool, + WINED3D_RTYPE_TEXTURE, device, usage, format, pool, parent, parent_ops, &texture2d_resource_ops); if (FAILED(hr)) { @@ -1072,28 +1035,28 @@ static HRESULT texture_init(struct wined3d_texture *texture, UINT width, UINT he /* Context activation is done by the caller. */ static HRESULT texture3d_bind(struct wined3d_texture *texture, - const struct wined3d_gl_info *gl_info, BOOL srgb) + struct wined3d_context *context, BOOL srgb) { BOOL dummy; - TRACE("texture %p, gl_info %p, srgb %#x.\n", texture, gl_info, srgb); + TRACE("texture %p, context %p, srgb %#x.\n", texture, context, srgb); - return wined3d_texture_bind(texture, gl_info, srgb, &dummy); + return wined3d_texture_bind(texture, context, srgb, &dummy); } /* Do not call while under the GL lock. */ static void texture3d_preload(struct wined3d_texture *texture, enum WINED3DSRGB srgb) { struct wined3d_device *device = texture->resource.device; - struct wined3d_context *context = NULL; + struct wined3d_context *context; BOOL srgb_was_toggled = FALSE; unsigned int i; TRACE("texture %p, srgb %#x.\n", texture, srgb); - if (!device->isInDraw) - context = context_acquire(device, NULL); - else if (texture->bind_count > 0) + /* TODO: Use already acquired context when possible. */ + context = context_acquire(device, NULL); + if (texture->bind_count > 0) { BOOL texture_srgb = texture->flags & WINED3D_TEXTURE_IS_SRGB; BOOL sampler_srgb = texture_srgb_mode(texture, srgb); @@ -1114,7 +1077,7 @@ static void texture3d_preload(struct wined3d_texture *texture, enum WINED3DSRGB { for (i = 0; i < texture->level_count; ++i) { - volume_load(volume_from_resource(texture->sub_resources[i]), i, + volume_load(volume_from_resource(texture->sub_resources[i]), context, i, texture->flags & WINED3D_TEXTURE_IS_SRGB); } } @@ -1124,7 +1087,7 @@ static void texture3d_preload(struct wined3d_texture *texture, enum WINED3DSRGB { struct wined3d_volume *volume = volume_from_resource(texture->sub_resources[i]); volume_add_dirty_box(volume, NULL); - volume_load(volume, i, texture->flags & WINED3D_TEXTURE_IS_SRGB); + volume_load(volume, context, i, texture->flags & WINED3D_TEXTURE_IS_SRGB); } } else @@ -1132,15 +1095,14 @@ static void texture3d_preload(struct wined3d_texture *texture, enum WINED3DSRGB TRACE("Texture %p not dirty, nothing to do.\n", texture); } - if (context) - context_release(context); + context_release(context); /* No longer dirty */ texture->texture_rgb.dirty = FALSE; } static void texture3d_sub_resource_add_dirty_region(struct wined3d_resource *sub_resource, - const WINED3DBOX *dirty_region) + const struct wined3d_box *dirty_region) { volume_add_dirty_box(volume_from_resource(sub_resource), dirty_region); } @@ -1186,7 +1148,7 @@ static const struct wined3d_resource_ops texture3d_resource_ops = static HRESULT volumetexture_init(struct wined3d_texture *texture, UINT width, UINT height, UINT depth, UINT levels, struct wined3d_device *device, DWORD usage, enum wined3d_format_id format_id, - WINED3DPOOL pool, void *parent, const struct wined3d_parent_ops *parent_ops) + enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops) { const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; const struct wined3d_format *format = wined3d_get_format(gl_info, format_id); @@ -1232,7 +1194,7 @@ static HRESULT volumetexture_init(struct wined3d_texture *texture, UINT width, U } hr = wined3d_texture_init(texture, &texture3d_ops, 1, levels, - WINED3DRTYPE_VOLUMETEXTURE, device, usage, format, pool, + WINED3D_RTYPE_VOLUME_TEXTURE, device, usage, format, pool, parent, parent_ops, &texture3d_resource_ops); if (FAILED(hr)) { @@ -1280,7 +1242,7 @@ static HRESULT volumetexture_init(struct wined3d_texture *texture, UINT width, U } HRESULT CDECL wined3d_texture_create_2d(struct wined3d_device *device, UINT width, UINT height, - UINT level_count, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool, void *parent, + UINT level_count, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture) { struct wined3d_texture *object; @@ -1316,7 +1278,7 @@ HRESULT CDECL wined3d_texture_create_2d(struct wined3d_device *device, UINT widt } HRESULT CDECL wined3d_texture_create_3d(struct wined3d_device *device, UINT width, UINT height, UINT depth, - UINT level_count, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool, void *parent, + UINT level_count, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture) { struct wined3d_texture *object; @@ -1352,7 +1314,7 @@ HRESULT CDECL wined3d_texture_create_3d(struct wined3d_device *device, UINT widt } HRESULT CDECL wined3d_texture_create_cube(struct wined3d_device *device, UINT edge_length, - UINT level_count, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool, void *parent, + UINT level_count, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture) { struct wined3d_texture *object; diff --git a/reactos/dll/directx/wine/wined3d/utils.c b/reactos/dll/directx/wine/wined3d/utils.c index 25c0512ccc0..35775df5129 100644 --- a/reactos/dll/directx/wine/wined3d/utils.c +++ b/reactos/dll/directx/wine/wined3d/utils.c @@ -134,6 +134,9 @@ static const struct StaticPixelFormatDesc formats[] = {WINED3DFMT_NVHU, 0x0, 0x0, 0x0, 0x0, 2, 0, 0}, {WINED3DFMT_NVHS, 0x0, 0x0, 0x0, 0x0, 2, 0, 0}, {WINED3DFMT_NULL, 0xff000000, 0x000000ff, 0x0000ff00, 0x00ff0000, 4, 0, 0}, + /* Unsure about them, could not find a Windows driver that supports them */ + {WINED3DFMT_R16, 0x0, 0x0000ffff, 0x0, 0x0, 2, 0, 0}, + {WINED3DFMT_AL16, 0xffff0000, 0x0, 0x0, 0x0, 4, 0, 0}, }; struct wined3d_format_base_flags @@ -186,7 +189,7 @@ static const struct wined3d_format_base_flags format_base_flags[] = {WINED3DFMT_S8_UINT_D24_FLOAT, WINED3DFMT_FLAG_FLOAT}, }; -struct wined3d_format_compression_info +struct wined3d_format_block_info { enum wined3d_format_id id; UINT block_width; @@ -194,7 +197,7 @@ struct wined3d_format_compression_info UINT block_byte_count; }; -static const struct wined3d_format_compression_info format_compression_info[] = +static const struct wined3d_format_block_info format_block_info[] = { {WINED3DFMT_DXT1, 4, 4, 8}, {WINED3DFMT_DXT2, 4, 4, 16}, @@ -202,6 +205,8 @@ static const struct wined3d_format_compression_info format_compression_info[] = {WINED3DFMT_DXT4, 4, 4, 16}, {WINED3DFMT_DXT5, 4, 4, 16}, {WINED3DFMT_ATI2N, 4, 4, 16}, + {WINED3DFMT_YUY2, 2, 1, 4}, + {WINED3DFMT_UYVY, 2, 1, 4}, }; struct wined3d_format_vertex_info @@ -246,7 +251,7 @@ struct wined3d_format_texture_info GLint gl_type; unsigned int conv_byte_count; unsigned int flags; - GL_SupportedExt extension; + enum wined3d_gl_extension extension; void (*convert)(const BYTE *src, BYTE *dst, UINT pitch, UINT width, UINT height); }; @@ -566,7 +571,7 @@ static const struct wined3d_format_texture_info format_texture_info[] = /* GL_APPLE_ycbcr_422 claims that its '2YUV' format, which is supported via the UNSIGNED_SHORT_8_8_REV_APPLE type * is equivalent to 'UYVY' format on Windows, and the 'YUVS' via UNSIGNED_SHORT_8_8_APPLE equates to 'YUY2'. The * d3d9 test however shows that the opposite is true. Since the extension is from 2002, it predates the x86 based - * Macs, so probably the endianess differs. This could be tested as soon as we have a Windows and MacOS on a big + * Macs, so probably the endianness differs. This could be tested as soon as we have a Windows and MacOS on a big * endian machine */ {WINED3DFMT_UYVY, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, 0, @@ -591,40 +596,45 @@ static const struct wined3d_format_texture_info format_texture_info[] = WINED3D_GL_EXT_NONE, NULL}, {WINED3DFMT_DXT1, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, - WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_SRGB_READ, + WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_SRGB_READ + | WINED3DFMT_FLAG_COMPRESSED, EXT_TEXTURE_COMPRESSION_S3TC, NULL}, {WINED3DFMT_DXT2, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, - WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_SRGB_READ, + WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_SRGB_READ + | WINED3DFMT_FLAG_COMPRESSED, EXT_TEXTURE_COMPRESSION_S3TC, NULL}, {WINED3DFMT_DXT3, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, - WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_SRGB_READ, + WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_SRGB_READ + | WINED3DFMT_FLAG_COMPRESSED, EXT_TEXTURE_COMPRESSION_S3TC, NULL}, {WINED3DFMT_DXT4, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, - WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_SRGB_READ, + WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_SRGB_READ + | WINED3DFMT_FLAG_COMPRESSED, EXT_TEXTURE_COMPRESSION_S3TC, NULL}, {WINED3DFMT_DXT5, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, - WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_SRGB_READ, + WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_SRGB_READ + | WINED3DFMT_FLAG_COMPRESSED, EXT_TEXTURE_COMPRESSION_S3TC, NULL}, /* IEEE formats */ {WINED3DFMT_R32_FLOAT, GL_RGB32F_ARB, GL_RGB32F_ARB, 0, GL_RED, GL_FLOAT, 0, - WINED3DFMT_FLAG_RENDERTARGET, + WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF, ARB_TEXTURE_FLOAT, NULL}, {WINED3DFMT_R32_FLOAT, GL_R32F, GL_R32F, 0, GL_RED, GL_FLOAT, 0, - WINED3DFMT_FLAG_RENDERTARGET, + WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF, ARB_TEXTURE_RG, NULL}, {WINED3DFMT_R32G32_FLOAT, GL_RGB32F_ARB, GL_RGB32F_ARB, 0, GL_RGB, GL_FLOAT, 12, - WINED3DFMT_FLAG_RENDERTARGET, - ARB_TEXTURE_FLOAT, &convert_r32g32_float}, + WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF, + ARB_TEXTURE_FLOAT, convert_r32g32_float}, {WINED3DFMT_R32G32_FLOAT, GL_RG32F, GL_RG32F, 0, GL_RG, GL_FLOAT, 0, - WINED3DFMT_FLAG_RENDERTARGET, + WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF, ARB_TEXTURE_RG, NULL}, {WINED3DFMT_R32G32B32A32_FLOAT, GL_RGBA32F_ARB, GL_RGBA32F_ARB, 0, GL_RGBA, GL_FLOAT, 0, @@ -633,23 +643,23 @@ static const struct wined3d_format_texture_info format_texture_info[] = /* Float */ {WINED3DFMT_R16_FLOAT, GL_RGB16F_ARB, GL_RGB16F_ARB, 0, GL_RED, GL_HALF_FLOAT_ARB, 0, - WINED3DFMT_FLAG_RENDERTARGET, + WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF, ARB_TEXTURE_FLOAT, NULL}, {WINED3DFMT_R16_FLOAT, GL_R16F, GL_R16F, 0, GL_RED, GL_HALF_FLOAT_ARB, 0, - WINED3DFMT_FLAG_RENDERTARGET, + WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF, ARB_TEXTURE_RG, NULL}, {WINED3DFMT_R16G16_FLOAT, GL_RGB16F_ARB, GL_RGB16F_ARB, 0, GL_RGB, GL_HALF_FLOAT_ARB, 6, - WINED3DFMT_FLAG_RENDERTARGET, - ARB_TEXTURE_FLOAT, &convert_r16g16}, + WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF, + ARB_TEXTURE_FLOAT, convert_r16g16}, {WINED3DFMT_R16G16_FLOAT, GL_RG16F, GL_RG16F, 0, GL_RG, GL_HALF_FLOAT_ARB, 0, - WINED3DFMT_FLAG_RENDERTARGET, + WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF, ARB_TEXTURE_RG, NULL}, {WINED3DFMT_R16G16B16A16_FLOAT, GL_RGBA16F_ARB, GL_RGBA16F_ARB, 0, GL_RGBA, GL_HALF_FLOAT_ARB, 0, - WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_RENDERTARGET, + WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF, ARB_TEXTURE_FLOAT, NULL}, /* Palettized formats */ {WINED3DFMT_P8_UINT, GL_RGBA, GL_RGBA, 0, @@ -668,7 +678,7 @@ static const struct wined3d_format_texture_info format_texture_info[] = {WINED3DFMT_B8G8R8A8_UNORM, GL_RGBA8, GL_SRGB8_ALPHA8_EXT, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0, WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET - | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE, + | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE | WINED3DFMT_FLAG_VTF, WINED3D_GL_EXT_NONE, NULL}, {WINED3DFMT_B8G8R8X8_UNORM, GL_RGB8, GL_SRGB8_EXT, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0, @@ -693,11 +703,11 @@ static const struct wined3d_format_texture_info format_texture_info[] = WINED3D_GL_EXT_NONE, NULL}, {WINED3DFMT_B2G3R3_UNORM, GL_R3_G3_B2, GL_R3_G3_B2, 0, GL_RGB, GL_UNSIGNED_BYTE_3_3_2, 0, - WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING, + WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING, WINED3D_GL_EXT_NONE, NULL}, {WINED3DFMT_A8_UNORM, GL_ALPHA8, GL_ALPHA8, 0, GL_ALPHA, GL_UNSIGNED_BYTE, 0, - WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING, + WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING, WINED3D_GL_EXT_NONE, NULL}, {WINED3DFMT_B4G4R4X4_UNORM, GL_RGB4, GL_RGB4, 0, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV, 0, @@ -705,7 +715,7 @@ static const struct wined3d_format_texture_info format_texture_info[] = WINED3D_GL_EXT_NONE, NULL}, {WINED3DFMT_R10G10B10A2_UNORM, GL_RGB10_A2, GL_RGB10_A2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, 0, - WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING, + WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET, WINED3D_GL_EXT_NONE, NULL}, {WINED3DFMT_R8G8B8A8_UNORM, GL_RGBA8, GL_RGBA8, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0, @@ -718,10 +728,10 @@ static const struct wined3d_format_texture_info format_texture_info[] = {WINED3DFMT_R16G16_UNORM, GL_RGB16, GL_RGB16, GL_RGBA16, GL_RGB, GL_UNSIGNED_SHORT, 6, WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING, - WINED3D_GL_EXT_NONE, &convert_r16g16}, + WINED3D_GL_EXT_NONE, convert_r16g16}, {WINED3DFMT_B10G10R10A2_UNORM, GL_RGB10_A2, GL_RGB10_A2, 0, GL_BGRA, GL_UNSIGNED_INT_2_10_10_10_REV, 0, - WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING, + WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET, WINED3D_GL_EXT_NONE, NULL}, {WINED3DFMT_R16G16B16A16_UNORM, GL_RGBA16, GL_RGBA16, 0, GL_RGBA, GL_UNSIGNED_SHORT, 0, @@ -738,13 +748,13 @@ static const struct wined3d_format_texture_info format_texture_info[] = WINED3D_GL_EXT_NONE, NULL}, {WINED3DFMT_L4A4_UNORM, GL_LUMINANCE4_ALPHA4, GL_LUMINANCE4_ALPHA4, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 2, - 0, - WINED3D_GL_EXT_NONE, &convert_l4a4_unorm}, + WINED3DFMT_FLAG_FILTERING, + WINED3D_GL_EXT_NONE, convert_l4a4_unorm}, /* Bump mapping stuff */ {WINED3DFMT_R8G8_SNORM, GL_RGB8, GL_RGB8, 0, GL_BGR, GL_UNSIGNED_BYTE, 3, WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_BUMPMAP, - WINED3D_GL_EXT_NONE, &convert_r8g8_snorm}, + WINED3D_GL_EXT_NONE, convert_r8g8_snorm}, {WINED3DFMT_R8G8_SNORM, GL_DSDT8_NV, GL_DSDT8_NV, 0, GL_DSDT_NV, GL_BYTE, 0, WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_BUMPMAP, @@ -752,23 +762,23 @@ static const struct wined3d_format_texture_info format_texture_info[] = {WINED3DFMT_R5G5_SNORM_L6_UNORM, GL_RGB5, GL_RGB5, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 2, WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_BUMPMAP, - WINED3D_GL_EXT_NONE, &convert_r5g5_snorm_l6_unorm}, + WINED3D_GL_EXT_NONE, convert_r5g5_snorm_l6_unorm}, {WINED3DFMT_R5G5_SNORM_L6_UNORM, GL_DSDT8_MAG8_NV, GL_DSDT8_MAG8_NV, 0, GL_DSDT_MAG_NV, GL_BYTE, 3, WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_BUMPMAP, - NV_TEXTURE_SHADER, &convert_r5g5_snorm_l6_unorm_nv}, + NV_TEXTURE_SHADER, convert_r5g5_snorm_l6_unorm_nv}, {WINED3DFMT_R8G8_SNORM_L8X8_UNORM, GL_RGB8, GL_RGB8, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 4, WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_BUMPMAP, - WINED3D_GL_EXT_NONE, &convert_r8g8_snorm_l8x8_unorm}, + WINED3D_GL_EXT_NONE, convert_r8g8_snorm_l8x8_unorm}, {WINED3DFMT_R8G8_SNORM_L8X8_UNORM, GL_DSDT8_MAG8_INTENSITY8_NV, GL_DSDT8_MAG8_INTENSITY8_NV, 0, GL_DSDT_MAG_VIB_NV, GL_UNSIGNED_INT_8_8_S8_S8_REV_NV, 4, WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_BUMPMAP, - NV_TEXTURE_SHADER, &convert_r8g8_snorm_l8x8_unorm_nv}, + NV_TEXTURE_SHADER, convert_r8g8_snorm_l8x8_unorm_nv}, {WINED3DFMT_R8G8B8A8_SNORM, GL_RGBA8, GL_RGBA8, 0, GL_BGRA, GL_UNSIGNED_BYTE, 4, WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_BUMPMAP, - WINED3D_GL_EXT_NONE, &convert_r8g8b8a8_snorm}, + WINED3D_GL_EXT_NONE, convert_r8g8b8a8_snorm}, {WINED3DFMT_R8G8B8A8_SNORM, GL_SIGNED_RGBA8_NV, GL_SIGNED_RGBA8_NV, 0, GL_RGBA, GL_BYTE, 0, WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_BUMPMAP, @@ -776,7 +786,7 @@ static const struct wined3d_format_texture_info format_texture_info[] = {WINED3DFMT_R16G16_SNORM, GL_RGB16, GL_RGB16, 0, GL_BGR, GL_UNSIGNED_SHORT, 6, WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_BUMPMAP, - WINED3D_GL_EXT_NONE, &convert_r16g16_snorm}, + WINED3D_GL_EXT_NONE, convert_r16g16_snorm}, {WINED3DFMT_R16G16_SNORM, GL_SIGNED_HILO16_NV, GL_SIGNED_HILO16_NV, 0, GL_HILO_NV, GL_SHORT, 0, WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_BUMPMAP, @@ -797,11 +807,11 @@ static const struct wined3d_format_texture_info format_texture_info[] = {WINED3DFMT_S1_UINT_D15_UNORM, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH24_STENCIL8_EXT, 0, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, 4, WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW, - EXT_PACKED_DEPTH_STENCIL, &convert_s1_uint_d15_unorm}, + EXT_PACKED_DEPTH_STENCIL, convert_s1_uint_d15_unorm}, {WINED3DFMT_S1_UINT_D15_UNORM, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 4, WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW, - ARB_FRAMEBUFFER_OBJECT, &convert_s1_uint_d15_unorm}, + ARB_FRAMEBUFFER_OBJECT, convert_s1_uint_d15_unorm}, {WINED3DFMT_D24_UNORM_S8_UINT, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0, WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_DEPTH @@ -829,11 +839,11 @@ static const struct wined3d_format_texture_info format_texture_info[] = {WINED3DFMT_S4X4_UINT_D24_UNORM, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH24_STENCIL8_EXT, 0, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, 4, WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW, - EXT_PACKED_DEPTH_STENCIL, &convert_s4x4_uint_d24_unorm}, + EXT_PACKED_DEPTH_STENCIL, convert_s4x4_uint_d24_unorm}, {WINED3DFMT_S4X4_UINT_D24_UNORM, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 4, WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW, - ARB_FRAMEBUFFER_OBJECT, &convert_s4x4_uint_d24_unorm}, + ARB_FRAMEBUFFER_OBJECT, convert_s4x4_uint_d24_unorm}, {WINED3DFMT_D16_UNORM, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0, WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_DEPTH @@ -850,15 +860,15 @@ static const struct wined3d_format_texture_info format_texture_info[] = {WINED3DFMT_S8_UINT_D24_FLOAT, GL_DEPTH32F_STENCIL8, GL_DEPTH32F_STENCIL8, 0, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, 8, WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW, - ARB_DEPTH_BUFFER_FLOAT, &convert_s8_uint_d24_float}, + ARB_DEPTH_BUFFER_FLOAT, convert_s8_uint_d24_float}, /* Vendor-specific formats */ {WINED3DFMT_ATI2N, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0, - WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING, + WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_COMPRESSED, ATI_TEXTURE_COMPRESSION_3DC, NULL}, {WINED3DFMT_ATI2N, GL_COMPRESSED_RED_GREEN_RGTC2, GL_COMPRESSED_RED_GREEN_RGTC2, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0, - WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING, + WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_COMPRESSED, ARB_TEXTURE_COMPRESSION_RGTC, NULL}, {WINED3DFMT_INTZ, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH24_STENCIL8_EXT, 0, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, 0, @@ -920,6 +930,9 @@ static BOOL init_format_base_info(struct wined3d_gl_info *gl_info) format->byte_count = formats[i].bpp; format->depth_size = formats[i].depthSize; format->stencil_size = formats[i].stencilSize; + format->block_width = 1; + format->block_height = 1; + format->block_byte_count = formats[i].bpp; } for (i = 0; i < (sizeof(format_base_flags) / sizeof(*format_base_flags)); ++i) @@ -940,27 +953,27 @@ static BOOL init_format_base_info(struct wined3d_gl_info *gl_info) return TRUE; } -static BOOL init_format_compression_info(struct wined3d_gl_info *gl_info) +static BOOL init_format_block_info(struct wined3d_gl_info *gl_info) { unsigned int i; - for (i = 0; i < (sizeof(format_compression_info) / sizeof(*format_compression_info)); ++i) + for (i = 0; i < (sizeof(format_block_info) / sizeof(*format_block_info)); ++i) { struct wined3d_format *format; - int fmt_idx = getFmtIdx(format_compression_info[i].id); + int fmt_idx = getFmtIdx(format_block_info[i].id); if (fmt_idx == -1) { ERR("Format %s (%#x) not found.\n", - debug_d3dformat(format_compression_info[i].id), format_compression_info[i].id); + debug_d3dformat(format_block_info[i].id), format_block_info[i].id); return FALSE; } format = &gl_info->formats[fmt_idx]; - format->block_width = format_compression_info[i].block_width; - format->block_height = format_compression_info[i].block_height; - format->block_byte_count = format_compression_info[i].block_byte_count; - format->flags |= WINED3DFMT_FLAG_COMPRESSED; + format->block_width = format_block_info[i].block_width; + format->block_height = format_block_info[i].block_height; + format->block_byte_count = format_block_info[i].block_byte_count; + format->flags |= WINED3DFMT_FLAG_BLOCKS; } return TRUE; @@ -1047,9 +1060,15 @@ static void check_fbo_compat(const struct wined3d_gl_info *gl_info, struct wined } } - if (status == GL_FRAMEBUFFER_COMPLETE && format->flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING) + if (status == GL_FRAMEBUFFER_COMPLETE && ((format->flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING) + || !(gl_info->quirks & WINED3D_QUIRK_LIMITED_TEX_FILTERING)) + && format->id != WINED3DFMT_NULL && format->id != WINED3DFMT_P8_UINT + && format->glFormat != GL_LUMINANCE && format->glFormat != GL_LUMINANCE_ALPHA) { - GLuint rb; + GLuint rb, tex2; + DWORD readback[16 * 16], color; + BYTE r, a; + BOOL match = TRUE; if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT] || gl_info->supported[EXT_PACKED_DEPTH_STENCIL]) @@ -1063,6 +1082,7 @@ static void check_fbo_compat(const struct wined3d_gl_info *gl_info, struct wined } glEnable(GL_BLEND); + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); if (glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION) { @@ -1070,6 +1090,72 @@ static void check_fbo_compat(const struct wined3d_gl_info *gl_info, struct wined TRACE("Format doesn't support post-pixelshader blending.\n"); format->flags &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING; } + else + { + glViewport(0, 0, 16, 16); + glDisable(GL_LIGHTING); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + /* Draw a full-black quad */ + glBegin(GL_TRIANGLE_STRIP); + glColor4ub(0x00, 0x00, 0x00, 0xff); + glVertex3f(-1.0f, -1.0f, 0.0f); + glColor4ub(0x00, 0x00, 0x00, 0xff); + glVertex3f(1.0f, -1.0f, 0.0f); + glColor4ub(0x00, 0x00, 0x00, 0xff); + glVertex3f(-1.0f, 1.0f, 0.0f); + glColor4ub(0x00, 0x00, 0x00, 0xff); + glVertex3f(1.0f, 1.0f, 0.0f); + glEnd(); + + /* Draw a half-transparent red quad */ + glBegin(GL_TRIANGLE_STRIP); + glColor4ub(0xff, 0x00, 0x00, 0x80); + glVertex3f(-1.0f, -1.0f, 0.0f); + glColor4ub(0xff, 0x00, 0x00, 0x80); + glVertex3f(1.0f, -1.0f, 0.0f); + glColor4ub(0xff, 0x00, 0x00, 0x80); + glVertex3f(-1.0f, 1.0f, 0.0f); + glColor4ub(0xff, 0x00, 0x00, 0x80); + glVertex3f(1.0f, 1.0f, 0.0f); + glEnd(); + + glGenTextures(1, &tex2); + glBindTexture(GL_TEXTURE_2D, tex2); + + glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, 16, 16, 0); + glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, readback); + checkGLcall("Post-pixelshader blending check"); + + color = readback[7 * 16 + 7]; + a = color >> 24; + r = (color & 0x00ff0000) >> 16; + + if (format->red_mask && (r < 0x7b || r > 0x84)) + match = FALSE; + /* If the alpha component is more than 1 bit */ + else if ((format->alpha_mask & (format->alpha_mask - 1)) && (a < 0x9f || a > 0xdf)) + match = FALSE; + if (!match) + { + TRACE("Format doesn't support post-pixelshader blending.\n"); + TRACE("Color output: %#x\n", color); + format->flags &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING; + } + else + { + TRACE("Format supports post-pixelshader blending.\n"); + format->flags |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING; + } + + glBindTexture(GL_TEXTURE_2D, tex); + glDeleteTextures(1, &tex2); + } if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT] || gl_info->supported[EXT_PACKED_DEPTH_STENCIL]) @@ -1099,6 +1185,8 @@ static void check_fbo_compat(const struct wined3d_gl_info *gl_info, struct wined WARN("Format %s's sRGB format is not FBO attachable.\n", debug_d3dformat(format->id)); } } + else if (status == GL_FRAMEBUFFER_COMPLETE) + format->flags |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB; glDeleteTextures(1, &tex); @@ -1117,6 +1205,8 @@ static void init_format_fbo_compat_info(struct wined3d_gl_info *gl_info) gl_info->fbo_ops.glGenFramebuffers(1, &fbo); gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo); + glDrawBuffer(GL_COLOR_ATTACHMENT0); + glReadBuffer(GL_COLOR_ATTACHMENT0); LEAVE_GL(); } @@ -1549,7 +1639,7 @@ BOOL initPixelFormatsNoGL(struct wined3d_gl_info *gl_info) { if (!init_format_base_info(gl_info)) return FALSE; - if (!init_format_compression_info(gl_info)) + if (!init_format_block_info(gl_info)) { HeapFree(GetProcessHeap(), 0, gl_info->formats); gl_info->formats = NULL; @@ -1564,7 +1654,7 @@ BOOL initPixelFormats(struct wined3d_gl_info *gl_info, enum wined3d_pci_vendor v { if (!init_format_base_info(gl_info)) return FALSE; - if (!init_format_compression_info(gl_info)) goto fail; + if (!init_format_block_info(gl_info)) goto fail; if (!init_format_texture_info(gl_info)) goto fail; if (!init_format_vertex_info(gl_info)) goto fail; @@ -1604,7 +1694,7 @@ UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT ali { size = 0; } - else if (format->flags & WINED3DFMT_FLAG_COMPRESSED) + else if (format->flags & WINED3DFMT_FLAG_BLOCKS) { UINT row_block_count = (width + format->block_width - 1) / format->block_width; UINT row_count = (height + format->block_height - 1) / format->block_height; @@ -1765,6 +1855,8 @@ const char *debug_d3dformat(enum wined3d_format_id format_id) FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM); FMT_TO_STR(WINED3DFMT_INTZ); FMT_TO_STR(WINED3DFMT_NULL); + FMT_TO_STR(WINED3DFMT_R16); + FMT_TO_STR(WINED3DFMT_AL16); #undef FMT_TO_STR default: { @@ -1783,17 +1875,17 @@ const char *debug_d3dformat(enum wined3d_format_id format_id) } } -const char *debug_d3ddevicetype(WINED3DDEVTYPE devtype) +const char *debug_d3ddevicetype(enum wined3d_device_type device_type) { - switch (devtype) + switch (device_type) { #define DEVTYPE_TO_STR(dev) case dev: return #dev - DEVTYPE_TO_STR(WINED3DDEVTYPE_HAL); - DEVTYPE_TO_STR(WINED3DDEVTYPE_REF); - DEVTYPE_TO_STR(WINED3DDEVTYPE_SW); + DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_HAL); + DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_REF); + DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_SW); #undef DEVTYPE_TO_STR default: - FIXME("Unrecognized %u WINED3DDEVTYPE!\n", devtype); + FIXME("Unrecognized device type %#x.\n", device_type); return "unrecognized"; } } @@ -1883,178 +1975,178 @@ const char* debug_d3ddeclusage(BYTE usage) { } } -const char *debug_d3dresourcetype(WINED3DRESOURCETYPE res) +const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type) { - switch (res) + switch (resource_type) { #define RES_TO_STR(res) case res: return #res - RES_TO_STR(WINED3DRTYPE_SURFACE); - RES_TO_STR(WINED3DRTYPE_VOLUME); - RES_TO_STR(WINED3DRTYPE_TEXTURE); - RES_TO_STR(WINED3DRTYPE_VOLUMETEXTURE); - RES_TO_STR(WINED3DRTYPE_CUBETEXTURE); - RES_TO_STR(WINED3DRTYPE_BUFFER); + RES_TO_STR(WINED3D_RTYPE_SURFACE); + RES_TO_STR(WINED3D_RTYPE_VOLUME); + RES_TO_STR(WINED3D_RTYPE_TEXTURE); + RES_TO_STR(WINED3D_RTYPE_VOLUME_TEXTURE); + RES_TO_STR(WINED3D_RTYPE_CUBE_TEXTURE); + RES_TO_STR(WINED3D_RTYPE_BUFFER); #undef RES_TO_STR default: - FIXME("Unrecognized %u WINED3DRESOURCETYPE!\n", res); + FIXME("Unrecognized resource type %#x.\n", resource_type); return "unrecognized"; } } -const char *debug_d3dprimitivetype(WINED3DPRIMITIVETYPE PrimitiveType) +const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type) { - switch (PrimitiveType) + switch (primitive_type) { #define PRIM_TO_STR(prim) case prim: return #prim - PRIM_TO_STR(WINED3DPT_UNDEFINED); - PRIM_TO_STR(WINED3DPT_POINTLIST); - PRIM_TO_STR(WINED3DPT_LINELIST); - PRIM_TO_STR(WINED3DPT_LINESTRIP); - PRIM_TO_STR(WINED3DPT_TRIANGLELIST); - PRIM_TO_STR(WINED3DPT_TRIANGLESTRIP); - PRIM_TO_STR(WINED3DPT_TRIANGLEFAN); - PRIM_TO_STR(WINED3DPT_LINELIST_ADJ); - PRIM_TO_STR(WINED3DPT_LINESTRIP_ADJ); - PRIM_TO_STR(WINED3DPT_TRIANGLELIST_ADJ); - PRIM_TO_STR(WINED3DPT_TRIANGLESTRIP_ADJ); + PRIM_TO_STR(WINED3D_PT_UNDEFINED); + PRIM_TO_STR(WINED3D_PT_POINTLIST); + PRIM_TO_STR(WINED3D_PT_LINELIST); + PRIM_TO_STR(WINED3D_PT_LINESTRIP); + PRIM_TO_STR(WINED3D_PT_TRIANGLELIST); + PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP); + PRIM_TO_STR(WINED3D_PT_TRIANGLEFAN); + PRIM_TO_STR(WINED3D_PT_LINELIST_ADJ); + PRIM_TO_STR(WINED3D_PT_LINESTRIP_ADJ); + PRIM_TO_STR(WINED3D_PT_TRIANGLELIST_ADJ); + PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP_ADJ); #undef PRIM_TO_STR default: - FIXME("Unrecognized %u WINED3DPRIMITIVETYPE!\n", PrimitiveType); + FIXME("Unrecognized %u primitive type!\n", primitive_type); return "unrecognized"; } } -const char *debug_d3drenderstate(WINED3DRENDERSTATETYPE state) +const char *debug_d3drenderstate(enum wined3d_render_state state) { switch (state) { #define D3DSTATE_TO_STR(u) case u: return #u - D3DSTATE_TO_STR(WINED3DRS_ANTIALIAS); - D3DSTATE_TO_STR(WINED3DRS_TEXTUREPERSPECTIVE); - D3DSTATE_TO_STR(WINED3DRS_WRAPU); - D3DSTATE_TO_STR(WINED3DRS_WRAPV); - D3DSTATE_TO_STR(WINED3DRS_ZENABLE); - D3DSTATE_TO_STR(WINED3DRS_FILLMODE); - D3DSTATE_TO_STR(WINED3DRS_SHADEMODE); - D3DSTATE_TO_STR(WINED3DRS_LINEPATTERN); - D3DSTATE_TO_STR(WINED3DRS_MONOENABLE); - D3DSTATE_TO_STR(WINED3DRS_ROP2); - D3DSTATE_TO_STR(WINED3DRS_PLANEMASK); - D3DSTATE_TO_STR(WINED3DRS_ZWRITEENABLE); - D3DSTATE_TO_STR(WINED3DRS_ALPHATESTENABLE); - D3DSTATE_TO_STR(WINED3DRS_LASTPIXEL); - D3DSTATE_TO_STR(WINED3DRS_SRCBLEND); - D3DSTATE_TO_STR(WINED3DRS_DESTBLEND); - D3DSTATE_TO_STR(WINED3DRS_CULLMODE); - D3DSTATE_TO_STR(WINED3DRS_ZFUNC); - D3DSTATE_TO_STR(WINED3DRS_ALPHAREF); - D3DSTATE_TO_STR(WINED3DRS_ALPHAFUNC); - D3DSTATE_TO_STR(WINED3DRS_DITHERENABLE); - D3DSTATE_TO_STR(WINED3DRS_ALPHABLENDENABLE); - D3DSTATE_TO_STR(WINED3DRS_FOGENABLE); - D3DSTATE_TO_STR(WINED3DRS_SPECULARENABLE); - D3DSTATE_TO_STR(WINED3DRS_ZVISIBLE); - D3DSTATE_TO_STR(WINED3DRS_SUBPIXEL); - D3DSTATE_TO_STR(WINED3DRS_SUBPIXELX); - D3DSTATE_TO_STR(WINED3DRS_STIPPLEDALPHA); - D3DSTATE_TO_STR(WINED3DRS_FOGCOLOR); - D3DSTATE_TO_STR(WINED3DRS_FOGTABLEMODE); - D3DSTATE_TO_STR(WINED3DRS_FOGSTART); - D3DSTATE_TO_STR(WINED3DRS_FOGEND); - D3DSTATE_TO_STR(WINED3DRS_FOGDENSITY); - D3DSTATE_TO_STR(WINED3DRS_STIPPLEENABLE); - D3DSTATE_TO_STR(WINED3DRS_EDGEANTIALIAS); - D3DSTATE_TO_STR(WINED3DRS_COLORKEYENABLE); - D3DSTATE_TO_STR(WINED3DRS_MIPMAPLODBIAS); - D3DSTATE_TO_STR(WINED3DRS_RANGEFOGENABLE); - D3DSTATE_TO_STR(WINED3DRS_ANISOTROPY); - D3DSTATE_TO_STR(WINED3DRS_FLUSHBATCH); - D3DSTATE_TO_STR(WINED3DRS_TRANSLUCENTSORTINDEPENDENT); - D3DSTATE_TO_STR(WINED3DRS_STENCILENABLE); - D3DSTATE_TO_STR(WINED3DRS_STENCILFAIL); - D3DSTATE_TO_STR(WINED3DRS_STENCILZFAIL); - D3DSTATE_TO_STR(WINED3DRS_STENCILPASS); - D3DSTATE_TO_STR(WINED3DRS_STENCILFUNC); - D3DSTATE_TO_STR(WINED3DRS_STENCILREF); - D3DSTATE_TO_STR(WINED3DRS_STENCILMASK); - D3DSTATE_TO_STR(WINED3DRS_STENCILWRITEMASK); - D3DSTATE_TO_STR(WINED3DRS_TEXTUREFACTOR); - D3DSTATE_TO_STR(WINED3DRS_WRAP0); - D3DSTATE_TO_STR(WINED3DRS_WRAP1); - D3DSTATE_TO_STR(WINED3DRS_WRAP2); - D3DSTATE_TO_STR(WINED3DRS_WRAP3); - D3DSTATE_TO_STR(WINED3DRS_WRAP4); - D3DSTATE_TO_STR(WINED3DRS_WRAP5); - D3DSTATE_TO_STR(WINED3DRS_WRAP6); - D3DSTATE_TO_STR(WINED3DRS_WRAP7); - D3DSTATE_TO_STR(WINED3DRS_CLIPPING); - D3DSTATE_TO_STR(WINED3DRS_LIGHTING); - D3DSTATE_TO_STR(WINED3DRS_EXTENTS); - D3DSTATE_TO_STR(WINED3DRS_AMBIENT); - D3DSTATE_TO_STR(WINED3DRS_FOGVERTEXMODE); - D3DSTATE_TO_STR(WINED3DRS_COLORVERTEX); - D3DSTATE_TO_STR(WINED3DRS_LOCALVIEWER); - D3DSTATE_TO_STR(WINED3DRS_NORMALIZENORMALS); - D3DSTATE_TO_STR(WINED3DRS_COLORKEYBLENDENABLE); - D3DSTATE_TO_STR(WINED3DRS_DIFFUSEMATERIALSOURCE); - D3DSTATE_TO_STR(WINED3DRS_SPECULARMATERIALSOURCE); - D3DSTATE_TO_STR(WINED3DRS_AMBIENTMATERIALSOURCE); - D3DSTATE_TO_STR(WINED3DRS_EMISSIVEMATERIALSOURCE); - D3DSTATE_TO_STR(WINED3DRS_VERTEXBLEND); - D3DSTATE_TO_STR(WINED3DRS_CLIPPLANEENABLE); - D3DSTATE_TO_STR(WINED3DRS_SOFTWAREVERTEXPROCESSING); - D3DSTATE_TO_STR(WINED3DRS_POINTSIZE); - D3DSTATE_TO_STR(WINED3DRS_POINTSIZE_MIN); - D3DSTATE_TO_STR(WINED3DRS_POINTSPRITEENABLE); - D3DSTATE_TO_STR(WINED3DRS_POINTSCALEENABLE); - D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_A); - D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_B); - D3DSTATE_TO_STR(WINED3DRS_POINTSCALE_C); - D3DSTATE_TO_STR(WINED3DRS_MULTISAMPLEANTIALIAS); - D3DSTATE_TO_STR(WINED3DRS_MULTISAMPLEMASK); - D3DSTATE_TO_STR(WINED3DRS_PATCHEDGESTYLE); - D3DSTATE_TO_STR(WINED3DRS_PATCHSEGMENTS); - D3DSTATE_TO_STR(WINED3DRS_DEBUGMONITORTOKEN); - D3DSTATE_TO_STR(WINED3DRS_POINTSIZE_MAX); - D3DSTATE_TO_STR(WINED3DRS_INDEXEDVERTEXBLENDENABLE); - D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE); - D3DSTATE_TO_STR(WINED3DRS_TWEENFACTOR); - D3DSTATE_TO_STR(WINED3DRS_BLENDOP); - D3DSTATE_TO_STR(WINED3DRS_POSITIONDEGREE); - D3DSTATE_TO_STR(WINED3DRS_NORMALDEGREE); - D3DSTATE_TO_STR(WINED3DRS_SCISSORTESTENABLE); - D3DSTATE_TO_STR(WINED3DRS_SLOPESCALEDEPTHBIAS); - D3DSTATE_TO_STR(WINED3DRS_ANTIALIASEDLINEENABLE); - D3DSTATE_TO_STR(WINED3DRS_MINTESSELLATIONLEVEL); - D3DSTATE_TO_STR(WINED3DRS_MAXTESSELLATIONLEVEL); - D3DSTATE_TO_STR(WINED3DRS_ADAPTIVETESS_X); - D3DSTATE_TO_STR(WINED3DRS_ADAPTIVETESS_Y); - D3DSTATE_TO_STR(WINED3DRS_ADAPTIVETESS_Z); - D3DSTATE_TO_STR(WINED3DRS_ADAPTIVETESS_W); - D3DSTATE_TO_STR(WINED3DRS_ENABLEADAPTIVETESSELLATION); - D3DSTATE_TO_STR(WINED3DRS_TWOSIDEDSTENCILMODE); - D3DSTATE_TO_STR(WINED3DRS_CCW_STENCILFAIL); - D3DSTATE_TO_STR(WINED3DRS_CCW_STENCILZFAIL); - D3DSTATE_TO_STR(WINED3DRS_CCW_STENCILPASS); - D3DSTATE_TO_STR(WINED3DRS_CCW_STENCILFUNC); - D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE1); - D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE2); - D3DSTATE_TO_STR(WINED3DRS_COLORWRITEENABLE3); - D3DSTATE_TO_STR(WINED3DRS_BLENDFACTOR); - D3DSTATE_TO_STR(WINED3DRS_SRGBWRITEENABLE); - D3DSTATE_TO_STR(WINED3DRS_DEPTHBIAS); - D3DSTATE_TO_STR(WINED3DRS_WRAP8); - D3DSTATE_TO_STR(WINED3DRS_WRAP9); - D3DSTATE_TO_STR(WINED3DRS_WRAP10); - D3DSTATE_TO_STR(WINED3DRS_WRAP11); - D3DSTATE_TO_STR(WINED3DRS_WRAP12); - D3DSTATE_TO_STR(WINED3DRS_WRAP13); - D3DSTATE_TO_STR(WINED3DRS_WRAP14); - D3DSTATE_TO_STR(WINED3DRS_WRAP15); - D3DSTATE_TO_STR(WINED3DRS_SEPARATEALPHABLENDENABLE); - D3DSTATE_TO_STR(WINED3DRS_SRCBLENDALPHA); - D3DSTATE_TO_STR(WINED3DRS_DESTBLENDALPHA); - D3DSTATE_TO_STR(WINED3DRS_BLENDOPALPHA); + D3DSTATE_TO_STR(WINED3D_RS_ANTIALIAS); + D3DSTATE_TO_STR(WINED3D_RS_TEXTUREPERSPECTIVE); + D3DSTATE_TO_STR(WINED3D_RS_WRAPU); + D3DSTATE_TO_STR(WINED3D_RS_WRAPV); + D3DSTATE_TO_STR(WINED3D_RS_ZENABLE); + D3DSTATE_TO_STR(WINED3D_RS_FILLMODE); + D3DSTATE_TO_STR(WINED3D_RS_SHADEMODE); + D3DSTATE_TO_STR(WINED3D_RS_LINEPATTERN); + D3DSTATE_TO_STR(WINED3D_RS_MONOENABLE); + D3DSTATE_TO_STR(WINED3D_RS_ROP2); + D3DSTATE_TO_STR(WINED3D_RS_PLANEMASK); + D3DSTATE_TO_STR(WINED3D_RS_ZWRITEENABLE); + D3DSTATE_TO_STR(WINED3D_RS_ALPHATESTENABLE); + D3DSTATE_TO_STR(WINED3D_RS_LASTPIXEL); + D3DSTATE_TO_STR(WINED3D_RS_SRCBLEND); + D3DSTATE_TO_STR(WINED3D_RS_DESTBLEND); + D3DSTATE_TO_STR(WINED3D_RS_CULLMODE); + D3DSTATE_TO_STR(WINED3D_RS_ZFUNC); + D3DSTATE_TO_STR(WINED3D_RS_ALPHAREF); + D3DSTATE_TO_STR(WINED3D_RS_ALPHAFUNC); + D3DSTATE_TO_STR(WINED3D_RS_DITHERENABLE); + D3DSTATE_TO_STR(WINED3D_RS_ALPHABLENDENABLE); + D3DSTATE_TO_STR(WINED3D_RS_FOGENABLE); + D3DSTATE_TO_STR(WINED3D_RS_SPECULARENABLE); + D3DSTATE_TO_STR(WINED3D_RS_ZVISIBLE); + D3DSTATE_TO_STR(WINED3D_RS_SUBPIXEL); + D3DSTATE_TO_STR(WINED3D_RS_SUBPIXELX); + D3DSTATE_TO_STR(WINED3D_RS_STIPPLEDALPHA); + D3DSTATE_TO_STR(WINED3D_RS_FOGCOLOR); + D3DSTATE_TO_STR(WINED3D_RS_FOGTABLEMODE); + D3DSTATE_TO_STR(WINED3D_RS_FOGSTART); + D3DSTATE_TO_STR(WINED3D_RS_FOGEND); + D3DSTATE_TO_STR(WINED3D_RS_FOGDENSITY); + D3DSTATE_TO_STR(WINED3D_RS_STIPPLEENABLE); + D3DSTATE_TO_STR(WINED3D_RS_EDGEANTIALIAS); + D3DSTATE_TO_STR(WINED3D_RS_COLORKEYENABLE); + D3DSTATE_TO_STR(WINED3D_RS_MIPMAPLODBIAS); + D3DSTATE_TO_STR(WINED3D_RS_RANGEFOGENABLE); + D3DSTATE_TO_STR(WINED3D_RS_ANISOTROPY); + D3DSTATE_TO_STR(WINED3D_RS_FLUSHBATCH); + D3DSTATE_TO_STR(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT); + D3DSTATE_TO_STR(WINED3D_RS_STENCILENABLE); + D3DSTATE_TO_STR(WINED3D_RS_STENCILFAIL); + D3DSTATE_TO_STR(WINED3D_RS_STENCILZFAIL); + D3DSTATE_TO_STR(WINED3D_RS_STENCILPASS); + D3DSTATE_TO_STR(WINED3D_RS_STENCILFUNC); + D3DSTATE_TO_STR(WINED3D_RS_STENCILREF); + D3DSTATE_TO_STR(WINED3D_RS_STENCILMASK); + D3DSTATE_TO_STR(WINED3D_RS_STENCILWRITEMASK); + D3DSTATE_TO_STR(WINED3D_RS_TEXTUREFACTOR); + D3DSTATE_TO_STR(WINED3D_RS_WRAP0); + D3DSTATE_TO_STR(WINED3D_RS_WRAP1); + D3DSTATE_TO_STR(WINED3D_RS_WRAP2); + D3DSTATE_TO_STR(WINED3D_RS_WRAP3); + D3DSTATE_TO_STR(WINED3D_RS_WRAP4); + D3DSTATE_TO_STR(WINED3D_RS_WRAP5); + D3DSTATE_TO_STR(WINED3D_RS_WRAP6); + D3DSTATE_TO_STR(WINED3D_RS_WRAP7); + D3DSTATE_TO_STR(WINED3D_RS_CLIPPING); + D3DSTATE_TO_STR(WINED3D_RS_LIGHTING); + D3DSTATE_TO_STR(WINED3D_RS_EXTENTS); + D3DSTATE_TO_STR(WINED3D_RS_AMBIENT); + D3DSTATE_TO_STR(WINED3D_RS_FOGVERTEXMODE); + D3DSTATE_TO_STR(WINED3D_RS_COLORVERTEX); + D3DSTATE_TO_STR(WINED3D_RS_LOCALVIEWER); + D3DSTATE_TO_STR(WINED3D_RS_NORMALIZENORMALS); + D3DSTATE_TO_STR(WINED3D_RS_COLORKEYBLENDENABLE); + D3DSTATE_TO_STR(WINED3D_RS_DIFFUSEMATERIALSOURCE); + D3DSTATE_TO_STR(WINED3D_RS_SPECULARMATERIALSOURCE); + D3DSTATE_TO_STR(WINED3D_RS_AMBIENTMATERIALSOURCE); + D3DSTATE_TO_STR(WINED3D_RS_EMISSIVEMATERIALSOURCE); + D3DSTATE_TO_STR(WINED3D_RS_VERTEXBLEND); + D3DSTATE_TO_STR(WINED3D_RS_CLIPPLANEENABLE); + D3DSTATE_TO_STR(WINED3D_RS_SOFTWAREVERTEXPROCESSING); + D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE); + D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MIN); + D3DSTATE_TO_STR(WINED3D_RS_POINTSPRITEENABLE); + D3DSTATE_TO_STR(WINED3D_RS_POINTSCALEENABLE); + D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_A); + D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_B); + D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_C); + D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEANTIALIAS); + D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEMASK); + D3DSTATE_TO_STR(WINED3D_RS_PATCHEDGESTYLE); + D3DSTATE_TO_STR(WINED3D_RS_PATCHSEGMENTS); + D3DSTATE_TO_STR(WINED3D_RS_DEBUGMONITORTOKEN); + D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MAX); + D3DSTATE_TO_STR(WINED3D_RS_INDEXEDVERTEXBLENDENABLE); + D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE); + D3DSTATE_TO_STR(WINED3D_RS_TWEENFACTOR); + D3DSTATE_TO_STR(WINED3D_RS_BLENDOP); + D3DSTATE_TO_STR(WINED3D_RS_POSITIONDEGREE); + D3DSTATE_TO_STR(WINED3D_RS_NORMALDEGREE); + D3DSTATE_TO_STR(WINED3D_RS_SCISSORTESTENABLE); + D3DSTATE_TO_STR(WINED3D_RS_SLOPESCALEDEPTHBIAS); + D3DSTATE_TO_STR(WINED3D_RS_ANTIALIASEDLINEENABLE); + D3DSTATE_TO_STR(WINED3D_RS_MINTESSELLATIONLEVEL); + D3DSTATE_TO_STR(WINED3D_RS_MAXTESSELLATIONLEVEL); + D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_X); + D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Y); + D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Z); + D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_W); + D3DSTATE_TO_STR(WINED3D_RS_ENABLEADAPTIVETESSELLATION); + D3DSTATE_TO_STR(WINED3D_RS_TWOSIDEDSTENCILMODE); + D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILFAIL); + D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILZFAIL); + D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILPASS); + D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILFUNC); + D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE1); + D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE2); + D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE3); + D3DSTATE_TO_STR(WINED3D_RS_BLENDFACTOR); + D3DSTATE_TO_STR(WINED3D_RS_SRGBWRITEENABLE); + D3DSTATE_TO_STR(WINED3D_RS_DEPTHBIAS); + D3DSTATE_TO_STR(WINED3D_RS_WRAP8); + D3DSTATE_TO_STR(WINED3D_RS_WRAP9); + D3DSTATE_TO_STR(WINED3D_RS_WRAP10); + D3DSTATE_TO_STR(WINED3D_RS_WRAP11); + D3DSTATE_TO_STR(WINED3D_RS_WRAP12); + D3DSTATE_TO_STR(WINED3D_RS_WRAP13); + D3DSTATE_TO_STR(WINED3D_RS_WRAP14); + D3DSTATE_TO_STR(WINED3D_RS_WRAP15); + D3DSTATE_TO_STR(WINED3D_RS_SEPARATEALPHABLENDENABLE); + D3DSTATE_TO_STR(WINED3D_RS_SRCBLENDALPHA); + D3DSTATE_TO_STR(WINED3D_RS_DESTBLENDALPHA); + D3DSTATE_TO_STR(WINED3D_RS_BLENDOPALPHA); #undef D3DSTATE_TO_STR default: FIXME("Unrecognized %u render state!\n", state); @@ -2062,24 +2154,24 @@ const char *debug_d3drenderstate(WINED3DRENDERSTATETYPE state) } } -const char *debug_d3dsamplerstate(DWORD state) +const char *debug_d3dsamplerstate(enum wined3d_sampler_state state) { switch (state) { #define D3DSTATE_TO_STR(u) case u: return #u - D3DSTATE_TO_STR(WINED3DSAMP_BORDERCOLOR); - D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSU); - D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSV); - D3DSTATE_TO_STR(WINED3DSAMP_ADDRESSW); - D3DSTATE_TO_STR(WINED3DSAMP_MAGFILTER); - D3DSTATE_TO_STR(WINED3DSAMP_MINFILTER); - D3DSTATE_TO_STR(WINED3DSAMP_MIPFILTER); - D3DSTATE_TO_STR(WINED3DSAMP_MIPMAPLODBIAS); - D3DSTATE_TO_STR(WINED3DSAMP_MAXMIPLEVEL); - D3DSTATE_TO_STR(WINED3DSAMP_MAXANISOTROPY); - D3DSTATE_TO_STR(WINED3DSAMP_SRGBTEXTURE); - D3DSTATE_TO_STR(WINED3DSAMP_ELEMENTINDEX); - D3DSTATE_TO_STR(WINED3DSAMP_DMAPOFFSET); + D3DSTATE_TO_STR(WINED3D_SAMP_BORDER_COLOR); + D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_U); + D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_V); + D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_W); + D3DSTATE_TO_STR(WINED3D_SAMP_MAG_FILTER); + D3DSTATE_TO_STR(WINED3D_SAMP_MIN_FILTER); + D3DSTATE_TO_STR(WINED3D_SAMP_MIP_FILTER); + D3DSTATE_TO_STR(WINED3D_SAMP_MIPMAP_LOD_BIAS); + D3DSTATE_TO_STR(WINED3D_SAMP_MAX_MIP_LEVEL); + D3DSTATE_TO_STR(WINED3D_SAMP_MAX_ANISOTROPY); + D3DSTATE_TO_STR(WINED3D_SAMP_SRGB_TEXTURE); + D3DSTATE_TO_STR(WINED3D_SAMP_ELEMENT_INDEX); + D3DSTATE_TO_STR(WINED3D_SAMP_DMAP_OFFSET); #undef D3DSTATE_TO_STR default: FIXME("Unrecognized %u sampler state!\n", state); @@ -2087,47 +2179,49 @@ const char *debug_d3dsamplerstate(DWORD state) } } -const char *debug_d3dtexturefiltertype(WINED3DTEXTUREFILTERTYPE filter_type) { - switch (filter_type) { +const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type) +{ + switch (filter_type) + { #define D3DTEXTUREFILTERTYPE_TO_STR(u) case u: return #u - D3DTEXTUREFILTERTYPE_TO_STR(WINED3DTEXF_NONE); - D3DTEXTUREFILTERTYPE_TO_STR(WINED3DTEXF_POINT); - D3DTEXTUREFILTERTYPE_TO_STR(WINED3DTEXF_LINEAR); - D3DTEXTUREFILTERTYPE_TO_STR(WINED3DTEXF_ANISOTROPIC); - D3DTEXTUREFILTERTYPE_TO_STR(WINED3DTEXF_FLATCUBIC); - D3DTEXTUREFILTERTYPE_TO_STR(WINED3DTEXF_GAUSSIANCUBIC); - D3DTEXTUREFILTERTYPE_TO_STR(WINED3DTEXF_PYRAMIDALQUAD); - D3DTEXTUREFILTERTYPE_TO_STR(WINED3DTEXF_GAUSSIANQUAD); + D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_NONE); + D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_POINT); + D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_LINEAR); + D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_ANISOTROPIC); + D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_FLAT_CUBIC); + D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_CUBIC); + D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_PYRAMIDAL_QUAD); + D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_QUAD); #undef D3DTEXTUREFILTERTYPE_TO_STR default: - FIXME("Unrecognied texture filter type 0x%08x\n", filter_type); + FIXME("Unrecognied texture filter type 0x%08x.\n", filter_type); return "unrecognized"; } } -const char *debug_d3dtexturestate(DWORD state) +const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state) { switch (state) { #define D3DSTATE_TO_STR(u) case u: return #u - D3DSTATE_TO_STR(WINED3DTSS_COLOROP); - D3DSTATE_TO_STR(WINED3DTSS_COLORARG1); - D3DSTATE_TO_STR(WINED3DTSS_COLORARG2); - D3DSTATE_TO_STR(WINED3DTSS_ALPHAOP); - D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG1); - D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG2); - D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT00); - D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT01); - D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT10); - D3DSTATE_TO_STR(WINED3DTSS_BUMPENVMAT11); - D3DSTATE_TO_STR(WINED3DTSS_TEXCOORDINDEX); - D3DSTATE_TO_STR(WINED3DTSS_BUMPENVLSCALE); - D3DSTATE_TO_STR(WINED3DTSS_BUMPENVLOFFSET); - D3DSTATE_TO_STR(WINED3DTSS_TEXTURETRANSFORMFLAGS); - D3DSTATE_TO_STR(WINED3DTSS_COLORARG0); - D3DSTATE_TO_STR(WINED3DTSS_ALPHAARG0); - D3DSTATE_TO_STR(WINED3DTSS_RESULTARG); - D3DSTATE_TO_STR(WINED3DTSS_CONSTANT); + D3DSTATE_TO_STR(WINED3D_TSS_COLOR_OP); + D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG1); + D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG2); + D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_OP); + D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG1); + D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG2); + D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT00); + D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT01); + D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT10); + D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT11); + D3DSTATE_TO_STR(WINED3D_TSS_TEXCOORD_INDEX); + D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LSCALE); + D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LOFFSET); + D3DSTATE_TO_STR(WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS); + D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG0); + D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG0); + D3DSTATE_TO_STR(WINED3D_TSS_RESULT_ARG); + D3DSTATE_TO_STR(WINED3D_TSS_CONSTANT); #undef D3DSTATE_TO_STR default: FIXME("Unrecognized %u texture state!\n", state); @@ -2135,63 +2229,68 @@ const char *debug_d3dtexturestate(DWORD state) } } -const char* debug_d3dtop(WINED3DTEXTUREOP d3dtop) { - switch (d3dtop) { +const char *debug_d3dtop(enum wined3d_texture_op d3dtop) +{ + switch (d3dtop) + { #define D3DTOP_TO_STR(u) case u: return #u - D3DTOP_TO_STR(WINED3DTOP_DISABLE); - D3DTOP_TO_STR(WINED3DTOP_SELECTARG1); - D3DTOP_TO_STR(WINED3DTOP_SELECTARG2); - D3DTOP_TO_STR(WINED3DTOP_MODULATE); - D3DTOP_TO_STR(WINED3DTOP_MODULATE2X); - D3DTOP_TO_STR(WINED3DTOP_MODULATE4X); - D3DTOP_TO_STR(WINED3DTOP_ADD); - D3DTOP_TO_STR(WINED3DTOP_ADDSIGNED); - D3DTOP_TO_STR(WINED3DTOP_ADDSIGNED2X); - D3DTOP_TO_STR(WINED3DTOP_SUBTRACT); - D3DTOP_TO_STR(WINED3DTOP_ADDSMOOTH); - D3DTOP_TO_STR(WINED3DTOP_BLENDDIFFUSEALPHA); - D3DTOP_TO_STR(WINED3DTOP_BLENDTEXTUREALPHA); - D3DTOP_TO_STR(WINED3DTOP_BLENDFACTORALPHA); - D3DTOP_TO_STR(WINED3DTOP_BLENDTEXTUREALPHAPM); - D3DTOP_TO_STR(WINED3DTOP_BLENDCURRENTALPHA); - D3DTOP_TO_STR(WINED3DTOP_PREMODULATE); - D3DTOP_TO_STR(WINED3DTOP_MODULATEALPHA_ADDCOLOR); - D3DTOP_TO_STR(WINED3DTOP_MODULATECOLOR_ADDALPHA); - D3DTOP_TO_STR(WINED3DTOP_MODULATEINVALPHA_ADDCOLOR); - D3DTOP_TO_STR(WINED3DTOP_MODULATEINVCOLOR_ADDALPHA); - D3DTOP_TO_STR(WINED3DTOP_BUMPENVMAP); - D3DTOP_TO_STR(WINED3DTOP_BUMPENVMAPLUMINANCE); - D3DTOP_TO_STR(WINED3DTOP_DOTPRODUCT3); - D3DTOP_TO_STR(WINED3DTOP_MULTIPLYADD); - D3DTOP_TO_STR(WINED3DTOP_LERP); + D3DTOP_TO_STR(WINED3D_TOP_DISABLE); + D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG1); + D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG2); + D3DTOP_TO_STR(WINED3D_TOP_MODULATE); + D3DTOP_TO_STR(WINED3D_TOP_MODULATE_2X); + D3DTOP_TO_STR(WINED3D_TOP_MODULATE_4X); + D3DTOP_TO_STR(WINED3D_TOP_ADD); + D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED); + D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED_2X); + D3DTOP_TO_STR(WINED3D_TOP_SUBTRACT); + D3DTOP_TO_STR(WINED3D_TOP_ADD_SMOOTH); + D3DTOP_TO_STR(WINED3D_TOP_BLEND_DIFFUSE_ALPHA); + D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA); + D3DTOP_TO_STR(WINED3D_TOP_BLEND_FACTOR_ALPHA); + D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM); + D3DTOP_TO_STR(WINED3D_TOP_BLEND_CURRENT_ALPHA); + D3DTOP_TO_STR(WINED3D_TOP_PREMODULATE); + D3DTOP_TO_STR(WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR); + D3DTOP_TO_STR(WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA); + D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR); + D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA); + D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP); + D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP_LUMINANCE); + D3DTOP_TO_STR(WINED3D_TOP_DOTPRODUCT3); + D3DTOP_TO_STR(WINED3D_TOP_MULTIPLY_ADD); + D3DTOP_TO_STR(WINED3D_TOP_LERP); #undef D3DTOP_TO_STR default: - FIXME("Unrecognized %u WINED3DTOP\n", d3dtop); + FIXME("Unrecognized texture op %#x.\n", d3dtop); return "unrecognized"; } } -const char* debug_d3dtstype(WINED3DTRANSFORMSTATETYPE tstype) { - switch (tstype) { +const char *debug_d3dtstype(enum wined3d_transform_state tstype) +{ + switch (tstype) + { #define TSTYPE_TO_STR(tstype) case tstype: return #tstype - TSTYPE_TO_STR(WINED3DTS_VIEW); - TSTYPE_TO_STR(WINED3DTS_PROJECTION); - TSTYPE_TO_STR(WINED3DTS_TEXTURE0); - TSTYPE_TO_STR(WINED3DTS_TEXTURE1); - TSTYPE_TO_STR(WINED3DTS_TEXTURE2); - TSTYPE_TO_STR(WINED3DTS_TEXTURE3); - TSTYPE_TO_STR(WINED3DTS_TEXTURE4); - TSTYPE_TO_STR(WINED3DTS_TEXTURE5); - TSTYPE_TO_STR(WINED3DTS_TEXTURE6); - TSTYPE_TO_STR(WINED3DTS_TEXTURE7); - TSTYPE_TO_STR(WINED3DTS_WORLDMATRIX(0)); + TSTYPE_TO_STR(WINED3D_TS_VIEW); + TSTYPE_TO_STR(WINED3D_TS_PROJECTION); + TSTYPE_TO_STR(WINED3D_TS_TEXTURE0); + TSTYPE_TO_STR(WINED3D_TS_TEXTURE1); + TSTYPE_TO_STR(WINED3D_TS_TEXTURE2); + TSTYPE_TO_STR(WINED3D_TS_TEXTURE3); + TSTYPE_TO_STR(WINED3D_TS_TEXTURE4); + TSTYPE_TO_STR(WINED3D_TS_TEXTURE5); + TSTYPE_TO_STR(WINED3D_TS_TEXTURE6); + TSTYPE_TO_STR(WINED3D_TS_TEXTURE7); + TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(0)); #undef TSTYPE_TO_STR default: - if (tstype > 256 && tstype < 512) { - FIXME("WINED3DTS_WORLDMATRIX(%u). 1..255 not currently supported\n", tstype); - return ("WINED3DTS_WORLDMATRIX > 0"); + if (tstype > 256 && tstype < 512) + { + FIXME("WINED3D_TS_WORLD_MATRIX(%u). 1..255 not currently supported.\n", tstype); + return ("WINED3D_TS_WORLD_MATRIX > 0"); } - FIXME("Unrecognized %u WINED3DTS\n", tstype); + FIXME("Unrecognized transform state %#x.\n", tstype); return "unrecognized"; } } @@ -2239,22 +2338,26 @@ const char *debug_d3dstate(DWORD state) return "STATE_FRONTFACE"; if (STATE_IS_POINTSPRITECOORDORIGIN(state)) return "STATE_POINTSPRITECOORDORIGIN"; + if (STATE_IS_BASEVERTEXINDEX(state)) + return "STATE_BASEVERTEXINDEX"; + if (STATE_IS_FRAMEBUFFER(state)) + return "STATE_FRAMEBUFFER"; return wine_dbg_sprintf("UNKNOWN_STATE(%#x)", state); } -const char *debug_d3dpool(WINED3DPOOL pool) +const char *debug_d3dpool(enum wined3d_pool pool) { switch (pool) { #define POOL_TO_STR(p) case p: return #p - POOL_TO_STR(WINED3DPOOL_DEFAULT); - POOL_TO_STR(WINED3DPOOL_MANAGED); - POOL_TO_STR(WINED3DPOOL_SYSTEMMEM); - POOL_TO_STR(WINED3DPOOL_SCRATCH); + POOL_TO_STR(WINED3D_POOL_DEFAULT); + POOL_TO_STR(WINED3D_POOL_MANAGED); + POOL_TO_STR(WINED3D_POOL_SYSTEM_MEM); + POOL_TO_STR(WINED3D_POOL_SCRATCH); #undef POOL_TO_STR default: - FIXME("Unrecognized %u WINED3DPOOL!\n", pool); + FIXME("Unrecognized pool %#x.\n", pool); return "unrecognized"; } } @@ -2297,21 +2400,25 @@ const char *debug_glerror(GLenum error) { } } -const char *debug_d3dbasis(WINED3DBASISTYPE basis) { - switch(basis) { - case WINED3DBASIS_BEZIER: return "WINED3DBASIS_BEZIER"; - case WINED3DBASIS_BSPLINE: return "WINED3DBASIS_BSPLINE"; - case WINED3DBASIS_INTERPOLATE: return "WINED3DBASIS_INTERPOLATE"; +const char *debug_d3dbasis(enum wined3d_basis_type basis) +{ + switch (basis) + { + case WINED3D_BASIS_BEZIER: return "WINED3D_BASIS_BEZIER"; + case WINED3D_BASIS_BSPLINE: return "WINED3D_BASIS_BSPLINE"; + case WINED3D_BASIS_INTERPOLATE: return "WINED3D_BASIS_INTERPOLATE"; default: return "unrecognized"; } } -const char *debug_d3ddegree(WINED3DDEGREETYPE degree) { - switch(degree) { - case WINED3DDEGREE_LINEAR: return "WINED3DDEGREE_LINEAR"; - case WINED3DDEGREE_QUADRATIC: return "WINED3DDEGREE_QUADRATIC"; - case WINED3DDEGREE_CUBIC: return "WINED3DDEGREE_CUBIC"; - case WINED3DDEGREE_QUINTIC: return "WINED3DDEGREE_QUINTIC"; +const char *debug_d3ddegree(enum wined3d_degree_type degree) +{ + switch (degree) + { + case WINED3D_DEGREE_LINEAR: return "WINED3D_DEGREE_LINEAR"; + case WINED3D_DEGREE_QUADRATIC: return "WINED3D_DEGREE_QUADRATIC"; + case WINED3D_DEGREE_CUBIC: return "WINED3D_DEGREE_CUBIC"; + case WINED3D_DEGREE_QUINTIC: return "WINED3D_DEGREE_QUINTIC"; default: return "unrecognized"; } } @@ -2370,60 +2477,32 @@ const char *debug_surflocation(DWORD flag) { char buf[128]; buf[0] = 0; - if(flag & SFLAG_INSYSMEM) strcat(buf, " | SFLAG_INSYSMEM"); - if(flag & SFLAG_INDRAWABLE) strcat(buf, " | SFLAG_INDRAWABLE"); - if(flag & SFLAG_INTEXTURE) strcat(buf, " | SFLAG_INTEXTURE"); - if(flag & SFLAG_INSRGBTEX) strcat(buf, " | SFLAG_INSRGBTEX"); + if (flag & SFLAG_INSYSMEM) strcat(buf, " | SFLAG_INSYSMEM"); /* 17 */ + if (flag & SFLAG_INDRAWABLE) strcat(buf, " | SFLAG_INDRAWABLE"); /* 19 */ + if (flag & SFLAG_INTEXTURE) strcat(buf, " | SFLAG_INTEXTURE"); /* 18 */ + if (flag & SFLAG_INSRGBTEX) strcat(buf, " | SFLAG_INSRGBTEX"); /* 18 */ + if (flag & SFLAG_INRB_MULTISAMPLE) strcat(buf, " | SFLAG_INRB_MULTISAMPLE"); /* 25 */ + if (flag & SFLAG_INRB_RESOLVED) strcat(buf, " | SFLAG_INRB_RESOLVED"); /* 22 */ return wine_dbg_sprintf("%s", buf[0] ? buf + 3 : "0"); } -/***************************************************************************** - * Useful functions mapping GL <-> D3D values - */ -GLenum StencilOp(DWORD op) { - switch(op) { - case WINED3DSTENCILOP_KEEP : return GL_KEEP; - case WINED3DSTENCILOP_ZERO : return GL_ZERO; - case WINED3DSTENCILOP_REPLACE : return GL_REPLACE; - case WINED3DSTENCILOP_INCRSAT : return GL_INCR; - case WINED3DSTENCILOP_DECRSAT : return GL_DECR; - case WINED3DSTENCILOP_INVERT : return GL_INVERT; - case WINED3DSTENCILOP_INCR : return GL_INCR_WRAP_EXT; - case WINED3DSTENCILOP_DECR : return GL_DECR_WRAP_EXT; - default: - FIXME("Unrecognized stencil op %d\n", op); - return GL_KEEP; - } -} - -GLenum CompareFunc(DWORD func) { - switch ((WINED3DCMPFUNC)func) { - case WINED3DCMP_NEVER : return GL_NEVER; - case WINED3DCMP_LESS : return GL_LESS; - case WINED3DCMP_EQUAL : return GL_EQUAL; - case WINED3DCMP_LESSEQUAL : return GL_LEQUAL; - case WINED3DCMP_GREATER : return GL_GREATER; - case WINED3DCMP_NOTEQUAL : return GL_NOTEQUAL; - case WINED3DCMP_GREATEREQUAL : return GL_GEQUAL; - case WINED3DCMP_ALWAYS : return GL_ALWAYS; - default: - FIXME("Unrecognized WINED3DCMPFUNC value %d\n", func); - return 0; - } -} - BOOL is_invalid_op(const struct wined3d_state *state, int stage, - WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3) + enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3) { - if (op == WINED3DTOP_DISABLE) return FALSE; - if (state->textures[stage]) return FALSE; + if (op == WINED3D_TOP_DISABLE) + return FALSE; + if (state->textures[stage]) + return FALSE; if ((arg1 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE - && op != WINED3DTOP_SELECTARG2) return TRUE; + && op != WINED3D_TOP_SELECT_ARG2) + return TRUE; if ((arg2 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE - && op != WINED3DTOP_SELECTARG1) return TRUE; + && op != WINED3D_TOP_SELECT_ARG1) + return TRUE; if ((arg3 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE - && (op == WINED3DTOP_MULTIPLYADD || op == WINED3DTOP_LERP)) return TRUE; + && (op == WINED3D_TOP_MULTIPLY_ADD || op == WINED3D_TOP_LERP)) + return TRUE; return FALSE; } @@ -2438,30 +2517,41 @@ void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords, B glMatrixMode(GL_TEXTURE); checkGLcall("glMatrixMode(GL_TEXTURE)"); - if (flags == WINED3DTTFF_DISABLE || flags == WINED3DTTFF_COUNT1 || transformed) { + if (flags == WINED3D_TTFF_DISABLE || flags == WINED3D_TTFF_COUNT1 || transformed) + { glLoadIdentity(); checkGLcall("glLoadIdentity()"); return; } - if (flags == (WINED3DTTFF_COUNT1|WINED3DTTFF_PROJECTED)) { - ERR("Invalid texture transform flags: WINED3DTTFF_COUNT1|WINED3DTTFF_PROJECTED\n"); + if (flags == (WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED)) + { + ERR("Invalid texture transform flags: WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED.\n"); return; } memcpy(mat, smat, 16 * sizeof(float)); - if (flags & WINED3DTTFF_PROJECTED) { - if(!ffp_proj_control) { - switch (flags & ~WINED3DTTFF_PROJECTED) { - case WINED3DTTFF_COUNT2: - mat[3] = mat[1], mat[7] = mat[5], mat[11] = mat[9], mat[15] = mat[13]; - mat[1] = mat[5] = mat[9] = mat[13] = 0; - break; - case WINED3DTTFF_COUNT3: - mat[3] = mat[2], mat[7] = mat[6], mat[11] = mat[10], mat[15] = mat[14]; - mat[2] = mat[6] = mat[10] = mat[14] = 0; - break; + if (flags & WINED3D_TTFF_PROJECTED) + { + if (!ffp_proj_control) + { + switch (flags & ~WINED3D_TTFF_PROJECTED) + { + case WINED3D_TTFF_COUNT2: + mat[ 3] = mat[ 1]; + mat[ 7] = mat[ 5]; + mat[11] = mat[ 9]; + mat[15] = mat[13]; + mat[ 1] = mat[ 5] = mat[ 9] = mat[13] = 0.0f; + break; + case WINED3D_TTFF_COUNT3: + mat[ 3] = mat[ 2]; + mat[ 7] = mat[ 6]; + mat[11] = mat[10]; + mat[15] = mat[14]; + mat[ 2] = mat[ 6] = mat[10] = mat[14] = 0.0f; + break; } } } else { /* under directx the R/Z coord can be used for translation, under opengl we use the Q coord instead */ @@ -2499,10 +2589,13 @@ void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords, B FIXME("Unexpected fixed function texture coord input\n"); } } - if(!ffp_proj_control) { - switch (flags & ~WINED3DTTFF_PROJECTED) { - /* case WINED3DTTFF_COUNT1: Won't ever get here */ - case WINED3DTTFF_COUNT2: mat[2] = mat[6] = mat[10] = mat[14] = 0; + if (!ffp_proj_control) + { + switch (flags & ~WINED3D_TTFF_PROJECTED) + { + /* case WINED3D_TTFF_COUNT1: Won't ever get here. */ + case WINED3D_TTFF_COUNT2: + mat[2] = mat[6] = mat[10] = mat[14] = 0; /* OpenGL divides the first 3 vertex coord by the 4th by default, * which is essentially the same as D3DTTFF_PROJECTED. Make sure that * the 4th coord evaluates to 1.0 to eliminate that. @@ -2514,9 +2607,9 @@ void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords, B * * A more serious problem occurs if the app passes 4 coordinates in, and the * 4th is != 1.0(opengl default). This would have to be fixed in drawStridedSlow - * or a replacement shader - */ - default: mat[3] = mat[7] = mat[11] = 0; mat[15] = 1; + * or a replacement shader. */ + default: + mat[3] = mat[7] = mat[11] = 0; mat[15] = 1; } } } @@ -2610,7 +2703,7 @@ BOOL getDepthStencilBits(const struct wined3d_format *format, BYTE *depthSize, B /* Note: It's the caller's responsibility to ensure values can be expressed * in the requested format. UNORM formats for example can only express values * in the range 0.0f -> 1.0f. */ -DWORD wined3d_format_convert_from_float(const struct wined3d_format *format, const WINED3DCOLORVALUE *color) +DWORD wined3d_format_convert_from_float(const struct wined3d_surface *surface, const struct wined3d_color *color) { static const struct { @@ -2641,6 +2734,7 @@ DWORD wined3d_format_convert_from_float(const struct wined3d_format *format, con {WINED3DFMT_B10G10R10A2_UNORM, 1023.0f, 1023.0f, 1023.0f, 3.0f, 20, 10, 0, 30}, {WINED3DFMT_R10G10B10A2_UNORM, 1023.0f, 1023.0f, 1023.0f, 3.0f, 0, 10, 20, 30}, }; + const struct wined3d_format *format = surface->resource.format; unsigned int i; TRACE("Converting color {%.8e %.8e %.8e %.8e} to format %s.\n", @@ -2662,6 +2756,40 @@ DWORD wined3d_format_convert_from_float(const struct wined3d_format *format, con return ret; } + if (format->id == WINED3DFMT_P8_UINT) + { + PALETTEENTRY *e; + BYTE r, g, b, a; + + if (!surface->palette) + { + WARN("Surface doesn't have a palette, returning 0.\n"); + return 0; + } + + r = (BYTE)((color->r * 255.0f) + 0.5f); + g = (BYTE)((color->g * 255.0f) + 0.5f); + b = (BYTE)((color->b * 255.0f) + 0.5f); + a = (BYTE)((color->a * 255.0f) + 0.5f); + + e = &surface->palette->palents[a]; + if (e->peRed == r && e->peGreen == g && e->peBlue == b) + return a; + + WARN("Alpha didn't match index, searching full palette.\n"); + + for (i = 0; i < 256; ++i) + { + e = &surface->palette->palents[i]; + if (e->peRed == r && e->peGreen == g && e->peBlue == b) + return i; + } + + FIXME("Unable to convert color to palette index.\n"); + + return 0; + } + FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format->id)); return 0; @@ -2681,8 +2809,10 @@ enum wined3d_format_id pixelformat_for_depth(DWORD depth) } } -void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2) { - WINED3DMATRIX temp; +void multiply_matrix(struct wined3d_matrix *dest, const struct wined3d_matrix *src1, + const struct wined3d_matrix *src2) +{ + struct wined3d_matrix temp; /* Now do the multiplication 'by hand'. I know that all this could be optimised, but this will be done later :-) */ @@ -2737,12 +2867,14 @@ DWORD get_flexible_vertex_size(DWORD d3dvtVertexType) { return size; } -void gen_ffp_frag_op(struct wined3d_stateblock *stateblock, struct ffp_frag_settings *settings, BOOL ignore_textype) +void gen_ffp_frag_op(const struct wined3d_device *device, const struct wined3d_state *state, + struct ffp_frag_settings *settings, BOOL ignore_textype) { #define ARG1 0x01 #define ARG2 0x02 #define ARG0 0x04 - static const unsigned char args[WINED3DTOP_LERP + 1] = { + static const unsigned char args[WINED3D_TOP_LERP + 1] = + { /* undefined */ 0, /* D3DTOP_DISABLE */ 0, /* D3DTOP_SELECTARG1 */ ARG1, @@ -2774,8 +2906,7 @@ void gen_ffp_frag_op(struct wined3d_stateblock *stateblock, struct ffp_frag_sett unsigned int i; DWORD ttff; DWORD cop, aop, carg0, carg1, carg2, aarg0, aarg1, aarg2; - struct wined3d_device *device = stateblock->device; - struct wined3d_surface *rt = device->fb.render_targets[0]; + const struct wined3d_surface *rt = state->fb->render_targets[0]; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; for (i = 0; i < gl_info->limits.texture_stages; ++i) @@ -2783,10 +2914,10 @@ void gen_ffp_frag_op(struct wined3d_stateblock *stateblock, struct ffp_frag_sett const struct wined3d_texture *texture; settings->op[i].padding = 0; - if (stateblock->state.texture_states[i][WINED3DTSS_COLOROP] == WINED3DTOP_DISABLE) + if (state->texture_states[i][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_DISABLE) { - settings->op[i].cop = WINED3DTOP_DISABLE; - settings->op[i].aop = WINED3DTOP_DISABLE; + settings->op[i].cop = WINED3D_TOP_DISABLE; + settings->op[i].aop = WINED3D_TOP_DISABLE; settings->op[i].carg0 = settings->op[i].carg1 = settings->op[i].carg2 = ARG_UNUSED; settings->op[i].aarg0 = settings->op[i].aarg1 = settings->op[i].aarg2 = ARG_UNUSED; settings->op[i].color_fixup = COLOR_FIXUP_IDENTITY; @@ -2797,7 +2928,7 @@ void gen_ffp_frag_op(struct wined3d_stateblock *stateblock, struct ffp_frag_sett break; } - if ((texture = stateblock->state.textures[i])) + if ((texture = state->textures[i])) { settings->op[i].color_fixup = texture->resource.format->color_fixup; if (ignore_textype) @@ -2830,22 +2961,23 @@ void gen_ffp_frag_op(struct wined3d_stateblock *stateblock, struct ffp_frag_sett settings->op[i].tex_type = tex_1d; } - cop = stateblock->state.texture_states[i][WINED3DTSS_COLOROP]; - aop = stateblock->state.texture_states[i][WINED3DTSS_ALPHAOP]; + cop = state->texture_states[i][WINED3D_TSS_COLOR_OP]; + aop = state->texture_states[i][WINED3D_TSS_ALPHA_OP]; - carg1 = (args[cop] & ARG1) ? stateblock->state.texture_states[i][WINED3DTSS_COLORARG1] : ARG_UNUSED; - carg2 = (args[cop] & ARG2) ? stateblock->state.texture_states[i][WINED3DTSS_COLORARG2] : ARG_UNUSED; - carg0 = (args[cop] & ARG0) ? stateblock->state.texture_states[i][WINED3DTSS_COLORARG0] : ARG_UNUSED; + carg1 = (args[cop] & ARG1) ? state->texture_states[i][WINED3D_TSS_COLOR_ARG1] : ARG_UNUSED; + carg2 = (args[cop] & ARG2) ? state->texture_states[i][WINED3D_TSS_COLOR_ARG2] : ARG_UNUSED; + carg0 = (args[cop] & ARG0) ? state->texture_states[i][WINED3D_TSS_COLOR_ARG0] : ARG_UNUSED; - if (is_invalid_op(&stateblock->state, i, cop, carg1, carg2, carg0)) + if (is_invalid_op(state, i, cop, carg1, carg2, carg0)) { carg0 = ARG_UNUSED; carg2 = ARG_UNUSED; carg1 = WINED3DTA_CURRENT; - cop = WINED3DTOP_SELECTARG1; + cop = WINED3D_TOP_SELECT_ARG1; } - if(cop == WINED3DTOP_DOTPRODUCT3) { + if (cop == WINED3D_TOP_DOTPRODUCT3) + { /* A dotproduct3 on the colorop overwrites the alphaop operation and replicates * the color result to the alpha component of the destination */ @@ -2856,16 +2988,16 @@ void gen_ffp_frag_op(struct wined3d_stateblock *stateblock, struct ffp_frag_sett } else { - aarg1 = (args[aop] & ARG1) ? stateblock->state.texture_states[i][WINED3DTSS_ALPHAARG1] : ARG_UNUSED; - aarg2 = (args[aop] & ARG2) ? stateblock->state.texture_states[i][WINED3DTSS_ALPHAARG2] : ARG_UNUSED; - aarg0 = (args[aop] & ARG0) ? stateblock->state.texture_states[i][WINED3DTSS_ALPHAARG0] : ARG_UNUSED; + aarg1 = (args[aop] & ARG1) ? state->texture_states[i][WINED3D_TSS_ALPHA_ARG1] : ARG_UNUSED; + aarg2 = (args[aop] & ARG2) ? state->texture_states[i][WINED3D_TSS_ALPHA_ARG2] : ARG_UNUSED; + aarg0 = (args[aop] & ARG0) ? state->texture_states[i][WINED3D_TSS_ALPHA_ARG0] : ARG_UNUSED; } - if (!i && stateblock->state.textures[0] && stateblock->state.render_states[WINED3DRS_COLORKEYENABLE]) + if (!i && state->textures[0] && state->render_states[WINED3D_RS_COLORKEYENABLE]) { GLenum texture_dimensions; - texture = stateblock->state.textures[0]; + texture = state->textures[0]; texture_dimensions = texture->target; if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB) @@ -2874,26 +3006,26 @@ void gen_ffp_frag_op(struct wined3d_stateblock *stateblock, struct ffp_frag_sett if (surf->CKeyFlags & WINEDDSD_CKSRCBLT && !surf->resource.format->alpha_mask) { - if (aop == WINED3DTOP_DISABLE) + if (aop == WINED3D_TOP_DISABLE) { aarg1 = WINED3DTA_TEXTURE; - aop = WINED3DTOP_SELECTARG1; + aop = WINED3D_TOP_SELECT_ARG1; } - else if (aop == WINED3DTOP_SELECTARG1 && aarg1 != WINED3DTA_TEXTURE) + else if (aop == WINED3D_TOP_SELECT_ARG1 && aarg1 != WINED3DTA_TEXTURE) { - if (stateblock->state.render_states[WINED3DRS_ALPHABLENDENABLE]) + if (state->render_states[WINED3D_RS_ALPHABLENDENABLE]) { aarg2 = WINED3DTA_TEXTURE; - aop = WINED3DTOP_MODULATE; + aop = WINED3D_TOP_MODULATE; } else aarg1 = WINED3DTA_TEXTURE; } - else if (aop == WINED3DTOP_SELECTARG2 && aarg2 != WINED3DTA_TEXTURE) + else if (aop == WINED3D_TOP_SELECT_ARG2 && aarg2 != WINED3DTA_TEXTURE) { - if (stateblock->state.render_states[WINED3DRS_ALPHABLENDENABLE]) + if (state->render_states[WINED3D_RS_ALPHABLENDENABLE]) { aarg1 = WINED3DTA_TEXTURE; - aop = WINED3DTOP_MODULATE; + aop = WINED3D_TOP_MODULATE; } else aarg2 = WINED3DTA_TEXTURE; } @@ -2901,27 +3033,27 @@ void gen_ffp_frag_op(struct wined3d_stateblock *stateblock, struct ffp_frag_sett } } - if (is_invalid_op(&stateblock->state, i, aop, aarg1, aarg2, aarg0)) + if (is_invalid_op(state, i, aop, aarg1, aarg2, aarg0)) { aarg0 = ARG_UNUSED; aarg2 = ARG_UNUSED; aarg1 = WINED3DTA_CURRENT; - aop = WINED3DTOP_SELECTARG1; + aop = WINED3D_TOP_SELECT_ARG1; } if (carg1 == WINED3DTA_TEXTURE || carg2 == WINED3DTA_TEXTURE || carg0 == WINED3DTA_TEXTURE || aarg1 == WINED3DTA_TEXTURE || aarg2 == WINED3DTA_TEXTURE || aarg0 == WINED3DTA_TEXTURE) { - ttff = stateblock->state.texture_states[i][WINED3DTSS_TEXTURETRANSFORMFLAGS]; - if (ttff == (WINED3DTTFF_PROJECTED | WINED3DTTFF_COUNT3)) - { + ttff = state->texture_states[i][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS]; + if (ttff == (WINED3D_TTFF_PROJECTED | WINED3D_TTFF_COUNT3)) settings->op[i].projected = proj_count3; - } else if(ttff == (WINED3DTTFF_PROJECTED | WINED3DTTFF_COUNT4)) { + else if (ttff & WINED3D_TTFF_PROJECTED) settings->op[i].projected = proj_count4; - } else { + else settings->op[i].projected = proj_none; - } - } else { + } + else + { settings->op[i].projected = proj_none; } @@ -2934,12 +3066,10 @@ void gen_ffp_frag_op(struct wined3d_stateblock *stateblock, struct ffp_frag_sett settings->op[i].aarg1 = aarg1; settings->op[i].aarg2 = aarg2; - if (stateblock->state.texture_states[i][WINED3DTSS_RESULTARG] == WINED3DTA_TEMP) - { + if (state->texture_states[i][WINED3D_TSS_RESULT_ARG] == WINED3DTA_TEMP) settings->op[i].dst = tempreg; - } else { + else settings->op[i].dst = resultreg; - } } /* Clear unsupported stages */ @@ -2947,28 +3077,28 @@ void gen_ffp_frag_op(struct wined3d_stateblock *stateblock, struct ffp_frag_sett memset(&settings->op[i], 0xff, sizeof(settings->op[i])); } - if (!stateblock->state.render_states[WINED3DRS_FOGENABLE]) + if (!state->render_states[WINED3D_RS_FOGENABLE]) { settings->fog = FOG_OFF; } - else if (stateblock->state.render_states[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) + else if (state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE) { - if (use_vs(&stateblock->state) || stateblock->state.vertex_declaration->position_transformed) + if (use_vs(state) || state->vertex_declaration->position_transformed) { settings->fog = FOG_LINEAR; } else { - switch (stateblock->state.render_states[WINED3DRS_FOGVERTEXMODE]) + switch (state->render_states[WINED3D_RS_FOGVERTEXMODE]) { - case WINED3DFOG_NONE: - case WINED3DFOG_LINEAR: + case WINED3D_FOG_NONE: + case WINED3D_FOG_LINEAR: settings->fog = FOG_LINEAR; break; - case WINED3DFOG_EXP: + case WINED3D_FOG_EXP: settings->fog = FOG_EXP; break; - case WINED3DFOG_EXP2: + case WINED3D_FOG_EXP2: settings->fog = FOG_EXP2; break; } @@ -2976,28 +3106,28 @@ void gen_ffp_frag_op(struct wined3d_stateblock *stateblock, struct ffp_frag_sett } else { - switch (stateblock->state.render_states[WINED3DRS_FOGTABLEMODE]) + switch (state->render_states[WINED3D_RS_FOGTABLEMODE]) { - case WINED3DFOG_LINEAR: + case WINED3D_FOG_LINEAR: settings->fog = FOG_LINEAR; break; - case WINED3DFOG_EXP: + case WINED3D_FOG_EXP: settings->fog = FOG_EXP; break; - case WINED3DFOG_EXP2: + case WINED3D_FOG_EXP2: settings->fog = FOG_EXP2; break; } } - if (stateblock->state.render_states[WINED3DRS_SRGBWRITEENABLE] + if (state->render_states[WINED3D_RS_SRGBWRITEENABLE] && rt->resource.format->flags & WINED3DFMT_FLAG_SRGB_WRITE) { settings->sRGB_write = 1; } else { settings->sRGB_write = 0; } - if (device->vs_clipping || !use_vs(&stateblock->state) || !stateblock->state.render_states[WINED3DRS_CLIPPING] - || !stateblock->state.render_states[WINED3DRS_CLIPPLANEENABLE]) + if (device->vs_clipping || !use_vs(state) || !state->render_states[WINED3D_RS_CLIPPING] + || !state->render_states[WINED3D_RS_CLIPPLANEENABLE]) { /* No need to emulate clipplanes if GL supports native vertex shader clipping or if * the fixed function vertex pipeline is used(which always supports clipplanes), or @@ -3116,20 +3246,22 @@ void texture_activate_dimensions(const struct wined3d_texture *texture, const st } /* GL locking is done by the caller (state handler) */ -void sampler_texdim(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) +void sampler_texdim(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { - DWORD sampler = state - STATE_SAMPLER(0); - DWORD mapped_stage = stateblock->device->texUnitMap[sampler]; + DWORD sampler = state_id - STATE_SAMPLER(0); + DWORD mapped_stage = context->swapchain->device->texUnitMap[sampler]; - /* No need to enable / disable anything here for unused samplers. The tex_colorop - * handler takes care. Also no action is needed with pixel shaders, or if tex_colorop - * will take care of this business - */ - if (mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= context->gl_info->limits.textures) return; - if (sampler >= stateblock->state.lowest_disabled_stage) return; - if (isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP))) return; + /* No need to enable / disable anything here for unused samplers. The + * tex_colorop handler takes care. Also no action is needed with pixel + * shaders, or if tex_colorop will take care of this business. */ + if (mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= context->gl_info->limits.textures) + return; + if (sampler >= state->lowest_disabled_stage) + return; + if (isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3D_TSS_COLOR_OP))) + return; - texture_activate_dimensions(stateblock->state.textures[sampler], context->gl_info); + texture_activate_dimensions(state->textures[sampler], context->gl_info); } void *wined3d_rb_alloc(size_t size) @@ -3215,8 +3347,8 @@ void select_shader_mode(const struct wined3d_gl_info *gl_info, int *ps_selected, } const struct blit_shader *wined3d_select_blitter(const struct wined3d_gl_info *gl_info, enum wined3d_blit_op blit_op, - const RECT *src_rect, DWORD src_usage, WINED3DPOOL src_pool, const struct wined3d_format *src_format, - const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool, const struct wined3d_format *dst_format) + const RECT *src_rect, DWORD src_usage, enum wined3d_pool src_pool, const struct wined3d_format *src_format, + const RECT *dst_rect, DWORD dst_usage, enum wined3d_pool dst_pool, const struct wined3d_format *dst_format) { static const struct blit_shader * const blitters[] = { @@ -3236,3 +3368,13 @@ const struct blit_shader *wined3d_select_blitter(const struct wined3d_gl_info *g return NULL; } + +void wined3d_get_draw_rect(const struct wined3d_state *state, RECT *rect) +{ + const struct wined3d_viewport *vp = &state->viewport; + + SetRect(rect, vp->x, vp->y, vp->x + vp->width, vp->y + vp->height); + + if (state->render_states[WINED3D_RS_SCISSORTESTENABLE]) + IntersectRect(rect, rect, &state->scissor_rect); +} diff --git a/reactos/dll/directx/wine/wined3d/vertexdeclaration.c b/reactos/dll/directx/wine/wined3d/vertexdeclaration.c index d5eae1604c0..576fe7c687b 100644 --- a/reactos/dll/directx/wine/wined3d/vertexdeclaration.c +++ b/reactos/dll/directx/wine/wined3d/vertexdeclaration.c @@ -27,7 +27,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d_decl); -static void dump_wined3dvertexelement(const WINED3DVERTEXELEMENT *element) { +static void dump_wined3d_vertex_element(const struct wined3d_vertex_element *element) +{ TRACE(" format: %s (%#x)\n", debug_d3dformat(element->format), element->format); TRACE(" input_slot: %u\n", element->input_slot); TRACE(" offset: %u\n", element->offset); @@ -69,7 +70,7 @@ void * CDECL wined3d_vertex_declaration_get_parent(const struct wined3d_vertex_d return declaration->parent; } -static BOOL declaration_element_valid_ffp(const WINED3DVERTEXELEMENT *element) +static BOOL declaration_element_valid_ffp(const struct wined3d_vertex_element *element) { switch(element->usage) { @@ -158,7 +159,7 @@ static BOOL declaration_element_valid_ffp(const WINED3DVERTEXELEMENT *element) } static HRESULT vertexdeclaration_init(struct wined3d_vertex_declaration *declaration, - struct wined3d_device *device, const WINED3DVERTEXELEMENT *elements, UINT element_count, + struct wined3d_device *device, const struct wined3d_vertex_element *elements, UINT element_count, void *parent, const struct wined3d_parent_ops *parent_ops) { const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; @@ -169,7 +170,7 @@ static HRESULT vertexdeclaration_init(struct wined3d_vertex_declaration *declara { for (i = 0; i < element_count; ++i) { - dump_wined3dvertexelement(elements + i); + dump_wined3d_vertex_element(elements + i); } } @@ -238,7 +239,7 @@ static HRESULT vertexdeclaration_init(struct wined3d_vertex_declaration *declara } HRESULT CDECL wined3d_vertex_declaration_create(struct wined3d_device *device, - const WINED3DVERTEXELEMENT *elements, UINT element_count, void *parent, + const struct wined3d_vertex_element *elements, UINT element_count, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_vertex_declaration **declaration) { struct wined3d_vertex_declaration *object; @@ -271,7 +272,7 @@ HRESULT CDECL wined3d_vertex_declaration_create(struct wined3d_device *device, struct wined3d_fvf_convert_state { const struct wined3d_gl_info *gl_info; - WINED3DVERTEXELEMENT *elements; + struct wined3d_vertex_element *elements; UINT offset; UINT idx; }; @@ -279,7 +280,7 @@ struct wined3d_fvf_convert_state static void append_decl_element(struct wined3d_fvf_convert_state *state, enum wined3d_format_id format_id, WINED3DDECLUSAGE usage, UINT usage_idx) { - WINED3DVERTEXELEMENT *elements = state->elements; + struct wined3d_vertex_element *elements = state->elements; const struct wined3d_format *format; UINT offset = state->offset; UINT idx = state->idx; @@ -298,7 +299,7 @@ static void append_decl_element(struct wined3d_fvf_convert_state *state, } static unsigned int convert_fvf_to_declaration(const struct wined3d_gl_info *gl_info, - DWORD fvf, WINED3DVERTEXELEMENT **elements) + DWORD fvf, struct wined3d_vertex_element **elements) { BOOL has_pos = !!(fvf & WINED3DFVF_POSITION_MASK); BOOL has_blend = (fvf & WINED3DFVF_XYZB5) > WINED3DFVF_XYZRHW; @@ -408,7 +409,7 @@ HRESULT CDECL wined3d_vertex_declaration_create_from_fvf(struct wined3d_device * DWORD fvf, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_vertex_declaration **declaration) { - WINED3DVERTEXELEMENT *elements; + struct wined3d_vertex_element *elements; unsigned int size; DWORD hr; diff --git a/reactos/dll/directx/wine/wined3d/volume.c b/reactos/dll/directx/wine/wined3d/volume.c index e0f8ed6a4c6..7659e6f094a 100644 --- a/reactos/dll/directx/wine/wined3d/volume.c +++ b/reactos/dll/directx/wine/wined3d/volume.c @@ -25,7 +25,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface); /* Context activation is done by the caller. */ -static void volume_bind_and_dirtify(struct wined3d_volume *volume, const struct wined3d_gl_info *gl_info) +static void volume_bind_and_dirtify(const struct wined3d_volume *volume, struct wined3d_context *context) { struct wined3d_texture *container = volume->container; DWORD active_sampler; @@ -37,49 +37,35 @@ static void volume_bind_and_dirtify(struct wined3d_volume *volume, const struct * To be more specific, this is tricky because we can implicitly be called * from sampler() in state.c. This means we can't touch anything other than * whatever happens to be the currently active texture, or we would risk - * marking already applied sampler states dirty again. - * - * TODO: Track the current active texture per GL context instead of using glGet - */ - if (gl_info->supported[ARB_MULTITEXTURE]) - { - GLint active_texture; - ENTER_GL(); - glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); - LEAVE_GL(); - active_sampler = volume->resource.device->rev_tex_unit_map[active_texture - GL_TEXTURE0_ARB]; - } else { - active_sampler = 0; - } + * marking already applied sampler states dirty again. */ + active_sampler = volume->resource.device->rev_tex_unit_map[context->active_texture]; if (active_sampler != WINED3D_UNMAPPED_STAGE) - { - IWineD3DDeviceImpl_MarkStateDirty(volume->resource.device, STATE_SAMPLER(active_sampler)); - } + device_invalidate_state(volume->resource.device, STATE_SAMPLER(active_sampler)); - container->texture_ops->texture_bind(container, gl_info, FALSE); + container->texture_ops->texture_bind(container, context, FALSE); } -void volume_add_dirty_box(struct wined3d_volume *volume, const WINED3DBOX *dirty_box) +void volume_add_dirty_box(struct wined3d_volume *volume, const struct wined3d_box *dirty_box) { volume->dirty = TRUE; if (dirty_box) { - volume->lockedBox.Left = min(volume->lockedBox.Left, dirty_box->Left); - volume->lockedBox.Top = min(volume->lockedBox.Top, dirty_box->Top); - volume->lockedBox.Front = min(volume->lockedBox.Front, dirty_box->Front); - volume->lockedBox.Right = max(volume->lockedBox.Right, dirty_box->Right); - volume->lockedBox.Bottom = max(volume->lockedBox.Bottom, dirty_box->Bottom); - volume->lockedBox.Back = max(volume->lockedBox.Back, dirty_box->Back); + volume->lockedBox.left = min(volume->lockedBox.left, dirty_box->left); + volume->lockedBox.top = min(volume->lockedBox.top, dirty_box->top); + volume->lockedBox.front = min(volume->lockedBox.front, dirty_box->front); + volume->lockedBox.right = max(volume->lockedBox.right, dirty_box->right); + volume->lockedBox.bottom = max(volume->lockedBox.bottom, dirty_box->bottom); + volume->lockedBox.back = max(volume->lockedBox.back, dirty_box->back); } else { - volume->lockedBox.Left = 0; - volume->lockedBox.Top = 0; - volume->lockedBox.Front = 0; - volume->lockedBox.Right = volume->resource.width; - volume->lockedBox.Bottom = volume->resource.height; - volume->lockedBox.Back = volume->resource.depth; + volume->lockedBox.left = 0; + volume->lockedBox.top = 0; + volume->lockedBox.front = 0; + volume->lockedBox.right = volume->resource.width; + volume->lockedBox.bottom = volume->resource.height; + volume->lockedBox.back = volume->resource.depth; } } @@ -91,15 +77,15 @@ void volume_set_container(struct wined3d_volume *volume, struct wined3d_texture } /* Context activation is done by the caller. */ -void volume_load(struct wined3d_volume *volume, UINT level, BOOL srgb_mode) +void volume_load(const struct wined3d_volume *volume, struct wined3d_context *context, UINT level, BOOL srgb_mode) { - const struct wined3d_gl_info *gl_info = &volume->resource.device->adapter->gl_info; + const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_format *format = volume->resource.format; - TRACE("volume %p, level %u, srgb %#x, format %s (%#x).\n", - volume, level, srgb_mode, debug_d3dformat(format->id), format->id); + TRACE("volume %p, context %p, level %u, srgb %#x, format %s (%#x).\n", + volume, context, level, srgb_mode, debug_d3dformat(format->id), format->id); - volume_bind_and_dirtify(volume, gl_info); + volume_bind_and_dirtify(volume, context); ENTER_GL(); GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D, level, format->glInternal, @@ -175,23 +161,6 @@ void * CDECL wined3d_volume_get_parent(const struct wined3d_volume *volume) return volume->resource.parent; } -HRESULT CDECL wined3d_volume_set_private_data(struct wined3d_volume *volume, - REFGUID guid, const void *data, DWORD data_size, DWORD flags) -{ - return resource_set_private_data(&volume->resource, guid, data, data_size, flags); -} - -HRESULT CDECL wined3d_volume_get_private_data(const struct wined3d_volume *volume, - REFGUID guid, void *data, DWORD *data_size) -{ - return resource_get_private_data(&volume->resource, guid, data, data_size); -} - -HRESULT CDECL wined3d_volume_free_private_data(struct wined3d_volume *volume, REFGUID guid) -{ - return resource_free_private_data(&volume->resource, guid); -} - DWORD CDECL wined3d_volume_set_priority(struct wined3d_volume *volume, DWORD priority) { return resource_set_priority(&volume->resource, priority); @@ -216,44 +185,44 @@ struct wined3d_resource * CDECL wined3d_volume_get_resource(struct wined3d_volum } HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume, - WINED3DLOCKED_BOX *locked_box, const WINED3DBOX *box, DWORD flags) + struct wined3d_mapped_box *mapped_box, const struct wined3d_box *box, DWORD flags) { - TRACE("volume %p, locked_box %p, box %p, flags %#x.\n", - volume, locked_box, box, flags); + TRACE("volume %p, mapped_box %p, box %p, flags %#x.\n", + volume, mapped_box, box, flags); if (!volume->resource.allocatedMemory) volume->resource.allocatedMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, volume->resource.size); TRACE("allocatedMemory %p.\n", volume->resource.allocatedMemory); - locked_box->RowPitch = volume->resource.format->byte_count * volume->resource.width; /* Bytes / row */ - locked_box->SlicePitch = volume->resource.format->byte_count + mapped_box->row_pitch = volume->resource.format->byte_count * volume->resource.width; /* Bytes / row */ + mapped_box->slice_pitch = volume->resource.format->byte_count * volume->resource.width * volume->resource.height; /* Bytes / slice */ if (!box) { TRACE("No box supplied - all is ok\n"); - locked_box->pBits = volume->resource.allocatedMemory; - volume->lockedBox.Left = 0; - volume->lockedBox.Top = 0; - volume->lockedBox.Front = 0; - volume->lockedBox.Right = volume->resource.width; - volume->lockedBox.Bottom = volume->resource.height; - volume->lockedBox.Back = volume->resource.depth; + mapped_box->data = volume->resource.allocatedMemory; + volume->lockedBox.left = 0; + volume->lockedBox.top = 0; + volume->lockedBox.front = 0; + volume->lockedBox.right = volume->resource.width; + volume->lockedBox.bottom = volume->resource.height; + volume->lockedBox.back = volume->resource.depth; } else { - TRACE("Lock Box (%p) = l %d, t %d, r %d, b %d, fr %d, ba %d\n", - box, box->Left, box->Top, box->Right, box->Bottom, box->Front, box->Back); - locked_box->pBits = volume->resource.allocatedMemory - + (locked_box->SlicePitch * box->Front) /* FIXME: is front < back or vica versa? */ - + (locked_box->RowPitch * box->Top) - + (box->Left * volume->resource.format->byte_count); - volume->lockedBox.Left = box->Left; - volume->lockedBox.Top = box->Top; - volume->lockedBox.Front = box->Front; - volume->lockedBox.Right = box->Right; - volume->lockedBox.Bottom = box->Bottom; - volume->lockedBox.Back = box->Back; + TRACE("Lock Box (%p) = l %u, t %u, r %u, b %u, fr %u, ba %u\n", + box, box->left, box->top, box->right, box->bottom, box->front, box->back); + mapped_box->data = volume->resource.allocatedMemory + + (mapped_box->slice_pitch * box->front) /* FIXME: is front < back or vica versa? */ + + (mapped_box->row_pitch * box->top) + + (box->left * volume->resource.format->byte_count); + volume->lockedBox.left = box->left; + volume->lockedBox.top = box->top; + volume->lockedBox.front = box->front; + volume->lockedBox.right = box->right; + volume->lockedBox.bottom = box->bottom; + volume->lockedBox.back = box->back; } if (!(flags & (WINED3DLOCK_NO_DIRTY_UPDATE | WINED3DLOCK_READONLY))) @@ -265,7 +234,7 @@ HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume, volume->locked = TRUE; TRACE("Returning memory %p, row pitch %d, slice pitch %d.\n", - locked_box->pBits, locked_box->RowPitch, locked_box->SlicePitch); + mapped_box->data, mapped_box->row_pitch, mapped_box->slice_pitch); return WINED3D_OK; } @@ -297,7 +266,7 @@ static const struct wined3d_resource_ops volume_resource_ops = }; static HRESULT volume_init(struct wined3d_volume *volume, struct wined3d_device *device, UINT width, - UINT height, UINT depth, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool, + UINT height, UINT depth, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops) { const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; @@ -310,8 +279,8 @@ static HRESULT volume_init(struct wined3d_volume *volume, struct wined3d_device return WINED3DERR_INVALIDCALL; } - hr = resource_init(&volume->resource, device, WINED3DRTYPE_VOLUME, format, - WINED3DMULTISAMPLE_NONE, 0, usage, pool, width, height, depth, + hr = resource_init(&volume->resource, device, WINED3D_RTYPE_VOLUME, format, + WINED3D_MULTISAMPLE_NONE, 0, usage, pool, width, height, depth, width * height * depth * format->byte_count, parent, parent_ops, &volume_resource_ops); if (FAILED(hr)) @@ -331,7 +300,7 @@ static HRESULT volume_init(struct wined3d_volume *volume, struct wined3d_device } HRESULT CDECL wined3d_volume_create(struct wined3d_device *device, UINT width, UINT height, - UINT depth, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool, void *parent, + UINT depth, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_volume **volume) { struct wined3d_volume *object; diff --git a/reactos/dll/directx/wine/wined3d/wined3d.spec b/reactos/dll/directx/wine/wined3d/wined3d.spec index fd8e8ea4293..f0821fbc312 100644 --- a/reactos/dll/directx/wine/wined3d/wined3d.spec +++ b/reactos/dll/directx/wine/wined3d/wined3d.spec @@ -6,7 +6,7 @@ @ cdecl wined3d_check_device_format_conversion(ptr long long long long) @ cdecl wined3d_check_device_multisample_type(ptr long long long long long ptr) @ cdecl wined3d_check_device_type(ptr long long long long long) -@ cdecl wined3d_create(long ptr) +@ cdecl wined3d_create(long long ptr) @ cdecl wined3d_decref(ptr) @ cdecl wined3d_enum_adapter_modes(ptr long long long ptr) @ cdecl wined3d_get_adapter_count(ptr) @@ -23,34 +23,22 @@ @ cdecl wined3d_buffer_create_ib(ptr long long long ptr ptr ptr) @ cdecl wined3d_buffer_create_vb(ptr long long long ptr ptr ptr) @ cdecl wined3d_buffer_decref(ptr) -@ cdecl wined3d_buffer_free_private_data(ptr ptr) @ cdecl wined3d_buffer_get_parent(ptr) @ cdecl wined3d_buffer_get_priority(ptr) -@ cdecl wined3d_buffer_get_private_data(ptr ptr ptr ptr) @ cdecl wined3d_buffer_get_resource(ptr) @ cdecl wined3d_buffer_incref(ptr) @ cdecl wined3d_buffer_map(ptr long long ptr long) @ cdecl wined3d_buffer_preload(ptr) @ cdecl wined3d_buffer_set_priority(ptr long) -@ cdecl wined3d_buffer_set_private_data(ptr ptr ptr long long) @ cdecl wined3d_buffer_unmap(ptr) -@ cdecl wined3d_clipper_create() -@ cdecl wined3d_clipper_decref(ptr) -@ cdecl wined3d_clipper_get_clip_list(ptr ptr ptr ptr) -@ cdecl wined3d_clipper_get_window(ptr ptr) -@ cdecl wined3d_clipper_incref(ptr) -@ cdecl wined3d_clipper_is_clip_list_changed(ptr ptr) -@ cdecl wined3d_clipper_set_clip_list(ptr ptr long) -@ cdecl wined3d_clipper_set_window(ptr long ptr) - @ cdecl wined3d_device_acquire_focus_window(ptr ptr) @ cdecl wined3d_device_begin_scene(ptr) @ cdecl wined3d_device_begin_stateblock(ptr) -@ cdecl wined3d_device_clear(ptr long ptr long long long long) +@ cdecl wined3d_device_clear(ptr long ptr long long float long) @ cdecl wined3d_device_clear_rendertarget_view(ptr ptr ptr) @ cdecl wined3d_device_color_fill(ptr ptr ptr ptr) -@ cdecl wined3d_device_create(ptr long long ptr long ptr ptr) +@ cdecl wined3d_device_create(ptr long long ptr long long ptr ptr) @ cdecl wined3d_device_decref(ptr) @ cdecl wined3d_device_delete_patch(ptr long) @ cdecl wined3d_device_draw_indexed_primitive(ptr long long) @@ -63,7 +51,6 @@ @ cdecl wined3d_device_draw_tri_patch(ptr long ptr ptr) @ cdecl wined3d_device_end_scene(ptr) @ cdecl wined3d_device_end_stateblock(ptr ptr) -@ cdecl wined3d_device_enum_resources(ptr ptr ptr) @ cdecl wined3d_device_evict_managed_resources(ptr) @ cdecl wined3d_device_get_available_texture_mem(ptr) @ cdecl wined3d_device_get_back_buffer(ptr long long long ptr) @@ -71,7 +58,6 @@ @ cdecl wined3d_device_get_clip_plane(ptr long ptr) @ cdecl wined3d_device_get_clip_status(ptr ptr) @ cdecl wined3d_device_get_creation_parameters(ptr ptr) -@ cdecl wined3d_device_get_current_texture_palette(ptr ptr) @ cdecl wined3d_device_get_depth_stencil(ptr ptr) @ cdecl wined3d_device_get_device_caps(ptr ptr) @ cdecl wined3d_device_get_display_mode(ptr long ptr) @@ -82,7 +68,6 @@ @ cdecl wined3d_device_get_light_enable(ptr long ptr) @ cdecl wined3d_device_get_material(ptr ptr) @ cdecl wined3d_device_get_npatch_mode(ptr) -@ cdecl wined3d_device_get_palette_entries(ptr long ptr) @ cdecl wined3d_device_get_pixel_shader(ptr) @ cdecl wined3d_device_get_primitive_type(ptr ptr) @ cdecl wined3d_device_get_ps_consts_b(ptr long ptr long) @@ -116,12 +101,11 @@ @ cdecl wined3d_device_present(ptr ptr ptr ptr ptr) @ cdecl wined3d_device_process_vertices(ptr long long long ptr ptr long long) @ cdecl wined3d_device_release_focus_window(ptr) -@ cdecl wined3d_device_reset(ptr ptr) +@ cdecl wined3d_device_reset(ptr ptr ptr) @ cdecl wined3d_device_restore_fullscreen_window(ptr ptr) @ cdecl wined3d_device_set_base_vertex_index(ptr long) @ cdecl wined3d_device_set_clip_plane(ptr long ptr) @ cdecl wined3d_device_set_clip_status(ptr ptr) -@ cdecl wined3d_device_set_current_texture_palette(ptr long) @ cdecl wined3d_device_set_cursor_position(ptr long long long) @ cdecl wined3d_device_set_cursor_properties(ptr long long ptr) @ cdecl wined3d_device_set_depth_stencil(ptr ptr) @@ -133,8 +117,7 @@ @ cdecl wined3d_device_set_light_enable(ptr long long) @ cdecl wined3d_device_set_material(ptr ptr) @ cdecl wined3d_device_set_multithreaded(ptr) -@ cdecl wined3d_device_set_npatch_mode(ptr long) -@ cdecl wined3d_device_set_palette_entries(ptr long ptr) +@ cdecl wined3d_device_set_npatch_mode(ptr float) @ cdecl wined3d_device_set_pixel_shader(ptr ptr) @ cdecl wined3d_device_set_primitive_type(ptr long) @ cdecl wined3d_device_set_ps_consts_b(ptr long ptr long) @@ -180,8 +163,11 @@ @ cdecl wined3d_query_incref(ptr) @ cdecl wined3d_query_issue(ptr long) +@ cdecl wined3d_resource_free_private_data(ptr ptr) @ cdecl wined3d_resource_get_desc(ptr ptr) @ cdecl wined3d_resource_get_parent(ptr) +@ cdecl wined3d_resource_get_private_data(ptr ptr ptr ptr) +@ cdecl wined3d_resource_set_private_data(ptr ptr ptr long long) @ cdecl wined3d_rendertarget_view_create(ptr ptr ptr) @ cdecl wined3d_rendertarget_view_decref(ptr) @@ -205,20 +191,17 @@ @ cdecl wined3d_stateblock_incref(ptr) @ cdecl wined3d_surface_blt(ptr ptr ptr ptr long ptr long) -@ cdecl wined3d_surface_bltfast(ptr long long ptr ptr long) @ cdecl wined3d_surface_create(ptr long long long long long long long long long long long ptr ptr ptr) @ cdecl wined3d_surface_decref(ptr) @ cdecl wined3d_surface_flip(ptr ptr long) -@ cdecl wined3d_surface_free_private_data(ptr ptr) @ cdecl wined3d_surface_get_blt_status(ptr long) -@ cdecl wined3d_surface_get_clipper(ptr) @ cdecl wined3d_surface_get_flip_status(ptr long) @ cdecl wined3d_surface_get_overlay_position(ptr ptr ptr) @ cdecl wined3d_surface_get_palette(ptr) @ cdecl wined3d_surface_get_parent(ptr) @ cdecl wined3d_surface_get_pitch(ptr) @ cdecl wined3d_surface_get_priority(ptr) -@ cdecl wined3d_surface_get_private_data(ptr ptr ptr ptr) +@ cdecl wined3d_surface_get_render_target_data(ptr ptr) @ cdecl wined3d_surface_get_resource(ptr) @ cdecl wined3d_surface_getdc(ptr ptr) @ cdecl wined3d_surface_incref(ptr) @@ -227,15 +210,13 @@ @ cdecl wined3d_surface_preload(ptr) @ cdecl wined3d_surface_releasedc(ptr ptr) @ cdecl wined3d_surface_restore(ptr) -@ cdecl wined3d_surface_set_clipper(ptr ptr) @ cdecl wined3d_surface_set_color_key(ptr long ptr) -@ cdecl wined3d_surface_set_format(ptr long) @ cdecl wined3d_surface_set_mem(ptr ptr) @ cdecl wined3d_surface_set_overlay_position(ptr long long) @ cdecl wined3d_surface_set_palette(ptr ptr) @ cdecl wined3d_surface_set_priority(ptr long) -@ cdecl wined3d_surface_set_private_data(ptr ptr ptr long long) @ cdecl wined3d_surface_unmap(ptr) +@ cdecl wined3d_surface_update_desc(ptr long long long long long) @ cdecl wined3d_surface_update_overlay(ptr ptr ptr ptr long ptr) @ cdecl wined3d_surface_update_overlay_z_order(ptr long ptr) @@ -247,7 +228,7 @@ @ cdecl wined3d_swapchain_get_front_buffer_data(ptr ptr) @ cdecl wined3d_swapchain_get_gamma_ramp(ptr ptr) @ cdecl wined3d_swapchain_get_parent(ptr) -@ cdecl wined3d_swapchain_get_present_parameters(ptr ptr) +@ cdecl wined3d_swapchain_get_desc(ptr ptr) @ cdecl wined3d_swapchain_get_raster_status(ptr ptr) @ cdecl wined3d_swapchain_incref(ptr) @ cdecl wined3d_swapchain_present(ptr ptr ptr ptr ptr long) @@ -259,22 +240,19 @@ @ cdecl wined3d_texture_create_3d(ptr long long long long long long long ptr ptr ptr) @ cdecl wined3d_texture_create_cube(ptr long long long long long ptr ptr ptr) @ cdecl wined3d_texture_decref(ptr) -@ cdecl wined3d_texture_free_private_data(ptr ptr) @ cdecl wined3d_texture_generate_mipmaps(ptr) @ cdecl wined3d_texture_get_autogen_filter_type(ptr) @ cdecl wined3d_texture_get_level_count(ptr) @ cdecl wined3d_texture_get_lod(ptr) @ cdecl wined3d_texture_get_parent(ptr) @ cdecl wined3d_texture_get_priority(ptr) -@ cdecl wined3d_texture_get_private_data(ptr ptr ptr ptr) +@ cdecl wined3d_texture_get_resource(ptr) @ cdecl wined3d_texture_get_sub_resource(ptr long) -@ cdecl wined3d_texture_get_type(ptr) @ cdecl wined3d_texture_incref(ptr) @ cdecl wined3d_texture_preload(ptr) @ cdecl wined3d_texture_set_autogen_filter_type(ptr long) @ cdecl wined3d_texture_set_lod(ptr long) @ cdecl wined3d_texture_set_priority(ptr long) -@ cdecl wined3d_texture_set_private_data(ptr ptr ptr long long) @ cdecl wined3d_vertex_declaration_create(ptr ptr long ptr ptr ptr) @ cdecl wined3d_vertex_declaration_create_from_fvf(ptr long ptr ptr ptr) @@ -284,15 +262,12 @@ @ cdecl wined3d_volume_create(ptr long long long long long long ptr ptr ptr) @ cdecl wined3d_volume_decref(ptr) -@ cdecl wined3d_volume_free_private_data(ptr ptr) @ cdecl wined3d_volume_from_resource(ptr) @ cdecl wined3d_volume_get_parent(ptr) @ cdecl wined3d_volume_get_priority(ptr) -@ cdecl wined3d_volume_get_private_data(ptr ptr ptr ptr) @ cdecl wined3d_volume_get_resource(ptr) @ cdecl wined3d_volume_incref(ptr) @ cdecl wined3d_volume_map(ptr ptr ptr long) @ cdecl wined3d_volume_preload(ptr) @ cdecl wined3d_volume_set_priority(ptr long) -@ cdecl wined3d_volume_set_private_data(ptr ptr ptr long long) @ cdecl wined3d_volume_unmap(ptr) diff --git a/reactos/dll/directx/wine/wined3d/wined3d_gl.h b/reactos/dll/directx/wine/wined3d/wined3d_gl.h index be50b2f672b..d9a88db2406 100644 --- a/reactos/dll/directx/wine/wined3d/wined3d_gl.h +++ b/reactos/dll/directx/wine/wined3d/wined3d_gl.h @@ -1721,7 +1721,7 @@ BOOL (WINAPI *pwglShareLists)(HGLRC, HGLRC) DECLSPEC_HIDDEN; USE_WGL_FUNC(wglShareLists) /* OpenGL extensions. */ -typedef enum wined3d_gl_extension +enum wined3d_gl_extension { WINED3D_GL_EXT_NONE, @@ -1738,12 +1738,14 @@ typedef enum wined3d_gl_extension ARB_DEPTH_CLAMP, ARB_DEPTH_TEXTURE, ARB_DRAW_BUFFERS, + ARB_DRAW_ELEMENTS_BASE_VERTEX, ARB_FRAGMENT_PROGRAM, ARB_FRAGMENT_SHADER, ARB_FRAMEBUFFER_OBJECT, ARB_GEOMETRY_SHADER4, ARB_HALF_FLOAT_PIXEL, ARB_HALF_FLOAT_VERTEX, + ARB_MAP_BUFFER_ALIGNMENT, ARB_MAP_BUFFER_RANGE, ARB_MULTISAMPLE, ARB_MULTITEXTURE, @@ -1844,7 +1846,7 @@ typedef enum wined3d_gl_extension WINED3D_GL_VERSION_2_0, WINED3D_GL_EXT_COUNT, -} GL_SupportedExt; +}; /* GL_APPLE_client_storage */ #ifndef GL_APPLE_client_storage @@ -1891,9 +1893,9 @@ typedef void (WINE_GLAPI *PGLFNFINISHOBJECTAPPLEPROC)(GLenum, GLuint); #define GL_APPLE_flush_buffer_range 1 #define GL_BUFFER_SERIALIZED_MODIFY_APPLE 0x8a12 #define GL_BUFFER_FLUSHING_UNMAP_APPLE 0x8a13 +#endif typedef void (WINE_GLAPI *PGLFNBUFFERPARAMETERIAPPLE)(GLenum target, GLenum pname, GLint param); typedef void (WINE_GLAPI *PGLFNFLUSHMAPPEDBUFFERRANGEAPPLE)(GLenum target, GLintptr offset, GLsizeiptr size); -#endif /* GL_APPLE_flush_render */ typedef void (WINE_GLAPI *PGLFNFLUSHRENDERAPPLEPROC)(void); @@ -1965,6 +1967,19 @@ typedef void (WINE_GLAPI *PGLFNCLAMPCOLORARBPROC)(GLenum target, GLenum clamp); #endif typedef void (WINE_GLAPI *PGLFNDRAWBUFFERSARBPROC)(GLsizei n, const GLenum *bufs); +/* GL_ARB_draw_elements_base_vertex */ +#ifndef GL_ARB_draw_elements_base_vertex +#define GL_ARB_draw_elements_base_vertex 1 +#endif +typedef void (WINE_GLAPI *PGLFNDRAWELEMENTSBASEVERTEXPROC)(GLenum mode, GLsizei count, GLenum type, + const GLvoid *indices, GLint basevertex); +typedef void (WINE_GLAPI *PGLFNDRAWRANGEELEMENTSBASEVERTEXPROC)(GLenum mode, GLuint start, GLuint end, + GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +typedef void (WINE_GLAPI *PGLFNDRAWELEMENTSINSTANCEDBASEVERTEXPROC)(GLenum mode, GLsizei count, + GLenum type, const GLvoid *indices, GLsizei primcount, GLint basevertex); +typedef void (WINE_GLAPI *PGLFNMULTIDRAWELEMENTSBASEVERTEXPROC)(GLenum mode, GLsizei *count, GLenum type, + const GLvoid **indices, GLsizei primcount, GLint *basevertex); + /* GL_ARB_fragment_program */ #ifndef GL_ARB_fragment_program #define GL_ARB_fragment_program 1 @@ -2147,6 +2162,12 @@ typedef void (WINE_GLAPI *PGLFNFRAMEBUFFERTEXTUREFACEARBPROC)(GLenum target, GLe #define GL_HALF_FLOAT 0x140b #endif +/* GL_ARB_map_buffer_alignment */ +#ifndef GL_ARB_map_buffer_alignment +#define GL_ARB_map_buffer_alignment 1 +#define GL_MIN_MAP_BUFFER_ALIGNMENT 0x90bc +#endif + /* GL_ARB_map_buffer_range */ #ifndef GL_ARB_map_buffer_range #define GL_ARB_map_buffer_range 1 @@ -3069,11 +3090,11 @@ typedef void (WINE_GLAPI *PGLFNGLGENERATEMIPMAPEXTPROC)(GLenum target); /* GL_EXT_gpu_program_parameters */ #ifndef GL_EXT_gpu_program_parameters #define GL_EXT_gpu_program_parameters 1 +#endif typedef void (WINE_GLAPI *PGLFNPROGRAMENVPARAMETERS4FVEXTPROC)(GLenum target, GLuint index, GLsizei count, const float *params); typedef void (WINE_GLAPI *PGLFNPROGRAMLOCALPARAMETERS4FVEXTPROC)(GLenum target, GLuint index, GLsizei count, const float *params); -#endif /* GL_EXT_gpu_shader4 */ #ifndef GL_EXT_gpu_shader4 @@ -3789,6 +3810,15 @@ typedef BOOL (WINAPI *WINED3D_PFNWGLSWAPINTERVALEXTPROC)(int interval); /* GL_ARB_draw_buffers */ \ USE_GL_FUNC(PGLFNDRAWBUFFERSARBPROC, \ glDrawBuffersARB, ARB_DRAW_BUFFERS, NULL) \ + /* GL_ARB_draw_elements_base_vertex */ \ + USE_GL_FUNC(PGLFNDRAWELEMENTSBASEVERTEXPROC, \ + glDrawElementsBaseVertex, ARB_DRAW_ELEMENTS_BASE_VERTEX, NULL) \ + USE_GL_FUNC(PGLFNDRAWRANGEELEMENTSBASEVERTEXPROC, \ + glDrawRangeElementsBaseVertex, ARB_DRAW_ELEMENTS_BASE_VERTEX, NULL) \ + USE_GL_FUNC(PGLFNDRAWELEMENTSINSTANCEDBASEVERTEXPROC, \ + glDrawElementsInstancedBaseVertex, ARB_DRAW_ELEMENTS_BASE_VERTEX, NULL) \ + USE_GL_FUNC(PGLFNMULTIDRAWELEMENTSBASEVERTEXPROC, \ + glMultiDrawElementsBaseVertex, ARB_DRAW_ELEMENTS_BASE_VERTEX, NULL) \ /* GL_ARB_framebuffer_object */ \ USE_GL_FUNC(PGLFNGLISRENDERBUFFERPROC, \ glIsRenderbuffer, ARB_FRAMEBUFFER_OBJECT, NULL) \ diff --git a/reactos/dll/directx/wine/wined3d/wined3d_main.c b/reactos/dll/directx/wine/wined3d/wined3d_main.c index 4f7b1cb03a1..1b7e4935637 100644 --- a/reactos/dll/directx/wine/wined3d/wined3d_main.c +++ b/reactos/dll/directx/wine/wined3d/wined3d_main.c @@ -28,6 +28,7 @@ #include "wined3d_private.h" WINE_DEFAULT_DEBUG_CHANNEL(d3d); +WINE_DECLARE_DEBUG_CHANNEL(winediag); struct wined3d_wndproc { @@ -60,6 +61,16 @@ static CRITICAL_SECTION_DEBUG wined3d_cs_debug = }; static CRITICAL_SECTION wined3d_cs = {&wined3d_cs_debug, -1, 0, 0, 0, 0}; +static CRITICAL_SECTION wined3d_wndproc_cs; +static CRITICAL_SECTION_DEBUG wined3d_wndproc_cs_debug = +{ + 0, 0, &wined3d_wndproc_cs, + {&wined3d_wndproc_cs_debug.ProcessLocksList, + &wined3d_wndproc_cs_debug.ProcessLocksList}, + 0, 0, {(DWORD_PTR)(__FILE__ ": wined3d_wndproc_cs")} +}; +static CRITICAL_SECTION wined3d_wndproc_cs = {&wined3d_wndproc_cs_debug, -1, 0, 0, 0, 0}; + /* When updating default value here, make sure to update winecfg as well, * where appropriate. */ struct wined3d_settings wined3d_settings = @@ -73,12 +84,13 @@ struct wined3d_settings wined3d_settings = PCI_DEVICE_NONE,/* PCI Device ID */ 0, /* The default of memory is set in init_driver_info */ NULL, /* No wine logo by default */ - FALSE, /* Disable multisampling for now due to Nvidia driver bugs which happens for some users */ + TRUE, /* Multisampling enabled by default. */ FALSE, /* No strict draw ordering. */ + FALSE, /* Try to render onscreen by default. */ }; /* Do not call while under the GL lock. */ -struct wined3d * CDECL wined3d_create(UINT version, void *parent) +struct wined3d * CDECL wined3d_create(UINT version, DWORD flags, void *parent) { struct wined3d *object; HRESULT hr; @@ -90,7 +102,7 @@ struct wined3d * CDECL wined3d_create(UINT version, void *parent) return NULL; } - hr = wined3d_init(object, version, parent); + hr = wined3d_init(object, version, flags, parent); if (FAILED(hr)) { WARN("Failed to initialize wined3d object, hr %#x.\n", hr); @@ -228,6 +240,7 @@ static BOOL wined3d_dll_init(HINSTANCE hInstDLL) { if (!strcmp(buffer,"disabled")) { + ERR_(winediag)("The GLSL shader backend has been disabled. You get to keep all the pieces if it breaks.\n"); TRACE("Use of GL Shading Language disabled\n"); wined3d_settings.glslRequested = FALSE; } @@ -247,12 +260,7 @@ static BOOL wined3d_dll_init(HINSTANCE hInstDLL) } if ( !get_config_key( hkey, appkey, "RenderTargetLockMode", buffer, size) ) { - if (!strcmp(buffer,"disabled")) - { - TRACE("Disabling render target locking\n"); - wined3d_settings.rendertargetlock_mode = RTL_DISABLE; - } - else if (!strcmp(buffer,"readdraw")) + if (!strcmp(buffer,"readdraw")) { TRACE("Using glReadPixels for render target reading and glDrawPixels for writing\n"); wined3d_settings.rendertargetlock_mode = RTL_READDRAW; @@ -316,10 +324,10 @@ static BOOL wined3d_dll_init(HINSTANCE hInstDLL) } if ( !get_config_key( hkey, appkey, "Multisampling", buffer, size) ) { - if (!strcmp(buffer,"enabled")) + if (!strcmp(buffer, "disabled")) { - TRACE("Allow multisampling\n"); - wined3d_settings.allow_multisampling = TRUE; + TRACE("Multisampling disabled.\n"); + wined3d_settings.allow_multisampling = FALSE; } } if (!get_config_key(hkey, appkey, "StrictDrawOrdering", buffer, size) @@ -328,6 +336,12 @@ static BOOL wined3d_dll_init(HINSTANCE hInstDLL) TRACE("Enforcing strict draw ordering.\n"); wined3d_settings.strict_draw_ordering = TRUE; } + if (!get_config_key(hkey, appkey, "AlwaysOffscreen", buffer, size) + && !strcmp(buffer,"enabled")) + { + TRACE("Always rendering backbuffers offscreen.\n"); + wined3d_settings.always_offscreen = TRUE; + } } if (wined3d_settings.vs_mode == VS_HW) TRACE("Allow HW vertex shaders\n"); @@ -368,6 +382,8 @@ static BOOL wined3d_dll_destroy(HINSTANCE hInstDLL) HeapFree(GetProcessHeap(), 0, wined3d_settings.logo); UnregisterClassA(WINED3D_OPENGL_WINDOW_CLASS_NAME, hInstDLL); + DeleteCriticalSection(&wined3d_wndproc_cs); + DeleteCriticalSection(&wined3d_cs); return TRUE; } @@ -381,6 +397,16 @@ void WINAPI wined3d_mutex_unlock(void) LeaveCriticalSection(&wined3d_cs); } +static void wined3d_wndproc_mutex_lock(void) +{ + EnterCriticalSection(&wined3d_wndproc_cs); +} + +static void wined3d_wndproc_mutex_unlock(void) +{ + LeaveCriticalSection(&wined3d_wndproc_cs); +} + static struct wined3d_wndproc *wined3d_find_wndproc(HWND window) { unsigned int i; @@ -403,12 +429,12 @@ static LRESULT CALLBACK wined3d_wndproc(HWND window, UINT message, WPARAM wparam BOOL unicode; WNDPROC proc; - wined3d_mutex_lock(); + wined3d_wndproc_mutex_lock(); entry = wined3d_find_wndproc(window); if (!entry) { - wined3d_mutex_unlock(); + wined3d_wndproc_mutex_unlock(); ERR("Window %p is not registered with wined3d.\n", window); return DefWindowProcW(window, message, wparam, lparam); } @@ -416,7 +442,7 @@ static LRESULT CALLBACK wined3d_wndproc(HWND window, UINT message, WPARAM wparam device = entry->device; unicode = entry->unicode; proc = entry->proc; - wined3d_mutex_unlock(); + wined3d_wndproc_mutex_unlock(); return device_process_message(device, window, unicode, message, wparam, lparam, proc); } @@ -425,11 +451,11 @@ BOOL wined3d_register_window(HWND window, struct wined3d_device *device) { struct wined3d_wndproc *entry; - wined3d_mutex_lock(); + wined3d_wndproc_mutex_lock(); if (wined3d_find_wndproc(window)) { - wined3d_mutex_unlock(); + wined3d_wndproc_mutex_unlock(); WARN("Window %p is already registered with wined3d.\n", window); return TRUE; } @@ -444,7 +470,7 @@ BOOL wined3d_register_window(HWND window, struct wined3d_device *device) if (!new_entries) { - wined3d_mutex_unlock(); + wined3d_wndproc_mutex_unlock(); ERR("Failed to grow table.\n"); return FALSE; } @@ -465,7 +491,7 @@ BOOL wined3d_register_window(HWND window, struct wined3d_device *device) entry->proc = (WNDPROC)SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)wined3d_wndproc); entry->device = device; - wined3d_mutex_unlock(); + wined3d_wndproc_mutex_unlock(); return TRUE; } @@ -475,11 +501,11 @@ void wined3d_unregister_window(HWND window) struct wined3d_wndproc *entry, *last; LONG_PTR proc; - wined3d_mutex_lock(); + wined3d_wndproc_mutex_lock(); if (!(entry = wined3d_find_wndproc(window))) { - wined3d_mutex_unlock(); + wined3d_wndproc_mutex_unlock(); ERR("Window %p is not registered with wined3d.\n", window); return; } @@ -489,7 +515,7 @@ void wined3d_unregister_window(HWND window) proc = GetWindowLongPtrW(window, GWLP_WNDPROC); if (proc != (LONG_PTR)wined3d_wndproc) { - wined3d_mutex_unlock(); + wined3d_wndproc_mutex_unlock(); WARN("Not unregistering window %p, window proc %#lx doesn't match wined3d window proc %p.\n", window, proc, wined3d_wndproc); return; @@ -502,7 +528,7 @@ void wined3d_unregister_window(HWND window) proc = GetWindowLongPtrA(window, GWLP_WNDPROC); if (proc != (LONG_PTR)wined3d_wndproc) { - wined3d_mutex_unlock(); + wined3d_wndproc_mutex_unlock(); WARN("Not unregistering window %p, window proc %#lx doesn't match wined3d window proc %p.\n", window, proc, wined3d_wndproc); return; @@ -514,7 +540,7 @@ void wined3d_unregister_window(HWND window) last = &wndproc_table.entries[--wndproc_table.count]; if (entry != last) *entry = *last; - wined3d_mutex_unlock(); + wined3d_wndproc_mutex_unlock(); } /* At process attach */ diff --git a/reactos/dll/directx/wine/wined3d/wined3d_private.h b/reactos/dll/directx/wine/wined3d/wined3d_private.h index 88c300d7ac1..c9d12085e9c 100644 --- a/reactos/dll/directx/wine/wined3d/wined3d_private.h +++ b/reactos/dll/directx/wine/wined3d/wined3d_private.h @@ -51,6 +51,9 @@ #define WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA 0x00000008 #define WINED3D_QUIRK_NV_CLIP_BROKEN 0x00000010 #define WINED3D_QUIRK_FBO_TEX_UPDATE 0x00000020 +#define WINED3D_QUIRK_BROKEN_RGBA16 0x00000040 +#define WINED3D_QUIRK_INFO_LOG_SPAM 0x00000080 +#define WINED3D_QUIRK_LIMITED_TEX_FILTERING 0x00000100 /* Texture format fixups */ @@ -154,22 +157,22 @@ void wined3d_rb_free(void *ptr) DECLSPEC_HIDDEN; struct min_lookup { - GLenum mip[WINED3DTEXF_LINEAR + 1]; + GLenum mip[WINED3D_TEXF_LINEAR + 1]; }; -extern const struct min_lookup minMipLookup[WINED3DTEXF_LINEAR + 1] DECLSPEC_HIDDEN; -extern const struct min_lookup minMipLookup_noFilter[WINED3DTEXF_LINEAR + 1] DECLSPEC_HIDDEN; -extern const struct min_lookup minMipLookup_noMip[WINED3DTEXF_LINEAR + 1] DECLSPEC_HIDDEN; -extern const GLenum magLookup[WINED3DTEXF_LINEAR + 1] DECLSPEC_HIDDEN; -extern const GLenum magLookup_noFilter[WINED3DTEXF_LINEAR + 1] DECLSPEC_HIDDEN; +extern const struct min_lookup minMipLookup[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN; +extern const struct min_lookup minMipLookup_noFilter[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN; +extern const struct min_lookup minMipLookup_noMip[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN; +extern const GLenum magLookup[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN; +extern const GLenum magLookup_noFilter[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN; -static inline GLenum wined3d_gl_mag_filter(const GLenum mag_lookup[], WINED3DTEXTUREFILTERTYPE mag_filter) +static inline GLenum wined3d_gl_mag_filter(const GLenum mag_lookup[], enum wined3d_texture_filter_type mag_filter) { return mag_lookup[mag_filter]; } static inline GLenum wined3d_gl_min_mip_filter(const struct min_lookup min_mip_lookup[], - WINED3DTEXTUREFILTERTYPE min_filter, WINED3DTEXTUREFILTERTYPE mip_filter) + enum wined3d_texture_filter_type min_filter, enum wined3d_texture_filter_type mip_filter) { return min_mip_lookup[min_filter].mip[mip_filter]; } @@ -196,8 +199,8 @@ static inline float float_16_to_32(const unsigned short *in) { } else if(e < 31) { return sgn * powf(2, (float)e - 15.0f) * (1.0f + ((float)m / 1024.0f)); } else { - if(m == 0) return sgn * INFINITY; /* +INF / -INF */ - else return NAN; + if(m == 0) return sgn / 0.0f; /* +INF / -INF */ + else return 0.0f / 0.0f; /* NAN */ } } @@ -218,8 +221,8 @@ static inline float float_24_to_32(DWORD in) } else { - if (m == 0) return sgn * INFINITY; /* +INF / -INF */ - else return NAN; + if (m == 0) return sgn / 0.0f; /* +INF / -INF */ + else return 0.0f / 0.0f; /* NAN */ } } @@ -243,7 +246,6 @@ static inline float float_24_to_32(DWORD in) #define SHADER_ATI 3 #define SHADER_NONE 4 -#define RTL_DISABLE -1 #define RTL_READDRAW 1 #define RTL_READTEX 2 @@ -270,20 +272,21 @@ struct wined3d_settings char *logo; int allow_multisampling; BOOL strict_draw_ordering; + BOOL always_offscreen; }; extern struct wined3d_settings wined3d_settings DECLSPEC_HIDDEN; -typedef enum _WINED3DSAMPLER_TEXTURE_TYPE +enum wined3d_sampler_texture_type { WINED3DSTT_UNKNOWN = 0, WINED3DSTT_1D = 1, WINED3DSTT_2D = 2, WINED3DSTT_CUBE = 3, WINED3DSTT_VOLUME = 4, -} WINED3DSAMPLER_TEXTURE_TYPE; +}; -typedef enum _WINED3DSHADER_PARAM_REGISTER_TYPE +enum wined3d_shader_register_type { WINED3DSPR_TEMP = 0, WINED3DSPR_INPUT = 1, @@ -311,7 +314,7 @@ typedef enum _WINED3DSHADER_PARAM_REGISTER_TYPE WINED3DSPR_CONSTBUFFER, WINED3DSPR_NULL, WINED3DSPR_RESOURCE, -} WINED3DSHADER_PARAM_REGISTER_TYPE; +}; enum wined3d_immconst_type { @@ -321,7 +324,7 @@ enum wined3d_immconst_type #define WINED3DSP_NOSWIZZLE (0 | (1 << 2) | (2 << 4) | (3 << 6)) -typedef enum _WINED3DSHADER_PARAM_SRCMOD_TYPE +enum wined3d_shader_src_modifier { WINED3DSPSM_NONE = 0, WINED3DSPSM_NEG = 1, @@ -337,7 +340,7 @@ typedef enum _WINED3DSHADER_PARAM_SRCMOD_TYPE WINED3DSPSM_ABS = 11, WINED3DSPSM_ABSNEG = 12, WINED3DSPSM_NOT = 13, -} WINED3DSHADER_PARAM_SRCMOD_TYPE; +}; #define WINED3DSP_WRITEMASK_0 0x1 /* .x r */ #define WINED3DSP_WRITEMASK_1 0x2 /* .y g */ @@ -345,27 +348,27 @@ typedef enum _WINED3DSHADER_PARAM_SRCMOD_TYPE #define WINED3DSP_WRITEMASK_3 0x8 /* .w a */ #define WINED3DSP_WRITEMASK_ALL 0xf /* all */ -typedef enum _WINED3DSHADER_PARAM_DSTMOD_TYPE +enum wined3d_shader_dst_modifier { WINED3DSPDM_NONE = 0, WINED3DSPDM_SATURATE = 1, WINED3DSPDM_PARTIALPRECISION = 2, WINED3DSPDM_MSAMPCENTROID = 4, -} WINED3DSHADER_PARAM_DSTMOD_TYPE; +}; /* Undocumented opcode control to identify projective texture lookups in ps 2.0 and later */ #define WINED3DSI_TEXLD_PROJECT 1 #define WINED3DSI_TEXLD_BIAS 2 -typedef enum COMPARISON_TYPE +enum wined3d_shader_rel_op { - COMPARISON_GT = 1, - COMPARISON_EQ = 2, - COMPARISON_GE = 3, - COMPARISON_LT = 4, - COMPARISON_NE = 5, - COMPARISON_LE = 6, -} COMPARISON_TYPE; + WINED3D_SHADER_REL_OP_GT = 1, + WINED3D_SHADER_REL_OP_EQ = 2, + WINED3D_SHADER_REL_OP_GE = 3, + WINED3D_SHADER_REL_OP_LT = 4, + WINED3D_SHADER_REL_OP_NE = 5, + WINED3D_SHADER_REL_OP_LE = 6, +}; #define WINED3D_SM1_VS 0xfffe #define WINED3D_SM1_PS 0xffff @@ -434,10 +437,12 @@ enum WINED3D_SHADER_INSTRUCTION_HANDLER WINED3DSIH_ENDIF, WINED3DSIH_ENDLOOP, WINED3DSIH_ENDREP, + WINED3DSIH_EQ, WINED3DSIH_EXP, WINED3DSIH_EXPP, WINED3DSIH_FRC, WINED3DSIH_FTOI, + WINED3DSIH_GE, WINED3DSIH_IADD, WINED3DSIH_IEQ, WINED3DSIH_IF, @@ -472,6 +477,7 @@ enum WINED3D_SHADER_INSTRUCTION_HANDLER WINED3DSIH_RCP, WINED3DSIH_REP, WINED3DSIH_RET, + WINED3DSIH_ROUND_NI, WINED3DSIH_RSQ, WINED3DSIH_SAMPLE, WINED3DSIH_SAMPLE_GRAD, @@ -505,7 +511,10 @@ enum WINED3D_SHADER_INSTRUCTION_HANDLER WINED3DSIH_TEXREG2AR, WINED3DSIH_TEXREG2GB, WINED3DSIH_TEXREG2RGB, + WINED3DSIH_UDIV, + WINED3DSIH_USHR, WINED3DSIH_UTOF, + WINED3DSIH_XOR, WINED3DSIH_TABLE_SIZE }; @@ -541,7 +550,7 @@ struct wined3d_shader_reg_maps WORD local_int_consts; /* MAX_CONST_I, 16 */ WORD local_bool_consts; /* MAX_CONST_B, 16 */ - WINED3DSAMPLER_TEXTURE_TYPE sampler_type[max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS)]; + enum wined3d_sampler_texture_type sampler_type[max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS)]; BYTE bumpmat; /* MAX_TEXTURES, 8 */ BYTE luminanceparams; /* MAX_TEXTURES, 8 */ @@ -583,7 +592,7 @@ struct wined3d_shader_loop_state struct wined3d_shader_context { - struct wined3d_shader *shader; + const struct wined3d_shader *shader; const struct wined3d_gl_info *gl_info; const struct wined3d_shader_reg_maps *reg_maps; struct wined3d_shader_buffer *buffer; @@ -594,7 +603,7 @@ struct wined3d_shader_context struct wined3d_shader_register { - WINED3DSHADER_PARAM_REGISTER_TYPE type; + enum wined3d_shader_register_type type; UINT idx; UINT array_idx; const struct wined3d_shader_src_param *rel_addr; @@ -614,7 +623,7 @@ struct wined3d_shader_src_param { struct wined3d_shader_register reg; DWORD swizzle; - DWORD modifiers; + enum wined3d_shader_src_modifier modifiers; }; struct wined3d_shader_instruction @@ -634,7 +643,7 @@ struct wined3d_shader_semantic { WINED3DDECLUSAGE usage; UINT usage_idx; - WINED3DSAMPLER_TEXTURE_TYPE sampler_type; + enum wined3d_sampler_texture_type sampler_type; struct wined3d_shader_dst_param reg; }; @@ -758,7 +767,7 @@ struct wined3d_shader_backend_ops void (*shader_destroy)(struct wined3d_shader *shader); HRESULT (*shader_alloc_private)(struct wined3d_device *device); void (*shader_free_private)(struct wined3d_device *device); - BOOL (*shader_dirtifyable_constants)(void); + void (*shader_context_destroyed)(void *shader_priv, const struct wined3d_context *context); void (*shader_get_caps)(const struct wined3d_gl_info *gl_info, struct shader_caps *caps); BOOL (*shader_color_fixup_supported)(struct color_fixup_desc fixup); }; @@ -808,7 +817,7 @@ extern int num_lock DECLSPEC_HIDDEN; (vec)[3] = D3DCOLOR_A(dw); \ } while(0) -#define HIGHEST_TRANSFORMSTATE WINED3DTS_WORLDMATRIX(255) /* Highest value in WINED3DTRANSFORMSTATETYPE */ +#define HIGHEST_TRANSFORMSTATE WINED3D_TS_WORLD_MATRIX(255) /* Highest value in wined3d_transform_state. */ /* Checking of API calls */ /* --------------------- */ @@ -816,7 +825,7 @@ extern int num_lock DECLSPEC_HIDDEN; #define checkGLcall(A) \ do { \ GLint err; \ - if(!__WINE_IS_DEBUG_ON(_FIXME, __wine_dbch___default)) break; \ + if (!__WINE_IS_DEBUG_ON(_ERR, __wine_dbch___default)) break; \ err = glGetError(); \ if (err == GL_NO_ERROR) { \ TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \ @@ -846,9 +855,9 @@ do { /* Trace vector and strided data information */ #define TRACE_STRIDED(si, name) do { if (si->use_map & (1 << name)) \ - TRACE( #name "=(data:%p, stride:%d, format:%#x, vbo %d, stream %u)\n", \ - si->elements[name].data, si->elements[name].stride, si->elements[name].format->id, \ - si->elements[name].buffer_object, si->elements[name].stream_idx); } while(0) + TRACE( #name " = (data {%#x:%p}, stride %d, format %s, stream %u)\n", \ + si->elements[name].data.buffer_object, si->elements[name].data.addr, si->elements[name].stride, \ + debug_d3dformat(si->elements[name].format->id), si->elements[name].stream_idx); } while(0) /* Global variables */ extern const float identity[16] DECLSPEC_HIDDEN; @@ -894,13 +903,18 @@ enum wined3d_ffp_emit_idx WINED3D_FFP_EMIT_COUNT = 17 }; +struct wined3d_bo_address +{ + GLuint buffer_object; + const BYTE *addr; +}; + struct wined3d_stream_info_element { const struct wined3d_format *format; + struct wined3d_bo_address data; GLsizei stride; - const BYTE *data; UINT stream_idx; - GLuint buffer_object; }; struct wined3d_stream_info @@ -950,9 +964,9 @@ extern glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC #define STATE_IS_PIXELSHADER(a) ((a) == STATE_PIXELSHADER) #define STATE_TRANSFORM(a) (STATE_PIXELSHADER + (a)) -#define STATE_IS_TRANSFORM(a) ((a) >= STATE_TRANSFORM(1) && (a) <= STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255))) +#define STATE_IS_TRANSFORM(a) ((a) >= STATE_TRANSFORM(1) && (a) <= STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255))) -#define STATE_STREAMSRC (STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)) + 1) +#define STATE_STREAMSRC (STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)) + 1) #define STATE_IS_STREAMSRC(a) ((a) == STATE_STREAMSRC) #define STATE_INDEXBUFFER (STATE_STREAMSRC + 1) #define STATE_IS_INDEXBUFFER(a) ((a) == STATE_INDEXBUFFER) @@ -989,7 +1003,13 @@ extern glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC #define STATE_POINTSPRITECOORDORIGIN (STATE_FRONTFACE + 1) #define STATE_IS_POINTSPRITECOORDORIGIN(a) ((a) == STATE_POINTSPRITECOORDORIGIN) -#define STATE_HIGHEST (STATE_POINTSPRITECOORDORIGIN) +#define STATE_BASEVERTEXINDEX (STATE_POINTSPRITECOORDORIGIN + 1) +#define STATE_IS_BASEVERTEXINDEX(a) ((a) == STATE_BASEVERTEXINDEX) + +#define STATE_FRAMEBUFFER (STATE_BASEVERTEXINDEX + 1) +#define STATE_IS_FRAMEBUFFER(a) ((a) == STATE_FRAMEBUFFER) + +#define STATE_HIGHEST (STATE_FRAMEBUFFER) enum fogsource { FOGSOURCE_FFP, @@ -1029,14 +1049,15 @@ enum wined3d_event_query_result }; void wined3d_event_query_destroy(struct wined3d_event_query *query) DECLSPEC_HIDDEN; -enum wined3d_event_query_result wined3d_event_query_finish(struct wined3d_event_query *query, - struct wined3d_device *device) DECLSPEC_HIDDEN; -void wined3d_event_query_issue(struct wined3d_event_query *query, struct wined3d_device *device) DECLSPEC_HIDDEN; +enum wined3d_event_query_result wined3d_event_query_finish(const struct wined3d_event_query *query, + const struct wined3d_device *device) DECLSPEC_HIDDEN; +void wined3d_event_query_issue(struct wined3d_event_query *query, const struct wined3d_device *device) DECLSPEC_HIDDEN; BOOL wined3d_event_query_supported(const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN; struct wined3d_context { const struct wined3d_gl_info *gl_info; + const struct StateEntry *state_table; /* State dirtification * dirtyArray is an array that contains markers for dirty states. numDirtyEntries states are dirty, their numbers are in indices * 0...numDirtyEntries - 1. isStateDirty is a redundant copy of the dirtyArray. Technically only one of them would be needed, @@ -1053,7 +1074,6 @@ struct wined3d_context /* Stores some information about the context state for optimization */ WORD render_offscreen : 1; - WORD draw_buffer_dirty : 1; WORD last_was_rhw : 1; /* true iff last draw_primitive was in xyzrhw mode */ WORD last_was_pshader : 1; WORD last_was_vshader : 1; @@ -1067,6 +1087,7 @@ struct wined3d_context WORD current : 1; WORD destroyed : 1; WORD valid : 1; + WORD padding : 1; BYTE texShaderBumpMap; /* MAX_TEXTURES, 8 */ BYTE lastWasPow2Texture; /* MAX_TEXTURES, 8 */ DWORD numbered_array_mask; @@ -1074,13 +1095,14 @@ struct wined3d_context GLenum untracked_materials[2]; UINT blit_w, blit_h; enum fogsource fog_source; - - char *vshader_const_dirty, *pshader_const_dirty; + DWORD active_texture; + DWORD texture_type[MAX_COMBINED_SAMPLERS]; /* The actual opengl context */ UINT level; HGLRC restore_ctx; HDC restore_dc; + int restore_pf; HGLRC glCtx; HWND win_handle; HDC hdc; @@ -1092,12 +1114,12 @@ struct wined3d_context struct list fbo_list; struct list fbo_destroy_list; struct fbo_entry *current_fbo; - GLuint dst_fbo; GLuint fbo_read_binding; GLuint fbo_draw_binding; BOOL rebind_fbo; struct wined3d_surface **blit_targets; GLenum *draw_buffers; + DWORD draw_buffers_mask; /* Enabled draw buffers, 31 max. */ /* Queries */ GLuint *free_occlusion_queries; @@ -1117,7 +1139,13 @@ struct wined3d_context GLuint dummy_arbfp_prog; }; -typedef void (*APPLYSTATEFUNC)(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *ctx); +struct wined3d_fb_state +{ + struct wined3d_surface **render_targets; + struct wined3d_surface *depth_stencil; +}; + +typedef void (*APPLYSTATEFUNC)(struct wined3d_context *ctx, const struct wined3d_state *state, DWORD state_id); struct StateEntry { @@ -1129,7 +1157,7 @@ struct StateEntryTemplate { DWORD state; struct StateEntry content; - GL_SupportedExt extension; + enum wined3d_gl_extension extension; }; struct fragment_caps @@ -1178,13 +1206,13 @@ struct blit_shader { HRESULT (*alloc_private)(struct wined3d_device *device); void (*free_private)(struct wined3d_device *device); - HRESULT (*set_shader)(void *blit_priv, const struct wined3d_gl_info *gl_info, struct wined3d_surface *surface); + HRESULT (*set_shader)(void *blit_priv, struct wined3d_context *context, const struct wined3d_surface *surface); void (*unset_shader)(const struct wined3d_gl_info *gl_info); BOOL (*blit_supported)(const struct wined3d_gl_info *gl_info, enum wined3d_blit_op blit_op, - const RECT *src_rect, DWORD src_usage, WINED3DPOOL src_pool, const struct wined3d_format *src_format, - const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool, const struct wined3d_format *dst_format); + const RECT *src_rect, DWORD src_usage, enum wined3d_pool src_pool, const struct wined3d_format *src_format, + const RECT *dst_rect, DWORD dst_usage, enum wined3d_pool dst_pool, const struct wined3d_format *dst_format); HRESULT (*color_fill)(struct wined3d_device *device, struct wined3d_surface *dst_surface, - const RECT *dst_rect, const WINED3DCOLORVALUE *color); + const RECT *dst_rect, const struct wined3d_color *color); HRESULT (*depth_fill)(struct wined3d_device *device, struct wined3d_surface *surface, const RECT *rect, float depth); }; @@ -1194,30 +1222,31 @@ extern const struct blit_shader arbfp_blit DECLSPEC_HIDDEN; extern const struct blit_shader cpu_blit DECLSPEC_HIDDEN; const struct blit_shader *wined3d_select_blitter(const struct wined3d_gl_info *gl_info, enum wined3d_blit_op blit_op, - const RECT *src_rect, DWORD src_usage, WINED3DPOOL src_pool, const struct wined3d_format *src_format, - const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool, const struct wined3d_format *dst_format) + const RECT *src_rect, DWORD src_usage, enum wined3d_pool src_pool, const struct wined3d_format *src_format, + const RECT *dst_rect, DWORD dst_usage, enum wined3d_pool dst_pool, const struct wined3d_format *dst_format) DECLSPEC_HIDDEN; /* Temporary blit_shader helper functions */ -HRESULT arbfp_blit_surface(struct wined3d_device *device, struct wined3d_surface *src_surface, - const RECT *src_rect, struct wined3d_surface *dst_surface, const RECT *dst_rect_in, - enum wined3d_blit_op blit_op, DWORD Filter) DECLSPEC_HIDDEN; +HRESULT arbfp_blit_surface(struct wined3d_device *device, DWORD filter, + struct wined3d_surface *src_surface, const RECT *src_rect, + struct wined3d_surface *dst_surface, const RECT *dst_rect) DECLSPEC_HIDDEN; -struct wined3d_context *context_acquire(struct wined3d_device *device, struct wined3d_surface *target) DECLSPEC_HIDDEN; +struct wined3d_context *context_acquire(const struct wined3d_device *device, + struct wined3d_surface *target) DECLSPEC_HIDDEN; void context_alloc_event_query(struct wined3d_context *context, struct wined3d_event_query *query) DECLSPEC_HIDDEN; void context_alloc_occlusion_query(struct wined3d_context *context, struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN; -void context_apply_blit_state(struct wined3d_context *context, struct wined3d_device *device) DECLSPEC_HIDDEN; -BOOL context_apply_clear_state(struct wined3d_context *context, struct wined3d_device *device, - UINT rt_count, struct wined3d_surface **rts, struct wined3d_surface *depth_stencil) DECLSPEC_HIDDEN; +void context_apply_blit_state(struct wined3d_context *context, const struct wined3d_device *device) DECLSPEC_HIDDEN; +BOOL context_apply_clear_state(struct wined3d_context *context, const struct wined3d_device *device, + UINT rt_count, const struct wined3d_fb_state *fb) DECLSPEC_HIDDEN; BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_device *device) DECLSPEC_HIDDEN; void context_apply_fbo_state_blit(struct wined3d_context *context, GLenum target, struct wined3d_surface *render_target, struct wined3d_surface *depth_stencil, DWORD location) DECLSPEC_HIDDEN; -void context_attach_depth_stencil_fbo(struct wined3d_context *context, - GLenum fbo_target, struct wined3d_surface *depth_stencil, BOOL use_render_buffer) DECLSPEC_HIDDEN; -void context_bind_fbo(struct wined3d_context *context, GLenum target, GLuint *fbo) DECLSPEC_HIDDEN; -void context_check_fbo_status(struct wined3d_context *context, GLenum target) DECLSPEC_HIDDEN; +void context_active_texture(struct wined3d_context *context, const struct wined3d_gl_info *gl_info, + unsigned int unit) DECLSPEC_HIDDEN; +void context_bind_texture(struct wined3d_context *context, GLenum target, GLuint name) DECLSPEC_HIDDEN; +void context_check_fbo_status(const struct wined3d_context *context, GLenum target) DECLSPEC_HIDDEN; struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, struct wined3d_surface *target, const struct wined3d_format *ds_format) DECLSPEC_HIDDEN; void context_destroy(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN; @@ -1225,29 +1254,27 @@ void context_free_event_query(struct wined3d_event_query *query) DECLSPEC_HIDDEN void context_free_occlusion_query(struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN; struct wined3d_context *context_get_current(void) DECLSPEC_HIDDEN; DWORD context_get_tls_idx(void) DECLSPEC_HIDDEN; +void context_invalidate_state(struct wined3d_context *context, DWORD state_id) DECLSPEC_HIDDEN; void context_release(struct wined3d_context *context) DECLSPEC_HIDDEN; -void context_resource_released(struct wined3d_device *device, - struct wined3d_resource *resource, WINED3DRESOURCETYPE type) DECLSPEC_HIDDEN; -void context_resource_unloaded(struct wined3d_device *device, - struct wined3d_resource *resource, WINED3DRESOURCETYPE type) DECLSPEC_HIDDEN; +void context_resource_released(const struct wined3d_device *device, + struct wined3d_resource *resource, enum wined3d_resource_type type) DECLSPEC_HIDDEN; +void context_resource_unloaded(const struct wined3d_device *device, + struct wined3d_resource *resource, enum wined3d_resource_type type) DECLSPEC_HIDDEN; BOOL context_set_current(struct wined3d_context *ctx) DECLSPEC_HIDDEN; void context_set_draw_buffer(struct wined3d_context *context, GLenum buffer) DECLSPEC_HIDDEN; void context_set_tls_idx(DWORD idx) DECLSPEC_HIDDEN; -void context_surface_update(struct wined3d_context *context, struct wined3d_surface *surface) DECLSPEC_HIDDEN; - -/* Macros for doing basic GPU detection based on opengl capabilities */ -#define WINE_D3D6_CAPABLE(gl_info) (gl_info->supported[ARB_MULTITEXTURE]) -#define WINE_D3D7_CAPABLE(gl_info) (gl_info->supported[ARB_TEXTURE_COMPRESSION] && gl_info->supported[ARB_TEXTURE_CUBE_MAP] && gl_info->supported[ARB_TEXTURE_ENV_DOT3]) -#define WINE_D3D8_CAPABLE(gl_info) WINE_D3D7_CAPABLE(gl_info) && (gl_info->supported[ARB_MULTISAMPLE] && gl_info->supported[ARB_TEXTURE_BORDER_CLAMP]) -#define WINE_D3D9_CAPABLE(gl_info) WINE_D3D8_CAPABLE(gl_info) && (gl_info->supported[ARB_FRAGMENT_PROGRAM] && gl_info->supported[ARB_VERTEX_SHADER]) -#define WINE_D3D10_CAPABLE(gl_info) WINE_D3D9_CAPABLE(gl_info) && (gl_info->supported[EXT_GPU_SHADER4]) +void context_state_drawbuf(struct wined3d_context *context, + const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN; +void context_state_fb(struct wined3d_context *context, + const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN; +void context_surface_update(struct wined3d_context *context, const struct wined3d_surface *surface) DECLSPEC_HIDDEN; /***************************************************************************** * Internal representation of a light */ struct wined3d_light_info { - WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */ + struct wined3d_light OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */ DWORD OriginalIndex; LONG glIndex; BOOL enabled; @@ -1262,7 +1289,7 @@ struct wined3d_light_info }; /* The default light parameters */ -extern const WINED3DLIGHT WINED3D_default_light DECLSPEC_HIDDEN; +extern const struct wined3d_light WINED3D_default_light DECLSPEC_HIDDEN; struct wined3d_pixel_format { @@ -1276,45 +1303,6 @@ struct wined3d_pixel_format int numSamples; }; -/* The driver names reflect the lowest GPU supported - * by a certain driver, so DRIVER_AMD_R300 supports - * R3xx, R4xx and R5xx GPUs. */ -enum wined3d_display_driver -{ - DRIVER_AMD_RAGE_128PRO, - DRIVER_AMD_R100, - DRIVER_AMD_R300, - DRIVER_AMD_R600, - DRIVER_INTEL_GMA800, - DRIVER_INTEL_GMA900, - DRIVER_INTEL_GMA950, - DRIVER_INTEL_GMA3000, - DRIVER_NVIDIA_TNT, - DRIVER_NVIDIA_GEFORCE2MX, - DRIVER_NVIDIA_GEFORCEFX, - DRIVER_NVIDIA_GEFORCE6, - DRIVER_UNKNOWN -}; - -enum wined3d_driver_model -{ - DRIVER_MODEL_WIN9X, - DRIVER_MODEL_NT40, - DRIVER_MODEL_NT5X, - DRIVER_MODEL_NT6X -}; - -enum wined3d_gl_vendor -{ - GL_VENDOR_UNKNOWN, - GL_VENDOR_APPLE, - GL_VENDOR_FGLRX, - GL_VENDOR_INTEL, - GL_VENDOR_MESA, - GL_VENDOR_NVIDIA, -}; - - enum wined3d_pci_vendor { HW_VENDOR_SOFTWARE = 0x0000, @@ -1359,7 +1347,12 @@ enum wined3d_pci_device CARD_AMD_RADEON_HD5850 = 0x6898, CARD_AMD_RADEON_HD5870 = 0x6899, CARD_AMD_RADEON_HD5900 = 0x689c, - CARD_AMD_RADEON_HD6310 = 0x9803, + CARD_AMD_RADEON_HD6300 = 0x9803, + CARD_AMD_RADEON_HD6400 = 0x6770, + CARD_AMD_RADEON_HD6410D = 0x9644, + CARD_AMD_RADEON_HD6550D = 0x9640, + CARD_AMD_RADEON_HD6600 = 0x6758, + CARD_AMD_RADEON_HD6600M = 0x6741, CARD_AMD_RADEON_HD6800 = 0x6739, CARD_AMD_RADEON_HD6900 = 0x6719, @@ -1411,22 +1404,52 @@ enum wined3d_pci_device CARD_NVIDIA_GEFORCE_GT440 = 0x0de0, CARD_NVIDIA_GEFORCE_GTS450 = 0x0dc4, CARD_NVIDIA_GEFORCE_GTX460 = 0x0e22, + CARD_NVIDIA_GEFORCE_GTX460M = 0x0dd1, CARD_NVIDIA_GEFORCE_GTX465 = 0x06c4, CARD_NVIDIA_GEFORCE_GTX470 = 0x06cd, CARD_NVIDIA_GEFORCE_GTX480 = 0x06c0, - CARD_NVIDIA_GEFORCE_GTX560 = 0x1200, + CARD_NVIDIA_GEFORCE_GT540M = 0x0df4, + CARD_NVIDIA_GEFORCE_GTX550 = 0x1244, + CARD_NVIDIA_GEFORCE_GT555M = 0x04b8, + CARD_NVIDIA_GEFORCE_GTX560TI = 0x1200, + CARD_NVIDIA_GEFORCE_GTX560 = 0x1201, CARD_NVIDIA_GEFORCE_GTX570 = 0x1081, CARD_NVIDIA_GEFORCE_GTX580 = 0x1080, + CARD_INTEL_830M = 0x3577, + CARD_INTEL_855GM = 0x3582, CARD_INTEL_845G = 0x2562, - CARD_INTEL_I830G = 0x3577, - CARD_INTEL_I855G = 0x3582, - CARD_INTEL_I865G = 0x2572, - CARD_INTEL_I915G = 0x2582, - CARD_INTEL_I915GM = 0x2592, - CARD_INTEL_I945GM = 0x27a2, /* Same as GMA 950? */ - CARD_INTEL_X3100 = 0x2a02, /* Found in Macs. Same as GM965/GL960 */ + CARD_INTEL_865G = 0x2572, + CARD_INTEL_915G = 0x2582, + CARD_INTEL_E7221G = 0x258a, + CARD_INTEL_915GM = 0x2592, + CARD_INTEL_945G = 0x2772, + CARD_INTEL_945GM = 0x27a2, + CARD_INTEL_945GME = 0x27ae, + CARD_INTEL_Q35 = 0x29b2, + CARD_INTEL_G33 = 0x29c2, + CARD_INTEL_Q33 = 0x29d2, + CARD_INTEL_PNVG = 0xa001, + CARD_INTEL_PNVM = 0xa011, + CARD_INTEL_965Q = 0x2992, + CARD_INTEL_965G = 0x2982, + CARD_INTEL_946GZ = 0x2972, + CARD_INTEL_965GM = 0x2a02, + CARD_INTEL_965GME = 0x2a12, CARD_INTEL_GM45 = 0x2a42, + CARD_INTEL_IGD = 0x2e02, + CARD_INTEL_Q45 = 0x2e12, + CARD_INTEL_G45 = 0x2e22, + CARD_INTEL_G41 = 0x2e32, + CARD_INTEL_B43 = 0x2e92, + CARD_INTEL_ILKD = 0x0042, + CARD_INTEL_ILKM = 0x0046, + CARD_INTEL_SNBD = 0x0122, + CARD_INTEL_SNBM = 0x0126, + CARD_INTEL_SNBS = 0x010a, + CARD_INTEL_IVBD = 0x0162, + CARD_INTEL_IVBM = 0x0166, + CARD_INTEL_IVBS = 0x015a, }; struct wined3d_fbo_ops @@ -1458,6 +1481,7 @@ struct wined3d_gl_limits UINT lights; UINT textures; UINT texture_stages; + UINT texture_coords; UINT fragment_samplers; UINT vertex_samplers; UINT combined_samplers; @@ -1468,10 +1492,11 @@ struct wined3d_gl_limits UINT texture3d_size; float pointsize_max; float pointsize_min; - UINT point_sprite_units; UINT blends; UINT anisotropy; float shininess; + UINT samples; + UINT vertex_attribs; UINT glsl_varyings; UINT glsl_vs_float_constants; @@ -1495,7 +1520,7 @@ struct wined3d_gl_info DWORD reserved_glsl_constants; DWORD quirks; BOOL supported[WINED3D_GL_EXT_COUNT]; - GLint wrap_lookup[WINED3DTADDRESS_MIRRORONCE - WINED3DTADDRESS_WRAP + 1]; + GLint wrap_lookup[WINED3D_TADDRESS_MIRROR_ONCE - WINED3D_TADDRESS_WRAP + 1]; struct wined3d_fbo_ops fbo_ops; #define USE_GL_FUNC(type, pfn, ext, replace) type pfn; @@ -1524,13 +1549,16 @@ struct wined3d_adapter { UINT ordinal; BOOL opengl; - POINT monitorPoint; + + POINT monitorPoint; + SIZE screen_size; + enum wined3d_format_id screen_format; + struct wined3d_gl_info gl_info; struct wined3d_driver_info driver_info; WCHAR DeviceName[CCHDEVICENAME]; /* DeviceName for use with e.g. ChangeDisplaySettings */ - int nCfgs; + unsigned int cfg_count; struct wined3d_pixel_format *cfgs; - BOOL brokenStencil; /* Set on cards which only offer mixed depth+stencil */ unsigned int TextureRam; /* Amount of texture memory both video ram + AGP/TurboCache/HyperMemory/.. */ unsigned int UsedTextureRam; LUID luid; @@ -1540,9 +1568,10 @@ struct wined3d_adapter const struct blit_shader *blitter; }; +unsigned int adapter_adjust_memory(struct wined3d_adapter *adapter, int amount) DECLSPEC_HIDDEN; + BOOL initPixelFormats(struct wined3d_gl_info *gl_info, enum wined3d_pci_vendor vendor) DECLSPEC_HIDDEN; BOOL initPixelFormatsNoGL(struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN; -extern unsigned int WineD3DAdapterChangeGLRam(struct wined3d_device *device, int glram) DECLSPEC_HIDDEN; extern void add_gl_compat_wrappers(struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN; /***************************************************************************** @@ -1552,8 +1581,8 @@ struct WineD3DRectPatch { UINT Handle; float *mem; - WineDirect3DVertexStridedData strided; - WINED3DRECTPATCH_INFO RectPatchInfo; + struct wined3d_strided_data strided; + struct wined3d_rect_patch_info rect_patch_info; float numSegs[4]; char has_normals, has_texcoords; struct list entry; @@ -1614,22 +1643,24 @@ struct ffp_frag_desc extern const struct wine_rb_functions wined3d_ffp_frag_program_rb_functions DECLSPEC_HIDDEN; extern const struct wined3d_parent_ops wined3d_null_parent_ops DECLSPEC_HIDDEN; -void gen_ffp_frag_op(struct wined3d_stateblock *stateblock, struct ffp_frag_settings *settings, - BOOL ignore_textype) DECLSPEC_HIDDEN; +void gen_ffp_frag_op(const struct wined3d_device *device, const struct wined3d_state *state, + struct ffp_frag_settings *settings, BOOL ignore_textype) DECLSPEC_HIDDEN; const struct ffp_frag_desc *find_ffp_frag_shader(const struct wine_rb_tree *fragment_shaders, const struct ffp_frag_settings *settings) DECLSPEC_HIDDEN; void add_ffp_frag_shader(struct wine_rb_tree *shaders, struct ffp_frag_desc *desc) DECLSPEC_HIDDEN; +void wined3d_get_draw_rect(const struct wined3d_state *state, RECT *rect) DECLSPEC_HIDDEN; struct wined3d { LONG ref; void *parent; + DWORD flags; UINT dxVersion; UINT adapter_count; struct wined3d_adapter adapters[1]; }; -HRESULT wined3d_init(struct wined3d *wined3d, UINT version, void *parent) DECLSPEC_HIDDEN; +HRESULT wined3d_init(struct wined3d *wined3d, UINT version, DWORD flags, void *parent) DECLSPEC_HIDDEN; BOOL wined3d_register_window(HWND window, struct wined3d_device *device) DECLSPEC_HIDDEN; void wined3d_unregister_window(HWND window) DECLSPEC_HIDDEN; @@ -1641,12 +1672,6 @@ void wined3d_unregister_window(HWND window) DECLSPEC_HIDDEN; /* Multithreaded flag. Removed from the public header to signal that IWineD3D::CreateDevice ignores it */ #define WINED3DCREATE_MULTITHREADED 0x00000004 -struct wined3d_fb_state -{ - struct wined3d_surface **render_targets; - struct wined3d_surface *depth_stencil; -}; - struct wined3d_device { LONG ref; @@ -1677,11 +1702,11 @@ struct wined3d_device const struct blit_shader *blitter; unsigned int max_ffp_textures; + DWORD vshader_version, pshader_version; DWORD d3d_vshader_constantF, d3d_pshader_constantF; /* Advertised d3d caps, not GL ones */ DWORD vs_clipping; WORD view_ident : 1; /* true iff view matrix is identity */ - WORD untransformed : 1; WORD vertexBlendUsed : 1; /* To avoid needless setting of the blend matrices */ WORD isRecordingState : 1; WORD isInDraw : 1; @@ -1692,7 +1717,7 @@ struct wined3d_device WORD useDrawStridedSlow : 1; WORD instancedDraw : 1; WORD filter_messages : 1; - WORD padding : 4; + WORD padding : 5; BYTE fixed_function_usage_map; /* MAX_TEXTURES, 8 */ @@ -1705,8 +1730,7 @@ struct wined3d_device struct wined3d_stateblock *updateStateBlock; /* Internal use fields */ - WINED3DDEVICE_CREATION_PARAMETERS createParms; - WINED3DDEVTYPE devType; + struct wined3d_device_creation_parameters create_parms; HWND focus_window; struct wined3d_swapchain **swapchains; @@ -1714,7 +1738,6 @@ struct wined3d_device struct list resources; /* a linked list to track resources created by the device */ struct list shaders; /* a linked list to track shaders (pixel and vertex) */ - unsigned int highest_dirty_ps_const, highest_dirty_vs_const; /* Render Target Support */ DWORD valid_rt_mask; @@ -1722,16 +1745,8 @@ struct wined3d_device struct wined3d_surface *onscreen_depth_stencil; struct wined3d_surface *auto_depth_stencil; - /* palettes texture management */ - PALETTEENTRY **palettes; - UINT palette_count; - UINT currentPalette; - /* For rendering to a texture using glCopyTexImage */ GLuint depth_blt_texture; - GLuint depth_blt_rb; - UINT depth_blt_rb_w; - UINT depth_blt_rb_h; /* Cursor management */ UINT xHotSpot; @@ -1746,11 +1761,10 @@ struct wined3d_device struct wined3d_surface *logo_surface; /* Textures for when no other textures are mapped */ - UINT dummyTextureName[MAX_TEXTURES]; - - /* DirectDraw stuff */ - DWORD ddraw_width, ddraw_height; - enum wined3d_format_id ddraw_format; + UINT dummy_texture_2d[MAX_COMBINED_SAMPLERS]; + UINT dummy_texture_rect[MAX_COMBINED_SAMPLERS]; + UINT dummy_texture_3d[MAX_COMBINED_SAMPLERS]; + UINT dummy_texture_cube[MAX_COMBINED_SAMPLERS]; /* With register combiners we can skip junk texture stages */ DWORD texUnitMap[MAX_COMBINED_SAMPLERS]; @@ -1758,7 +1772,7 @@ struct wined3d_device /* Stream source management */ struct wined3d_stream_info strided_streams; - const WineDirect3DVertexStridedData *up_strided; + const struct wined3d_strided_data *up_strided; struct wined3d_event_query *buffer_queries[MAX_ATTRIBS]; unsigned int num_buffer_queries; @@ -1770,38 +1784,43 @@ struct wined3d_device #define PATCHMAP_SIZE 43 #define PATCHMAP_HASHFUNC(x) ((x) % PATCHMAP_SIZE) /* Primitive and simple function */ struct list patches[PATCHMAP_SIZE]; - struct WineD3DRectPatch *currentPatch; }; -HRESULT device_clear_render_targets(struct wined3d_device *device, UINT rt_count, struct wined3d_surface **rts, - struct wined3d_surface *depth_stencil, UINT rect_count, const RECT *rects, const RECT *draw_rect, - DWORD flags, const WINED3DCOLORVALUE *color, float depth, DWORD stencil) DECLSPEC_HIDDEN; +HRESULT device_clear_render_targets(struct wined3d_device *device, UINT rt_count, const struct wined3d_fb_state *fb, + UINT rect_count, const RECT *rects, const RECT *draw_rect, DWORD flags, + const struct wined3d_color *color, float depth, DWORD stencil) DECLSPEC_HIDDEN; BOOL device_context_add(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN; void device_context_remove(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN; -void device_get_draw_rect(struct wined3d_device *device, RECT *rect) DECLSPEC_HIDDEN; HRESULT device_init(struct wined3d_device *device, struct wined3d *wined3d, - UINT adapter_idx, WINED3DDEVTYPE device_type, HWND focus_window, DWORD flags, - struct wined3d_device_parent *device_parent) DECLSPEC_HIDDEN; -void device_preload_textures(struct wined3d_device *device) DECLSPEC_HIDDEN; + UINT adapter_idx, enum wined3d_device_type device_type, HWND focus_window, DWORD flags, + BYTE surface_alignment, struct wined3d_device_parent *device_parent) DECLSPEC_HIDDEN; +void device_preload_textures(const struct wined3d_device *device) DECLSPEC_HIDDEN; LRESULT device_process_message(struct wined3d_device *device, HWND window, BOOL unicode, UINT message, WPARAM wparam, LPARAM lparam, WNDPROC proc) DECLSPEC_HIDDEN; void device_resource_add(struct wined3d_device *device, struct wined3d_resource *resource) DECLSPEC_HIDDEN; void device_resource_released(struct wined3d_device *device, struct wined3d_resource *resource) DECLSPEC_HIDDEN; void device_stream_info_from_declaration(struct wined3d_device *device, - BOOL use_vshader, struct wined3d_stream_info *stream_info, BOOL *fixup) DECLSPEC_HIDDEN; + struct wined3d_stream_info *stream_info, BOOL *fixup) DECLSPEC_HIDDEN; void device_switch_onscreen_ds(struct wined3d_device *device, struct wined3d_context *context, struct wined3d_surface *depth_stencil) DECLSPEC_HIDDEN; void device_update_stream_info(struct wined3d_device *device, const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN; void device_update_tex_unit_map(struct wined3d_device *device) DECLSPEC_HIDDEN; -void IWineD3DDeviceImpl_MarkStateDirty(struct wined3d_device *device, DWORD state) DECLSPEC_HIDDEN; +void device_invalidate_state(const struct wined3d_device *device, DWORD state) DECLSPEC_HIDDEN; -static inline BOOL isStateDirty(struct wined3d_context *context, DWORD state) +static inline BOOL isStateDirty(const struct wined3d_context *context, DWORD state) { DWORD idx = state / (sizeof(*context->isStateDirty) * CHAR_BIT); BYTE shift = state & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1); return context->isStateDirty[idx] & (1 << shift); } +static inline void invalidate_active_texture(const struct wined3d_device *device, struct wined3d_context *context) +{ + DWORD sampler = device->rev_tex_unit_map[context->active_texture]; + if (sampler != WINED3D_UNMAPPED_STAGE) + context_invalidate_state(context, STATE_SAMPLER(sampler)); +} + #define WINED3D_RESOURCE_ACCESS_GPU 0x1 #define WINED3D_RESOURCE_ACCESS_CPU 0x2 /* SCRATCH is mostly the same as CPU, but can't be used by the GPU at all, @@ -1817,12 +1836,12 @@ struct wined3d_resource { LONG ref; struct wined3d_device *device; - WINED3DRESOURCETYPE resourceType; + enum wined3d_resource_type type; const struct wined3d_format *format; - WINED3DMULTISAMPLE_TYPE multisample_type; + enum wined3d_multisample_type multisample_type; UINT multisample_quality; DWORD usage; - WINED3DPOOL pool; + enum wined3d_pool pool; DWORD access_flags; UINT width; UINT height; @@ -1840,25 +1859,21 @@ struct wined3d_resource }; void resource_cleanup(struct wined3d_resource *resource) DECLSPEC_HIDDEN; -HRESULT resource_free_private_data(struct wined3d_resource *resource, REFGUID guid) DECLSPEC_HIDDEN; DWORD resource_get_priority(const struct wined3d_resource *resource) DECLSPEC_HIDDEN; -HRESULT resource_get_private_data(const struct wined3d_resource *resource, REFGUID guid, - void *data, DWORD *data_size) DECLSPEC_HIDDEN; HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *device, - WINED3DRESOURCETYPE resource_type, const struct wined3d_format *format, - WINED3DMULTISAMPLE_TYPE multisample_type, UINT multisample_quality, - DWORD usage, WINED3DPOOL pool, UINT width, UINT height, UINT depth, UINT size, + enum wined3d_resource_type type, const struct wined3d_format *format, + enum wined3d_multisample_type multisample_type, UINT multisample_quality, + DWORD usage, enum wined3d_pool pool, UINT width, UINT height, UINT depth, UINT size, void *parent, const struct wined3d_parent_ops *parent_ops, const struct wined3d_resource_ops *resource_ops) DECLSPEC_HIDDEN; DWORD resource_set_priority(struct wined3d_resource *resource, DWORD priority) DECLSPEC_HIDDEN; -HRESULT resource_set_private_data(struct wined3d_resource *resource, REFGUID guid, - const void *data, DWORD data_size, DWORD flags) DECLSPEC_HIDDEN; void resource_unload(struct wined3d_resource *resource) DECLSPEC_HIDDEN; /* Tests show that the start address of resources is 32 byte aligned */ #define RESOURCE_ALIGNMENT 16 -typedef enum winetexturestates { +enum wined3d_texture_state +{ WINED3DTEXSTA_ADDRESSU = 0, WINED3DTEXSTA_ADDRESSV = 1, WINED3DTEXSTA_ADDRESSW = 2, @@ -1871,7 +1886,7 @@ typedef enum winetexturestates { WINED3DTEXSTA_SRGBTEXTURE = 9, WINED3DTEXSTA_SHADOW = 10, MAX_WINETEXTURESTATES = 11, -} winetexturestates; +}; enum WINED3DSRGB { @@ -1890,10 +1905,10 @@ struct gl_texture struct wined3d_texture_ops { HRESULT (*texture_bind)(struct wined3d_texture *texture, - const struct wined3d_gl_info *gl_info, BOOL srgb); + struct wined3d_context *context, BOOL srgb); void (*texture_preload)(struct wined3d_texture *texture, enum WINED3DSRGB srgb); void (*texture_sub_resource_add_dirty_region)(struct wined3d_resource *sub_resource, - const WINED3DBOX *dirty_region); + const struct wined3d_box *dirty_region); void (*texture_sub_resource_cleanup)(struct wined3d_resource *sub_resource); }; @@ -1911,7 +1926,7 @@ struct wined3d_texture UINT level_count; float pow2_matrix[16]; UINT lod; - WINED3DTEXTUREFILTERTYPE filter_type; + enum wined3d_texture_filter_type filter_type; LONG bind_count; DWORD sampler; DWORD flags; @@ -1943,8 +1958,8 @@ struct wined3d_volume struct wined3d_texture *container; BOOL lockable; BOOL locked; - WINED3DBOX lockedBox; - WINED3DBOX dirtyBox; + struct wined3d_box lockedBox; + struct wined3d_box dirtyBox; BOOL dirty; }; @@ -1953,20 +1968,16 @@ static inline struct wined3d_volume *volume_from_resource(struct wined3d_resourc return CONTAINING_RECORD(resource, struct wined3d_volume, resource); } -void volume_add_dirty_box(struct wined3d_volume *volume, const WINED3DBOX *dirty_box) DECLSPEC_HIDDEN; -void volume_load(struct wined3d_volume *volume, UINT level, BOOL srgb_mode) DECLSPEC_HIDDEN; +void volume_add_dirty_box(struct wined3d_volume *volume, const struct wined3d_box *dirty_box) DECLSPEC_HIDDEN; +void volume_load(const struct wined3d_volume *volume, struct wined3d_context *context, UINT level, BOOL srgb_mode) DECLSPEC_HIDDEN; void volume_set_container(struct wined3d_volume *volume, struct wined3d_texture *container) DECLSPEC_HIDDEN; -/***************************************************************************** - * Structure for DIB Surfaces (GetDC and GDI surfaces) - */ -typedef struct wineD3DSurface_DIB { +struct wined3d_surface_dib +{ HBITMAP DIBsection; - void* bitmap_data; + void *bitmap_data; UINT bitmap_size; - HGDIOBJ holdbitmap; - BOOL client_memory; -} wineD3DSurface_DIB; +}; struct wined3d_renderbuffer_entry { @@ -1982,17 +1993,11 @@ struct fbo_entry struct wined3d_surface **render_targets; struct wined3d_surface *depth_stencil; DWORD location; + DWORD rt_mask; BOOL attached; GLuint id; }; -struct wined3d_clipper -{ - LONG ref; - - HWND hWnd; -}; - enum wined3d_container_type { WINED3D_CONTAINER_NONE = 0, @@ -2014,20 +2019,9 @@ struct wined3d_subresource_container struct wined3d_surface_ops { HRESULT (*surface_private_setup)(struct wined3d_surface *surface); - void (*surface_cleanup)(struct wined3d_surface *surface); void (*surface_realize_palette)(struct wined3d_surface *surface); - HRESULT (*surface_draw_overlay)(struct wined3d_surface *surface); - void (*surface_preload)(struct wined3d_surface *surface); void (*surface_map)(struct wined3d_surface *surface, const RECT *rect, DWORD flags); void (*surface_unmap)(struct wined3d_surface *surface); - HRESULT (*surface_getdc)(struct wined3d_surface *surface); - HRESULT (*surface_flip)(struct wined3d_surface *surface, struct wined3d_surface *override); - HRESULT (*surface_blt)(struct wined3d_surface *dst_surface, const RECT *dst_rect, - struct wined3d_surface *src_surface, const RECT *src_rect, DWORD flags, - const WINEDDBLTFX *fx, WINED3DTEXTUREFILTERTYPE filter); - HRESULT (*surface_bltfast)(struct wined3d_surface *dst_surface, DWORD dst_x, DWORD dst_y, - struct wined3d_surface *src_surface, const RECT *src_rect, DWORD trans); - HRESULT (*surface_set_mem)(struct wined3d_surface *surface, void *mem); }; struct wined3d_surface @@ -2036,7 +2030,7 @@ struct wined3d_surface const struct wined3d_surface_ops *surface_ops; struct wined3d_subresource_container container; struct wined3d_palette *palette; /* D3D7 style palette handling */ - PALETTEENTRY *palette9; /* D3D8/9 style palette handling */ + DWORD draw_binding; DWORD flags; @@ -2045,10 +2039,12 @@ struct wined3d_surface UINT pow2Height; /* A method to retrieve the drawable size. Not in the Vtable to make it changeable */ - void (*get_drawable_size)(struct wined3d_context *context, UINT *width, UINT *height); + void (*get_drawable_size)(const struct wined3d_context *context, UINT *width, UINT *height); /* PBO */ GLuint pbo; + GLuint rb_multisample; + GLuint rb_resolved; GLuint texture_name; GLuint texture_name_srgb; GLint texture_level; @@ -2060,25 +2056,22 @@ struct wined3d_surface #define MAXLOCKCOUNT 50 /* After this amount of locks do not free the sysmem copy */ /* For GetDC */ - wineD3DSurface_DIB dib; + struct wined3d_surface_dib dib; HDC hDC; /* Color keys for DDraw */ - WINEDDCOLORKEY DestBltCKey; - WINEDDCOLORKEY DestOverlayCKey; - WINEDDCOLORKEY SrcOverlayCKey; - WINEDDCOLORKEY SrcBltCKey; + struct wined3d_color_key dst_blt_color_key; + struct wined3d_color_key src_blt_color_key; + struct wined3d_color_key dst_overlay_color_key; + struct wined3d_color_key src_overlay_color_key; DWORD CKeyFlags; - WINEDDCOLORKEY glCKey; + struct wined3d_color_key gl_color_key; struct list renderbuffers; - struct wined3d_renderbuffer_entry *current_renderbuffer; + const struct wined3d_renderbuffer_entry *current_renderbuffer; SIZE ds_current_size; - /* DirectDraw clippers */ - struct wined3d_clipper *clipper; - /* DirectDraw Overlay handling */ RECT overlay_srcrect; RECT overlay_destrect; @@ -2092,67 +2085,76 @@ static inline struct wined3d_surface *surface_from_resource(struct wined3d_resou return CONTAINING_RECORD(resource, struct wined3d_surface, resource); } -static inline GLuint surface_get_texture_name(struct wined3d_surface *surface, +static inline GLuint surface_get_texture_name(const struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info, BOOL srgb) { return srgb && !gl_info->supported[EXT_TEXTURE_SRGB_DECODE] ? surface->texture_name_srgb : surface->texture_name; } -void surface_add_dirty_rect(struct wined3d_surface *surface, const WINED3DBOX *dirty_rect) DECLSPEC_HIDDEN; -void surface_bind(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info, BOOL srgb) DECLSPEC_HIDDEN; -HRESULT surface_color_fill(struct wined3d_surface *s, const RECT *rect, const WINED3DCOLORVALUE *color) DECLSPEC_HIDDEN; -GLenum surface_get_gl_buffer(struct wined3d_surface *surface) DECLSPEC_HIDDEN; +void surface_add_dirty_rect(struct wined3d_surface *surface, const struct wined3d_box *dirty_rect) DECLSPEC_HIDDEN; +void surface_bind(struct wined3d_surface *surface, struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN; +HRESULT surface_color_fill(struct wined3d_surface *s, + const RECT *rect, const struct wined3d_color *color) DECLSPEC_HIDDEN; +GLenum surface_get_gl_buffer(const struct wined3d_surface *surface) DECLSPEC_HIDDEN; BOOL surface_init_sysmem(struct wined3d_surface *surface) DECLSPEC_HIDDEN; void surface_internal_preload(struct wined3d_surface *surface, enum WINED3DSRGB srgb) DECLSPEC_HIDDEN; -BOOL surface_is_offscreen(struct wined3d_surface *surface) DECLSPEC_HIDDEN; +BOOL surface_is_offscreen(const struct wined3d_surface *surface) DECLSPEC_HIDDEN; HRESULT surface_load(struct wined3d_surface *surface, BOOL srgb) DECLSPEC_HIDDEN; void surface_load_ds_location(struct wined3d_surface *surface, struct wined3d_context *context, DWORD location) DECLSPEC_HIDDEN; -HRESULT surface_load_location(struct wined3d_surface *surface, DWORD flag, const RECT *rect) DECLSPEC_HIDDEN; +void surface_load_fb_texture(struct wined3d_surface *surface, BOOL srgb) DECLSPEC_HIDDEN; +HRESULT surface_load_location(struct wined3d_surface *surface, DWORD location, const RECT *rect) DECLSPEC_HIDDEN; void surface_modify_ds_location(struct wined3d_surface *surface, DWORD location, UINT w, UINT h) DECLSPEC_HIDDEN; -void surface_modify_location(struct wined3d_surface *surface, DWORD flag, BOOL persistent) DECLSPEC_HIDDEN; +void surface_modify_location(struct wined3d_surface *surface, DWORD location, BOOL persistent) DECLSPEC_HIDDEN; +void surface_prepare_rb(struct wined3d_surface *surface, + const struct wined3d_gl_info *gl_info, BOOL multisample) DECLSPEC_HIDDEN; void surface_prepare_texture(struct wined3d_surface *surface, - const struct wined3d_gl_info *gl_info, BOOL srgb) DECLSPEC_HIDDEN; -void surface_set_compatible_renderbuffer(struct wined3d_surface *surface, struct wined3d_surface *rt) DECLSPEC_HIDDEN; + struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN; +void surface_set_compatible_renderbuffer(struct wined3d_surface *surface, + const struct wined3d_surface *rt) DECLSPEC_HIDDEN; void surface_set_container(struct wined3d_surface *surface, enum wined3d_container_type type, void *container) DECLSPEC_HIDDEN; void surface_set_texture_name(struct wined3d_surface *surface, GLuint name, BOOL srgb_name) DECLSPEC_HIDDEN; void surface_set_texture_target(struct wined3d_surface *surface, GLenum target) DECLSPEC_HIDDEN; -void surface_translate_drawable_coords(struct wined3d_surface *surface, HWND window, RECT *rect) DECLSPEC_HIDDEN; +void surface_translate_drawable_coords(const struct wined3d_surface *surface, HWND window, RECT *rect) DECLSPEC_HIDDEN; +void surface_update_draw_binding(struct wined3d_surface *surface) DECLSPEC_HIDDEN; +HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const POINT *dst_point, + struct wined3d_surface *src_surface, const RECT *src_rect) DECLSPEC_HIDDEN; -void get_drawable_size_swapchain(struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN; -void get_drawable_size_backbuffer(struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN; -void get_drawable_size_fbo(struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN; +void get_drawable_size_swapchain(const struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN; +void get_drawable_size_backbuffer(const struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN; +void get_drawable_size_fbo(const struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN; -void draw_textured_quad(struct wined3d_surface *src_surface, const RECT *src_rect, - const RECT *dst_rect, WINED3DTEXTUREFILTERTYPE Filter) DECLSPEC_HIDDEN; +void draw_textured_quad(const struct wined3d_surface *src_surface, struct wined3d_context *context, + const RECT *src_rect, const RECT *dst_rect, enum wined3d_texture_filter_type filter) DECLSPEC_HIDDEN; void flip_surface(struct wined3d_surface *front, struct wined3d_surface *back) DECLSPEC_HIDDEN; /* Surface flags: */ -#define SFLAG_CONVERTED 0x00000002 /* Converted for color keying or Palettized */ -#define SFLAG_DIBSECTION 0x00000004 /* Has a DIB section attached for GetDC */ -#define SFLAG_LOCKABLE 0x00000008 /* Surface can be locked */ -#define SFLAG_DISCARD 0x00000010 /* ??? */ -#define SFLAG_LOCKED 0x00000020 /* Surface is locked atm */ -#define SFLAG_INTEXTURE 0x00000040 /* The GL texture contains the newest surface content */ -#define SFLAG_INSRGBTEX 0x00000080 /* The GL srgb texture contains the newest surface content */ -#define SFLAG_INDRAWABLE 0x00000100 /* The gl drawable contains the most up to date data */ -#define SFLAG_INSYSMEM 0x00000200 /* The system memory copy is most up to date */ -#define SFLAG_NONPOW2 0x00000400 /* Surface sizes are not a power of 2 */ -#define SFLAG_DYNLOCK 0x00000800 /* Surface is often locked by the app */ -#define SFLAG_DCINUSE 0x00001000 /* Set between GetDC and ReleaseDC calls */ -#define SFLAG_LOST 0x00002000 /* Surface lost flag for DDraw */ -#define SFLAG_USERPTR 0x00004000 /* The application allocated the memory for this surface */ -#define SFLAG_GLCKEY 0x00008000 /* The gl texture was created with a color key */ -#define SFLAG_CLIENT 0x00010000 /* GL_APPLE_client_storage is used on that texture */ -#define SFLAG_ALLOCATED 0x00020000 /* A gl texture is allocated for this surface */ -#define SFLAG_SRGBALLOCATED 0x00040000 /* A srgb gl texture is allocated for this surface */ -#define SFLAG_PBO 0x00080000 /* Has a PBO attached for speeding up data transfers for dynamically locked surfaces */ -#define SFLAG_NORMCOORD 0x00100000 /* Set if the GL texture coords are normalized(non-texture rectangle) */ -#define SFLAG_DS_ONSCREEN 0x00200000 /* Is a depth stencil, last modified onscreen */ -#define SFLAG_DS_OFFSCREEN 0x00400000 /* Is a depth stencil, last modified offscreen */ -#define SFLAG_INOVERLAYDRAW 0x00800000 /* Overlay drawing is in progress. Recursion prevention */ +#define SFLAG_CONVERTED 0x00000001 /* Converted for color keying or palettized. */ +#define SFLAG_DISCARD 0x00000002 /* ??? */ +#define SFLAG_NONPOW2 0x00000004 /* Surface sizes are not a power of 2 */ +#define SFLAG_NORMCOORD 0x00000008 /* Set if GL texture coordinates are normalized (non-texture rectangle). */ +#define SFLAG_LOCKABLE 0x00000010 /* Surface can be locked. */ +#define SFLAG_DYNLOCK 0x00000020 /* Surface is often locked by the application. */ +#define SFLAG_LOCKED 0x00000040 /* Surface is currently locked. */ +#define SFLAG_DCINUSE 0x00000080 /* Set between GetDC and ReleaseDC calls. */ +#define SFLAG_LOST 0x00000100 /* Surface lost flag for ddraw. */ +#define SFLAG_GLCKEY 0x00000200 /* The GL texture was created with a color key. */ +#define SFLAG_CLIENT 0x00000400 /* GL_APPLE_client_storage is used with this surface. */ +#define SFLAG_INOVERLAYDRAW 0x00000800 /* Overlay drawing is in progress. Recursion prevention. */ +#define SFLAG_DIBSECTION 0x00001000 /* Has a DIB section attached for GetDC. */ +#define SFLAG_USERPTR 0x00002000 /* The application allocated the memory for this surface. */ +#define SFLAG_ALLOCATED 0x00004000 /* A GL texture is allocated for this surface. */ +#define SFLAG_SRGBALLOCATED 0x00008000 /* A sRGB GL texture is allocated for this surface. */ +#define SFLAG_PBO 0x00010000 /* The surface has a PBO. */ +#define SFLAG_INSYSMEM 0x00020000 /* The system memory copy is current. */ +#define SFLAG_INTEXTURE 0x00040000 /* The GL texture is current. */ +#define SFLAG_INSRGBTEX 0x00080000 /* The GL sRGB texture is current. */ +#define SFLAG_INDRAWABLE 0x00100000 /* The GL drawable is current. */ +#define SFLAG_INRB_MULTISAMPLE 0x00200000 /* The multisample renderbuffer is current. */ +#define SFLAG_INRB_RESOLVED 0x00400000 /* The resolved renderbuffer is current. */ +#define SFLAG_PIN_SYSMEM 0x02000000 /* Keep the surface in sysmem, at the same address. */ /* In some conditions the surface memory must not be freed: * SFLAG_CONVERTED: Converting the data back would take too long @@ -2162,22 +2164,21 @@ void flip_surface(struct wined3d_surface *front, struct wined3d_surface *back) D * SFLAG_PBO: PBOs don't use 'normal' memory. It is either allocated by the driver or must be NULL. * SFLAG_CLIENT: OpenGL uses our memory as backup */ -#define SFLAG_DONOTFREE (SFLAG_CONVERTED | \ - SFLAG_DIBSECTION | \ - SFLAG_LOCKED | \ - SFLAG_DYNLOCK | \ - SFLAG_USERPTR | \ - SFLAG_PBO | \ - SFLAG_CLIENT) +#define SFLAG_DONOTFREE (SFLAG_CONVERTED | \ + SFLAG_DYNLOCK | \ + SFLAG_LOCKED | \ + SFLAG_CLIENT | \ + SFLAG_DIBSECTION | \ + SFLAG_USERPTR | \ + SFLAG_PBO | \ + SFLAG_PIN_SYSMEM) -#define SFLAG_LOCATIONS (SFLAG_INSYSMEM | \ - SFLAG_INTEXTURE | \ - SFLAG_INDRAWABLE | \ - SFLAG_INSRGBTEX) - -#define SFLAG_DS_LOCATIONS (SFLAG_DS_ONSCREEN | \ - SFLAG_DS_OFFSCREEN) -#define SFLAG_DS_DISCARDED SFLAG_DS_LOCATIONS +#define SFLAG_LOCATIONS (SFLAG_INSYSMEM | \ + SFLAG_INTEXTURE | \ + SFLAG_INSRGBTEX | \ + SFLAG_INDRAWABLE | \ + SFLAG_INRB_MULTISAMPLE | \ + SFLAG_INRB_RESOLVED) typedef enum { NO_CONVERSION, @@ -2189,11 +2190,9 @@ typedef enum { CONVERT_RGB32_888 } CONVERT_TYPES; -HRESULT d3dfmt_get_conv(struct wined3d_surface *surface, BOOL need_alpha_ck, BOOL use_texturing, +HRESULT d3dfmt_get_conv(const struct wined3d_surface *surface, BOOL need_alpha_ck, BOOL use_texturing, struct wined3d_format *format, CONVERT_TYPES *convert) DECLSPEC_HIDDEN; -void d3dfmt_p8_init_palette(struct wined3d_surface *surface, BYTE table[256][4], BOOL colorkey) DECLSPEC_HIDDEN; - -BOOL palette9_changed(struct wined3d_surface *surface) DECLSPEC_HIDDEN; +void d3dfmt_p8_init_palette(const struct wined3d_surface *surface, BYTE table[256][4], BOOL colorkey) DECLSPEC_HIDDEN; struct wined3d_vertex_declaration_element { @@ -2223,10 +2222,8 @@ struct wined3d_vertex_declaration BOOL half_float_conv_needed; }; -/* Internal state Block for Begin/End/Capture/Create/Apply info */ -/* Note: Very long winded but gl Lists are not flexible enough */ -/* to resolve everything we need, so doing it manually for now */ -typedef struct SAVEDSTATES { +struct wined3d_saved_states +{ DWORD transform[(HIGHEST_TRANSFORMSTATE >> 5) + 1]; WORD streamSource; /* MAX_STREAMS, 16 */ WORD streamFreq; /* MAX_STREAMS, 16 */ @@ -2250,7 +2247,7 @@ typedef struct SAVEDSTATES { DWORD vertexShader : 1; DWORD scissorRect : 1; DWORD padding : 4; -} SAVEDSTATES; +}; struct StageState { DWORD stage; @@ -2268,6 +2265,8 @@ struct wined3d_stream_state struct wined3d_state { + const struct wined3d_fb_state *fb; + struct wined3d_vertex_declaration *vertex_declaration; struct wined3d_stream_state streams[MAX_STREAMS + 1 /* tesselated pseudo-stream */]; BOOL user_stream; @@ -2292,11 +2291,10 @@ struct wined3d_state DWORD texture_states[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1]; DWORD lowest_disabled_stage; - WINED3DMATRIX transforms[HIGHEST_TRANSFORMSTATE + 1]; + struct wined3d_matrix transforms[HIGHEST_TRANSFORMSTATE + 1]; double clip_planes[MAX_CLIPPLANES][4]; - WINED3DCLIPSTATUS clip_status; - WINED3DMATERIAL material; - WINED3DVIEWPORT viewport; + struct wined3d_material material; + struct wined3d_viewport viewport; RECT scissor_rect; /* Light hashmap . Collisions are handled using standard wine double linked lists */ @@ -2312,10 +2310,10 @@ struct wined3d_stateblock { LONG ref; /* Note: Ref counting not required */ struct wined3d_device *device; - WINED3DSTATEBLOCKTYPE blockType; + enum wined3d_stateblock_type blockType; /* Array indicating whether things have been set or changed */ - SAVEDSTATES changed; + struct wined3d_saved_states changed; struct wined3d_state state; /* Contained state management */ @@ -2343,14 +2341,7 @@ struct wined3d_stateblock void stateblock_init_contained_states(struct wined3d_stateblock *stateblock) DECLSPEC_HIDDEN; void stateblock_init_default_state(struct wined3d_stateblock *stateblock) DECLSPEC_HIDDEN; - -static inline void stateblock_apply_state(DWORD state, struct wined3d_stateblock *stateblock, - struct wined3d_context *context) -{ - const struct StateEntry *statetable = stateblock->device->StateTable; - DWORD rep = statetable[state].representative; - statetable[rep].apply(rep, stateblock, context); -} +void stateblock_unbind_resources(struct wined3d_stateblock *stateblock) DECLSPEC_HIDDEN; /* Direct3D terminology with little modifications. We do not have an issued state * because only the driver knows about it, but we have a created state because d3d @@ -2374,7 +2365,7 @@ struct wined3d_query const struct wined3d_query_ops *query_ops; struct wined3d_device *device; enum query_state state; - WINED3DQUERYTYPE type; + enum wined3d_query_type type; DWORD data_size; void *extendedData; }; @@ -2434,8 +2425,8 @@ static inline struct wined3d_buffer *buffer_from_resource(struct wined3d_resourc return CONTAINING_RECORD(resource, struct wined3d_buffer, resource); } -const BYTE *buffer_get_memory(struct wined3d_buffer *buffer, const struct wined3d_gl_info *gl_info, - GLuint *buffer_object) DECLSPEC_HIDDEN; +void buffer_get_memory(struct wined3d_buffer *buffer, const struct wined3d_gl_info *gl_info, + struct wined3d_bo_address *data) DECLSPEC_HIDDEN; BYTE *buffer_get_sysmem(struct wined3d_buffer *This, const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN; struct wined3d_rendertarget_view @@ -2462,10 +2453,10 @@ struct wined3d_swapchain struct wined3d_surface **back_buffers; struct wined3d_surface *front_buffer; - WINED3DPRESENT_PARAMETERS presentParms; + struct wined3d_swapchain_desc desc; DWORD orig_width, orig_height; enum wined3d_format_id orig_fmt; - WINED3DGAMMARAMP orig_gamma; + struct wined3d_gamma_ramp orig_gamma; BOOL render_to_fbo; const struct wined3d_format *ds_format; @@ -2481,9 +2472,13 @@ struct wined3d_swapchain HWND backup_wnd; }; -void x11_copy_to_screen(struct wined3d_swapchain *swapchain, const RECT *rect) DECLSPEC_HIDDEN; +void x11_copy_to_screen(const struct wined3d_swapchain *swapchain, const RECT *rect) DECLSPEC_HIDDEN; struct wined3d_context *swapchain_get_context(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN; +void swapchain_destroy_contexts(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN; +HDC swapchain_get_backup_dc(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN; +void swapchain_update_draw_bindings(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN; +void swapchain_update_render_to_fbo(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN; #define DEFAULT_REFRESH_RATE 0 @@ -2493,54 +2488,51 @@ struct wined3d_context *swapchain_get_context(struct wined3d_swapchain *swapchai /* Trace routines */ const char *debug_d3dformat(enum wined3d_format_id format_id) DECLSPEC_HIDDEN; -const char *debug_d3ddevicetype(WINED3DDEVTYPE devtype) DECLSPEC_HIDDEN; -const char *debug_d3dresourcetype(WINED3DRESOURCETYPE res) DECLSPEC_HIDDEN; +const char *debug_d3ddevicetype(enum wined3d_device_type device_type) DECLSPEC_HIDDEN; +const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type) DECLSPEC_HIDDEN; const char *debug_d3dusage(DWORD usage) DECLSPEC_HIDDEN; const char *debug_d3dusagequery(DWORD usagequery) DECLSPEC_HIDDEN; const char *debug_d3ddeclmethod(WINED3DDECLMETHOD method) DECLSPEC_HIDDEN; const char *debug_d3ddeclusage(BYTE usage) DECLSPEC_HIDDEN; -const char *debug_d3dprimitivetype(WINED3DPRIMITIVETYPE PrimitiveType) DECLSPEC_HIDDEN; -const char *debug_d3drenderstate(DWORD state) DECLSPEC_HIDDEN; -const char *debug_d3dsamplerstate(DWORD state) DECLSPEC_HIDDEN; +const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type) DECLSPEC_HIDDEN; +const char *debug_d3drenderstate(enum wined3d_render_state state) DECLSPEC_HIDDEN; +const char *debug_d3dsamplerstate(enum wined3d_sampler_state state) DECLSPEC_HIDDEN; const char *debug_d3dstate(DWORD state) DECLSPEC_HIDDEN; -const char *debug_d3dtexturefiltertype(WINED3DTEXTUREFILTERTYPE filter_type) DECLSPEC_HIDDEN; -const char *debug_d3dtexturestate(DWORD state) DECLSPEC_HIDDEN; -const char *debug_d3dtstype(WINED3DTRANSFORMSTATETYPE tstype) DECLSPEC_HIDDEN; -const char *debug_d3dpool(WINED3DPOOL pool) DECLSPEC_HIDDEN; +const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type) DECLSPEC_HIDDEN; +const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state) DECLSPEC_HIDDEN; +const char *debug_d3dtstype(enum wined3d_transform_state tstype) DECLSPEC_HIDDEN; +const char *debug_d3dpool(enum wined3d_pool pool) DECLSPEC_HIDDEN; const char *debug_fbostatus(GLenum status) DECLSPEC_HIDDEN; const char *debug_glerror(GLenum error) DECLSPEC_HIDDEN; -const char *debug_d3dbasis(WINED3DBASISTYPE basis) DECLSPEC_HIDDEN; -const char *debug_d3ddegree(WINED3DDEGREETYPE order) DECLSPEC_HIDDEN; -const char *debug_d3dtop(WINED3DTEXTUREOP d3dtop) DECLSPEC_HIDDEN; +const char *debug_d3dbasis(enum wined3d_basis_type basis) DECLSPEC_HIDDEN; +const char *debug_d3ddegree(enum wined3d_degree_type order) DECLSPEC_HIDDEN; +const char *debug_d3dtop(enum wined3d_texture_op d3dtop) DECLSPEC_HIDDEN; void dump_color_fixup_desc(struct color_fixup_desc fixup) DECLSPEC_HIDDEN; const char *debug_surflocation(DWORD flag) DECLSPEC_HIDDEN; -/* Routines for GL <-> D3D values */ -GLenum StencilOp(DWORD op) DECLSPEC_HIDDEN; -GLenum CompareFunc(DWORD func) DECLSPEC_HIDDEN; BOOL is_invalid_op(const struct wined3d_state *state, int stage, - WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3) DECLSPEC_HIDDEN; + enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3) DECLSPEC_HIDDEN; void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state, - BOOL is_alpha, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, + BOOL is_alpha, int stage, enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx, DWORD dst) DECLSPEC_HIDDEN; void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords, BOOL transformed, enum wined3d_format_id coordtype, BOOL ffp_can_disable_proj) DECLSPEC_HIDDEN; void texture_activate_dimensions(const struct wined3d_texture *texture, const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN; -void sampler_texdim(DWORD state, struct wined3d_stateblock *stateblock, - struct wined3d_context *context) DECLSPEC_HIDDEN; -void tex_alphaop(DWORD state, struct wined3d_stateblock *stateblock, - struct wined3d_context *context) DECLSPEC_HIDDEN; -void apply_pixelshader(DWORD state, struct wined3d_stateblock *stateblock, - struct wined3d_context *context) DECLSPEC_HIDDEN; -void state_fogcolor(DWORD state, struct wined3d_stateblock *stateblock, - struct wined3d_context *context) DECLSPEC_HIDDEN; -void state_fogdensity(DWORD state, struct wined3d_stateblock *stateblock, - struct wined3d_context *context) DECLSPEC_HIDDEN; -void state_fogstartend(DWORD state, struct wined3d_stateblock *stateblock, - struct wined3d_context *context) DECLSPEC_HIDDEN; -void state_fog_fragpart(DWORD state, struct wined3d_stateblock *stateblock, - struct wined3d_context *context) DECLSPEC_HIDDEN; +void sampler_texdim(struct wined3d_context *context, + const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN; +void tex_alphaop(struct wined3d_context *context, + const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN; +void apply_pixelshader(struct wined3d_context *context, + const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN; +void state_fogcolor(struct wined3d_context *context, + const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN; +void state_fogdensity(struct wined3d_context *context, + const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN; +void state_fogstartend(struct wined3d_context *context, + const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN; +void state_fog_fragpart(struct wined3d_context *context, + const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN; BOOL getColorBits(const struct wined3d_format *format, BYTE *redSize, BYTE *greenSize, BYTE *blueSize, BYTE *alphaSize, BYTE *totalSize) DECLSPEC_HIDDEN; @@ -2548,17 +2540,19 @@ BOOL getDepthStencilBits(const struct wined3d_format *format, BYTE *depthSize, BYTE *stencilSize) DECLSPEC_HIDDEN; /* Math utils */ -void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2) DECLSPEC_HIDDEN; +void multiply_matrix(struct wined3d_matrix *dest, const struct wined3d_matrix *src1, + const struct wined3d_matrix *src2) DECLSPEC_HIDDEN; UINT wined3d_log2i(UINT32 x) DECLSPEC_HIDDEN; unsigned int count_bits(unsigned int mask) DECLSPEC_HIDDEN; void select_shader_mode(const struct wined3d_gl_info *gl_info, int *ps_selected, int *vs_selected) DECLSPEC_HIDDEN; -typedef struct local_constant { +struct wined3d_shader_lconst +{ struct list entry; unsigned int idx; DWORD value[4]; -} local_constant; +}; struct wined3d_shader_limits { @@ -2586,7 +2580,7 @@ int shader_addline(struct wined3d_shader_buffer *buffer, const char *fmt, ...) P int shader_vaddline(struct wined3d_shader_buffer *buffer, const char *fmt, va_list args) DECLSPEC_HIDDEN; /* Vertex shader utility functions */ -extern BOOL vshader_get_input(struct wined3d_shader *shader, +BOOL vshader_get_input(const struct wined3d_shader *shader, BYTE usage_req, BYTE usage_idx_req, unsigned int *regnum) DECLSPEC_HIDDEN; struct wined3d_vertex_shader @@ -2602,7 +2596,6 @@ struct wined3d_pixel_shader unsigned int declared_in_count; /* Some information about the shader behavior */ - char vpos_uniform; BOOL color0_mov; DWORD color0_reg; }; @@ -2661,8 +2654,8 @@ void shader_dump_dst_param(const struct wined3d_shader_dst_param *param, const struct wined3d_shader_version *shader_version) DECLSPEC_HIDDEN; unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps *reg_maps, unsigned int max) DECLSPEC_HIDDEN; -void shader_generate_main(struct wined3d_shader *shader, struct wined3d_shader_buffer *buffer, - const struct wined3d_shader_reg_maps *reg_maps, const DWORD *pFunction, void *backend_ctx) DECLSPEC_HIDDEN; +void shader_generate_main(const struct wined3d_shader *shader, struct wined3d_shader_buffer *buffer, + const struct wined3d_shader_reg_maps *reg_maps, const DWORD *byte_code, void *backend_ctx) DECLSPEC_HIDDEN; BOOL shader_match_semantic(const char *semantic_name, WINED3DDECLUSAGE usage) DECLSPEC_HIDDEN; static inline BOOL shader_is_pshader_version(enum wined3d_shader_type type) @@ -2715,8 +2708,8 @@ static inline void shader_get_position_fixup(const struct wined3d_context *conte { position_fixup[0] = 1.0f; position_fixup[1] = 1.0f; - position_fixup[2] = (63.0f / 64.0f) / state->viewport.Width; - position_fixup[3] = -(63.0f / 64.0f) / state->viewport.Height; + position_fixup[2] = (63.0f / 64.0f) / state->viewport.width; + position_fixup[3] = -(63.0f / 64.0f) / state->viewport.height; if (context->render_offscreen) { @@ -2727,12 +2720,12 @@ static inline void shader_get_position_fixup(const struct wined3d_context *conte static inline BOOL shader_constant_is_local(const struct wined3d_shader *shader, DWORD reg) { - struct local_constant *lconst; + struct wined3d_shader_lconst *lconst; if (shader->load_local_constsF) return FALSE; - LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, local_constant, entry) + LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry) { if (lconst->idx == reg) return TRUE; @@ -2805,6 +2798,7 @@ extern enum wined3d_format_id pixelformat_for_depth(DWORD depth) DECLSPEC_HIDDEN #define WINED3DFMT_FLAG_SHADOW 0x00004000 #define WINED3DFMT_FLAG_COMPRESSED 0x00008000 #define WINED3DFMT_FLAG_BROKEN_PITCH 0x00010000 +#define WINED3DFMT_FLAG_BLOCKS 0x00020000 struct wined3d_format { @@ -2845,8 +2839,8 @@ const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl enum wined3d_format_id format_id) DECLSPEC_HIDDEN; UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT alignment, UINT width, UINT height) DECLSPEC_HIDDEN; -DWORD wined3d_format_convert_from_float(const struct wined3d_format *format, - const WINED3DCOLORVALUE *color) DECLSPEC_HIDDEN; +DWORD wined3d_format_convert_from_float(const struct wined3d_surface *surface, + const struct wined3d_color *color) DECLSPEC_HIDDEN; static inline BOOL use_vs(const struct wined3d_state *state) { @@ -2862,6 +2856,14 @@ static inline BOOL use_ps(const struct wined3d_state *state) return !!state->pixel_shader; } +static inline void context_apply_state(struct wined3d_context *context, + const struct wined3d_state *state, DWORD state_id) +{ + const struct StateEntry *state_table = context->state_table; + DWORD rep = state_table[state_id].representative; + state_table[rep].apply(context, state, rep); +} + /* The WNDCLASS-Name for the fake window which we use to retrieve the GL capabilities */ #define WINED3D_OPENGL_WINDOW_CLASS_NAME "WineD3D_OpenGL" diff --git a/reactos/include/reactos/wine/wined3d.h b/reactos/include/reactos/wine/wined3d.h index ed269f006e9..f1e389d4f65 100644 --- a/reactos/include/reactos/wine/wined3d.h +++ b/reactos/include/reactos/wine/wined3d.h @@ -65,51 +65,45 @@ #define WINEDDERR_NOCLIPLIST MAKE_WINED3DHRESULT(205) #define WINEDDERR_OVERLAYNOTVISIBLE MAKE_WINED3DHRESULT(577) -typedef DWORD WINED3DCOLOR; - -typedef enum _WINED3DLIGHTTYPE +enum wined3d_light_type { - WINED3DLIGHT_POINT = 1, - WINED3DLIGHT_SPOT = 2, - WINED3DLIGHT_DIRECTIONAL = 3, - WINED3DLIGHT_PARALLELPOINT = 4, /* D3D7 */ - WINED3DLIGHT_GLSPOT = 5, /* D3D7 */ - WINED3DLIGHT_FORCE_DWORD = 0x7fffffff -} WINED3DLIGHTTYPE; + WINED3D_LIGHT_POINT = 1, + WINED3D_LIGHT_SPOT = 2, + WINED3D_LIGHT_DIRECTIONAL = 3, + WINED3D_LIGHT_PARALLELPOINT = 4, /* D3D7 */ + WINED3D_LIGHT_GLSPOT = 5, /* D3D7 */ +}; -typedef enum _WINED3DPRIMITIVETYPE +enum wined3d_primitive_type { - WINED3DPT_UNDEFINED = 0, - WINED3DPT_POINTLIST = 1, - WINED3DPT_LINELIST = 2, - WINED3DPT_LINESTRIP = 3, - WINED3DPT_TRIANGLELIST = 4, - WINED3DPT_TRIANGLESTRIP = 5, - WINED3DPT_TRIANGLEFAN = 6, - WINED3DPT_LINELIST_ADJ = 10, - WINED3DPT_LINESTRIP_ADJ = 11, - WINED3DPT_TRIANGLELIST_ADJ = 12, - WINED3DPT_TRIANGLESTRIP_ADJ = 13, - WINED3DPT_FORCE_DWORD = 0x7fffffff -} WINED3DPRIMITIVETYPE; + WINED3D_PT_UNDEFINED = 0, + WINED3D_PT_POINTLIST = 1, + WINED3D_PT_LINELIST = 2, + WINED3D_PT_LINESTRIP = 3, + WINED3D_PT_TRIANGLELIST = 4, + WINED3D_PT_TRIANGLESTRIP = 5, + WINED3D_PT_TRIANGLEFAN = 6, + WINED3D_PT_LINELIST_ADJ = 10, + WINED3D_PT_LINESTRIP_ADJ = 11, + WINED3D_PT_TRIANGLELIST_ADJ = 12, + WINED3D_PT_TRIANGLESTRIP_ADJ = 13, +}; -typedef enum _WINED3DDEVTYPE +enum wined3d_device_type { - WINED3DDEVTYPE_HAL = 1, - WINED3DDEVTYPE_REF = 2, - WINED3DDEVTYPE_SW = 3, - WINED3DDEVTYPE_NULLREF = 4, - WINED3DDEVTYPE_FORCE_DWORD = 0xffffffff -} WINED3DDEVTYPE; + WINED3D_DEVICE_TYPE_HAL = 1, + WINED3D_DEVICE_TYPE_REF = 2, + WINED3D_DEVICE_TYPE_SW = 3, + WINED3D_DEVICE_TYPE_NULLREF = 4, +}; -typedef enum _WINED3DDEGREETYPE +enum wined3d_degree_type { - WINED3DDEGREE_LINEAR = 1, - WINED3DDEGREE_QUADRATIC = 2, - WINED3DDEGREE_CUBIC = 3, - WINED3DDEGREE_QUINTIC = 5, - WINED3DDEGREE_FORCE_DWORD = 0x7fffffff -} WINED3DDEGREETYPE; + WINED3D_DEGREE_LINEAR = 1, + WINED3D_DEGREE_QUADRATIC = 2, + WINED3D_DEGREE_CUBIC = 3, + WINED3D_DEGREE_QUINTIC = 5, +}; #define WINEMAKEFOURCC(ch0, ch1, ch2, ch3) \ ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \ @@ -252,503 +246,478 @@ enum wined3d_format_id WINED3DFMT_NVHS = WINEMAKEFOURCC('N','V','H','S'), WINED3DFMT_INTZ = WINEMAKEFOURCC('I','N','T','Z'), WINED3DFMT_NULL = WINEMAKEFOURCC('N','U','L','L'), + WINED3DFMT_R16 = WINEMAKEFOURCC(' ','R','1','6'), + WINED3DFMT_AL16 = WINEMAKEFOURCC('A','L','1','6'), WINED3DFMT_FORCE_DWORD = 0xffffffff }; -typedef enum _WINED3DRENDERSTATETYPE +enum wined3d_render_state { - WINED3DRS_ANTIALIAS = 2, /* d3d7 */ - WINED3DRS_TEXTUREPERSPECTIVE = 4, /* d3d7 */ - WINED3DRS_WRAPU = 5, /* d3d7 */ - WINED3DRS_WRAPV = 6, /* d3d7 */ - WINED3DRS_ZENABLE = 7, - WINED3DRS_FILLMODE = 8, - WINED3DRS_SHADEMODE = 9, - WINED3DRS_LINEPATTERN = 10, /* d3d7, d3d8 */ - WINED3DRS_MONOENABLE = 11, /* d3d7 */ - WINED3DRS_ROP2 = 12, /* d3d7 */ - WINED3DRS_PLANEMASK = 13, /* d3d7 */ - WINED3DRS_ZWRITEENABLE = 14, - WINED3DRS_ALPHATESTENABLE = 15, - WINED3DRS_LASTPIXEL = 16, - WINED3DRS_SRCBLEND = 19, - WINED3DRS_DESTBLEND = 20, - WINED3DRS_CULLMODE = 22, - WINED3DRS_ZFUNC = 23, - WINED3DRS_ALPHAREF = 24, - WINED3DRS_ALPHAFUNC = 25, - WINED3DRS_DITHERENABLE = 26, - WINED3DRS_ALPHABLENDENABLE = 27, - WINED3DRS_FOGENABLE = 28, - WINED3DRS_SPECULARENABLE = 29, - WINED3DRS_ZVISIBLE = 30, /* d3d7, d3d8 */ - WINED3DRS_SUBPIXEL = 31, /* d3d7 */ - WINED3DRS_SUBPIXELX = 32, /* d3d7 */ - WINED3DRS_STIPPLEDALPHA = 33, /* d3d7 */ - WINED3DRS_FOGCOLOR = 34, - WINED3DRS_FOGTABLEMODE = 35, - WINED3DRS_FOGSTART = 36, - WINED3DRS_FOGEND = 37, - WINED3DRS_FOGDENSITY = 38, - WINED3DRS_STIPPLEENABLE = 39, /* d3d7 */ - WINED3DRS_EDGEANTIALIAS = 40, /* d3d7, d3d8 */ - WINED3DRS_COLORKEYENABLE = 41, /* d3d7 */ - WINED3DRS_MIPMAPLODBIAS = 46, /* d3d7 */ - WINED3DRS_RANGEFOGENABLE = 48, - WINED3DRS_ANISOTROPY = 49, /* d3d7 */ - WINED3DRS_FLUSHBATCH = 50, /* d3d7 */ - WINED3DRS_TRANSLUCENTSORTINDEPENDENT = 51, /* d3d7 */ - WINED3DRS_STENCILENABLE = 52, - WINED3DRS_STENCILFAIL = 53, - WINED3DRS_STENCILZFAIL = 54, - WINED3DRS_STENCILPASS = 55, - WINED3DRS_STENCILFUNC = 56, - WINED3DRS_STENCILREF = 57, - WINED3DRS_STENCILMASK = 58, - WINED3DRS_STENCILWRITEMASK = 59, - WINED3DRS_TEXTUREFACTOR = 60, - WINED3DRS_WRAP0 = 128, - WINED3DRS_WRAP1 = 129, - WINED3DRS_WRAP2 = 130, - WINED3DRS_WRAP3 = 131, - WINED3DRS_WRAP4 = 132, - WINED3DRS_WRAP5 = 133, - WINED3DRS_WRAP6 = 134, - WINED3DRS_WRAP7 = 135, - WINED3DRS_CLIPPING = 136, - WINED3DRS_LIGHTING = 137, - WINED3DRS_EXTENTS = 138, /* d3d7 */ - WINED3DRS_AMBIENT = 139, - WINED3DRS_FOGVERTEXMODE = 140, - WINED3DRS_COLORVERTEX = 141, - WINED3DRS_LOCALVIEWER = 142, - WINED3DRS_NORMALIZENORMALS = 143, - WINED3DRS_COLORKEYBLENDENABLE = 144, /* d3d7 */ - WINED3DRS_DIFFUSEMATERIALSOURCE = 145, - WINED3DRS_SPECULARMATERIALSOURCE = 146, - WINED3DRS_AMBIENTMATERIALSOURCE = 147, - WINED3DRS_EMISSIVEMATERIALSOURCE = 148, - WINED3DRS_VERTEXBLEND = 151, - WINED3DRS_CLIPPLANEENABLE = 152, - WINED3DRS_SOFTWAREVERTEXPROCESSING = 153, /* d3d8 */ - WINED3DRS_POINTSIZE = 154, - WINED3DRS_POINTSIZE_MIN = 155, - WINED3DRS_POINTSPRITEENABLE = 156, - WINED3DRS_POINTSCALEENABLE = 157, - WINED3DRS_POINTSCALE_A = 158, - WINED3DRS_POINTSCALE_B = 159, - WINED3DRS_POINTSCALE_C = 160, - WINED3DRS_MULTISAMPLEANTIALIAS = 161, - WINED3DRS_MULTISAMPLEMASK = 162, - WINED3DRS_PATCHEDGESTYLE = 163, - WINED3DRS_PATCHSEGMENTS = 164, /* d3d8 */ - WINED3DRS_DEBUGMONITORTOKEN = 165, - WINED3DRS_POINTSIZE_MAX = 166, - WINED3DRS_INDEXEDVERTEXBLENDENABLE = 167, - WINED3DRS_COLORWRITEENABLE = 168, - WINED3DRS_TWEENFACTOR = 170, - WINED3DRS_BLENDOP = 171, - WINED3DRS_POSITIONDEGREE = 172, - WINED3DRS_NORMALDEGREE = 173, - WINED3DRS_SCISSORTESTENABLE = 174, - WINED3DRS_SLOPESCALEDEPTHBIAS = 175, - WINED3DRS_ANTIALIASEDLINEENABLE = 176, - WINED3DRS_MINTESSELLATIONLEVEL = 178, - WINED3DRS_MAXTESSELLATIONLEVEL = 179, - WINED3DRS_ADAPTIVETESS_X = 180, - WINED3DRS_ADAPTIVETESS_Y = 181, - WINED3DRS_ADAPTIVETESS_Z = 182, - WINED3DRS_ADAPTIVETESS_W = 183, - WINED3DRS_ENABLEADAPTIVETESSELLATION = 184, - WINED3DRS_TWOSIDEDSTENCILMODE = 185, - WINED3DRS_CCW_STENCILFAIL = 186, - WINED3DRS_CCW_STENCILZFAIL = 187, - WINED3DRS_CCW_STENCILPASS = 188, - WINED3DRS_CCW_STENCILFUNC = 189, - WINED3DRS_COLORWRITEENABLE1 = 190, - WINED3DRS_COLORWRITEENABLE2 = 191, - WINED3DRS_COLORWRITEENABLE3 = 192, - WINED3DRS_BLENDFACTOR = 193, - WINED3DRS_SRGBWRITEENABLE = 194, - WINED3DRS_DEPTHBIAS = 195, - WINED3DRS_WRAP8 = 198, - WINED3DRS_WRAP9 = 199, - WINED3DRS_WRAP10 = 200, - WINED3DRS_WRAP11 = 201, - WINED3DRS_WRAP12 = 202, - WINED3DRS_WRAP13 = 203, - WINED3DRS_WRAP14 = 204, - WINED3DRS_WRAP15 = 205, - WINED3DRS_SEPARATEALPHABLENDENABLE = 206, - WINED3DRS_SRCBLENDALPHA = 207, - WINED3DRS_DESTBLENDALPHA = 208, - WINED3DRS_BLENDOPALPHA = 209, - WINED3DRS_FORCE_DWORD = 0x7fffffff -} WINED3DRENDERSTATETYPE; -#define WINEHIGHEST_RENDER_STATE WINED3DRS_BLENDOPALPHA + WINED3D_RS_ANTIALIAS = 2, /* d3d7 */ + WINED3D_RS_TEXTUREPERSPECTIVE = 4, /* d3d7 */ + WINED3D_RS_WRAPU = 5, /* d3d7 */ + WINED3D_RS_WRAPV = 6, /* d3d7 */ + WINED3D_RS_ZENABLE = 7, + WINED3D_RS_FILLMODE = 8, + WINED3D_RS_SHADEMODE = 9, + WINED3D_RS_LINEPATTERN = 10, /* d3d7, d3d8 */ + WINED3D_RS_MONOENABLE = 11, /* d3d7 */ + WINED3D_RS_ROP2 = 12, /* d3d7 */ + WINED3D_RS_PLANEMASK = 13, /* d3d7 */ + WINED3D_RS_ZWRITEENABLE = 14, + WINED3D_RS_ALPHATESTENABLE = 15, + WINED3D_RS_LASTPIXEL = 16, + WINED3D_RS_SRCBLEND = 19, + WINED3D_RS_DESTBLEND = 20, + WINED3D_RS_CULLMODE = 22, + WINED3D_RS_ZFUNC = 23, + WINED3D_RS_ALPHAREF = 24, + WINED3D_RS_ALPHAFUNC = 25, + WINED3D_RS_DITHERENABLE = 26, + WINED3D_RS_ALPHABLENDENABLE = 27, + WINED3D_RS_FOGENABLE = 28, + WINED3D_RS_SPECULARENABLE = 29, + WINED3D_RS_ZVISIBLE = 30, /* d3d7, d3d8 */ + WINED3D_RS_SUBPIXEL = 31, /* d3d7 */ + WINED3D_RS_SUBPIXELX = 32, /* d3d7 */ + WINED3D_RS_STIPPLEDALPHA = 33, /* d3d7 */ + WINED3D_RS_FOGCOLOR = 34, + WINED3D_RS_FOGTABLEMODE = 35, + WINED3D_RS_FOGSTART = 36, + WINED3D_RS_FOGEND = 37, + WINED3D_RS_FOGDENSITY = 38, + WINED3D_RS_STIPPLEENABLE = 39, /* d3d7 */ + WINED3D_RS_EDGEANTIALIAS = 40, /* d3d7, d3d8 */ + WINED3D_RS_COLORKEYENABLE = 41, /* d3d7 */ + WINED3D_RS_MIPMAPLODBIAS = 46, /* d3d7 */ + WINED3D_RS_RANGEFOGENABLE = 48, + WINED3D_RS_ANISOTROPY = 49, /* d3d7 */ + WINED3D_RS_FLUSHBATCH = 50, /* d3d7 */ + WINED3D_RS_TRANSLUCENTSORTINDEPENDENT = 51, /* d3d7 */ + WINED3D_RS_STENCILENABLE = 52, + WINED3D_RS_STENCILFAIL = 53, + WINED3D_RS_STENCILZFAIL = 54, + WINED3D_RS_STENCILPASS = 55, + WINED3D_RS_STENCILFUNC = 56, + WINED3D_RS_STENCILREF = 57, + WINED3D_RS_STENCILMASK = 58, + WINED3D_RS_STENCILWRITEMASK = 59, + WINED3D_RS_TEXTUREFACTOR = 60, + WINED3D_RS_WRAP0 = 128, + WINED3D_RS_WRAP1 = 129, + WINED3D_RS_WRAP2 = 130, + WINED3D_RS_WRAP3 = 131, + WINED3D_RS_WRAP4 = 132, + WINED3D_RS_WRAP5 = 133, + WINED3D_RS_WRAP6 = 134, + WINED3D_RS_WRAP7 = 135, + WINED3D_RS_CLIPPING = 136, + WINED3D_RS_LIGHTING = 137, + WINED3D_RS_EXTENTS = 138, /* d3d7 */ + WINED3D_RS_AMBIENT = 139, + WINED3D_RS_FOGVERTEXMODE = 140, + WINED3D_RS_COLORVERTEX = 141, + WINED3D_RS_LOCALVIEWER = 142, + WINED3D_RS_NORMALIZENORMALS = 143, + WINED3D_RS_COLORKEYBLENDENABLE = 144, /* d3d7 */ + WINED3D_RS_DIFFUSEMATERIALSOURCE = 145, + WINED3D_RS_SPECULARMATERIALSOURCE = 146, + WINED3D_RS_AMBIENTMATERIALSOURCE = 147, + WINED3D_RS_EMISSIVEMATERIALSOURCE = 148, + WINED3D_RS_VERTEXBLEND = 151, + WINED3D_RS_CLIPPLANEENABLE = 152, + WINED3D_RS_SOFTWAREVERTEXPROCESSING = 153, /* d3d8 */ + WINED3D_RS_POINTSIZE = 154, + WINED3D_RS_POINTSIZE_MIN = 155, + WINED3D_RS_POINTSPRITEENABLE = 156, + WINED3D_RS_POINTSCALEENABLE = 157, + WINED3D_RS_POINTSCALE_A = 158, + WINED3D_RS_POINTSCALE_B = 159, + WINED3D_RS_POINTSCALE_C = 160, + WINED3D_RS_MULTISAMPLEANTIALIAS = 161, + WINED3D_RS_MULTISAMPLEMASK = 162, + WINED3D_RS_PATCHEDGESTYLE = 163, + WINED3D_RS_PATCHSEGMENTS = 164, /* d3d8 */ + WINED3D_RS_DEBUGMONITORTOKEN = 165, + WINED3D_RS_POINTSIZE_MAX = 166, + WINED3D_RS_INDEXEDVERTEXBLENDENABLE = 167, + WINED3D_RS_COLORWRITEENABLE = 168, + WINED3D_RS_TWEENFACTOR = 170, + WINED3D_RS_BLENDOP = 171, + WINED3D_RS_POSITIONDEGREE = 172, + WINED3D_RS_NORMALDEGREE = 173, + WINED3D_RS_SCISSORTESTENABLE = 174, + WINED3D_RS_SLOPESCALEDEPTHBIAS = 175, + WINED3D_RS_ANTIALIASEDLINEENABLE = 176, + WINED3D_RS_MINTESSELLATIONLEVEL = 178, + WINED3D_RS_MAXTESSELLATIONLEVEL = 179, + WINED3D_RS_ADAPTIVETESS_X = 180, + WINED3D_RS_ADAPTIVETESS_Y = 181, + WINED3D_RS_ADAPTIVETESS_Z = 182, + WINED3D_RS_ADAPTIVETESS_W = 183, + WINED3D_RS_ENABLEADAPTIVETESSELLATION = 184, + WINED3D_RS_TWOSIDEDSTENCILMODE = 185, + WINED3D_RS_CCW_STENCILFAIL = 186, + WINED3D_RS_CCW_STENCILZFAIL = 187, + WINED3D_RS_CCW_STENCILPASS = 188, + WINED3D_RS_CCW_STENCILFUNC = 189, + WINED3D_RS_COLORWRITEENABLE1 = 190, + WINED3D_RS_COLORWRITEENABLE2 = 191, + WINED3D_RS_COLORWRITEENABLE3 = 192, + WINED3D_RS_BLENDFACTOR = 193, + WINED3D_RS_SRGBWRITEENABLE = 194, + WINED3D_RS_DEPTHBIAS = 195, + WINED3D_RS_WRAP8 = 198, + WINED3D_RS_WRAP9 = 199, + WINED3D_RS_WRAP10 = 200, + WINED3D_RS_WRAP11 = 201, + WINED3D_RS_WRAP12 = 202, + WINED3D_RS_WRAP13 = 203, + WINED3D_RS_WRAP14 = 204, + WINED3D_RS_WRAP15 = 205, + WINED3D_RS_SEPARATEALPHABLENDENABLE = 206, + WINED3D_RS_SRCBLENDALPHA = 207, + WINED3D_RS_DESTBLENDALPHA = 208, + WINED3D_RS_BLENDOPALPHA = 209, +}; +#define WINEHIGHEST_RENDER_STATE WINED3D_RS_BLENDOPALPHA -typedef enum _WINED3DBLEND +enum wined3d_blend { - WINED3DBLEND_ZERO = 1, - WINED3DBLEND_ONE = 2, - WINED3DBLEND_SRCCOLOR = 3, - WINED3DBLEND_INVSRCCOLOR = 4, - WINED3DBLEND_SRCALPHA = 5, - WINED3DBLEND_INVSRCALPHA = 6, - WINED3DBLEND_DESTALPHA = 7, - WINED3DBLEND_INVDESTALPHA = 8, - WINED3DBLEND_DESTCOLOR = 9, - WINED3DBLEND_INVDESTCOLOR = 10, - WINED3DBLEND_SRCALPHASAT = 11, - WINED3DBLEND_BOTHSRCALPHA = 12, - WINED3DBLEND_BOTHINVSRCALPHA = 13, - WINED3DBLEND_BLENDFACTOR = 14, - WINED3DBLEND_INVBLENDFACTOR = 15, - WINED3DBLEND_FORCE_DWORD = 0x7fffffff -} WINED3DBLEND; + WINED3D_BLEND_ZERO = 1, + WINED3D_BLEND_ONE = 2, + WINED3D_BLEND_SRCCOLOR = 3, + WINED3D_BLEND_INVSRCCOLOR = 4, + WINED3D_BLEND_SRCALPHA = 5, + WINED3D_BLEND_INVSRCALPHA = 6, + WINED3D_BLEND_DESTALPHA = 7, + WINED3D_BLEND_INVDESTALPHA = 8, + WINED3D_BLEND_DESTCOLOR = 9, + WINED3D_BLEND_INVDESTCOLOR = 10, + WINED3D_BLEND_SRCALPHASAT = 11, + WINED3D_BLEND_BOTHSRCALPHA = 12, + WINED3D_BLEND_BOTHINVSRCALPHA = 13, + WINED3D_BLEND_BLENDFACTOR = 14, + WINED3D_BLEND_INVBLENDFACTOR = 15, +}; -typedef enum _WINED3DBLENDOP +enum wined3d_blend_op { - WINED3DBLENDOP_ADD = 1, - WINED3DBLENDOP_SUBTRACT = 2, - WINED3DBLENDOP_REVSUBTRACT = 3, - WINED3DBLENDOP_MIN = 4, - WINED3DBLENDOP_MAX = 5, - WINED3DBLENDOP_FORCE_DWORD = 0x7fffffff -} WINED3DBLENDOP; + WINED3D_BLEND_OP_ADD = 1, + WINED3D_BLEND_OP_SUBTRACT = 2, + WINED3D_BLEND_OP_REVSUBTRACT = 3, + WINED3D_BLEND_OP_MIN = 4, + WINED3D_BLEND_OP_MAX = 5, +}; -typedef enum _WINED3DVERTEXBLENDFLAGS +enum wined3d_vertex_blend_flags { - WINED3DVBF_DISABLE = 0, - WINED3DVBF_1WEIGHTS = 1, - WINED3DVBF_2WEIGHTS = 2, - WINED3DVBF_3WEIGHTS = 3, - WINED3DVBF_TWEENING = 255, - WINED3DVBF_0WEIGHTS = 256 -} WINED3DVERTEXBLENDFLAGS; + WINED3D_VBF_DISABLE = 0, + WINED3D_VBF_1WEIGHTS = 1, + WINED3D_VBF_2WEIGHTS = 2, + WINED3D_VBF_3WEIGHTS = 3, + WINED3D_VBF_TWEENING = 255, + WINED3D_VBF_0WEIGHTS = 256, +}; -typedef enum _WINED3DCMPFUNC +enum wined3d_cmp_func { - WINED3DCMP_NEVER = 1, - WINED3DCMP_LESS = 2, - WINED3DCMP_EQUAL = 3, - WINED3DCMP_LESSEQUAL = 4, - WINED3DCMP_GREATER = 5, - WINED3DCMP_NOTEQUAL = 6, - WINED3DCMP_GREATEREQUAL = 7, - WINED3DCMP_ALWAYS = 8, - WINED3DCMP_FORCE_DWORD = 0x7fffffff -} WINED3DCMPFUNC; + WINED3D_CMP_NEVER = 1, + WINED3D_CMP_LESS = 2, + WINED3D_CMP_EQUAL = 3, + WINED3D_CMP_LESSEQUAL = 4, + WINED3D_CMP_GREATER = 5, + WINED3D_CMP_NOTEQUAL = 6, + WINED3D_CMP_GREATEREQUAL = 7, + WINED3D_CMP_ALWAYS = 8, +}; -typedef enum _WINED3DZBUFFERTYPE +enum wined3d_depth_buffer_type { - WINED3DZB_FALSE = 0, - WINED3DZB_TRUE = 1, - WINED3DZB_USEW = 2, - WINED3DZB_FORCE_DWORD = 0x7fffffff -} WINED3DZBUFFERTYPE; + WINED3D_ZB_FALSE = 0, + WINED3D_ZB_TRUE = 1, + WINED3D_ZB_USEW = 2, +}; -typedef enum _WINED3DFOGMODE +enum wined3d_fog_mode { - WINED3DFOG_NONE = 0, - WINED3DFOG_EXP = 1, - WINED3DFOG_EXP2 = 2, - WINED3DFOG_LINEAR = 3, - WINED3DFOG_FORCE_DWORD = 0x7fffffff -} WINED3DFOGMODE; + WINED3D_FOG_NONE = 0, + WINED3D_FOG_EXP = 1, + WINED3D_FOG_EXP2 = 2, + WINED3D_FOG_LINEAR = 3, +}; -typedef enum _WINED3DSHADEMODE +enum wined3d_shade_mode { - WINED3DSHADE_FLAT = 1, - WINED3DSHADE_GOURAUD = 2, - WINED3DSHADE_PHONG = 3, - WINED3DSHADE_FORCE_DWORD = 0x7fffffff -} WINED3DSHADEMODE; + WINED3D_SHADE_FLAT = 1, + WINED3D_SHADE_GOURAUD = 2, + WINED3D_SHADE_PHONG = 3, +}; -typedef enum _WINED3DFILLMODE +enum wined3d_fill_mode { - WINED3DFILL_POINT = 1, - WINED3DFILL_WIREFRAME = 2, - WINED3DFILL_SOLID = 3, - WINED3DFILL_FORCE_DWORD = 0x7fffffff -} WINED3DFILLMODE; + WINED3D_FILL_POINT = 1, + WINED3D_FILL_WIREFRAME = 2, + WINED3D_FILL_SOLID = 3, +}; -typedef enum _WINED3DCULL +enum wined3d_cull { - WINED3DCULL_NONE = 1, - WINED3DCULL_CW = 2, - WINED3DCULL_CCW = 3, - WINED3DCULL_FORCE_DWORD = 0x7fffffff -} WINED3DCULL; + WINED3D_CULL_NONE = 1, + WINED3D_CULL_CW = 2, + WINED3D_CULL_CCW = 3, +}; -typedef enum _WINED3DSTENCILOP +enum wined3d_stencil_op { - WINED3DSTENCILOP_KEEP = 1, - WINED3DSTENCILOP_ZERO = 2, - WINED3DSTENCILOP_REPLACE = 3, - WINED3DSTENCILOP_INCRSAT = 4, - WINED3DSTENCILOP_DECRSAT = 5, - WINED3DSTENCILOP_INVERT = 6, - WINED3DSTENCILOP_INCR = 7, - WINED3DSTENCILOP_DECR = 8, - WINED3DSTENCILOP_FORCE_DWORD = 0x7fffffff -} WINED3DSTENCILOP; + WINED3D_STENCIL_OP_KEEP = 1, + WINED3D_STENCIL_OP_ZERO = 2, + WINED3D_STENCIL_OP_REPLACE = 3, + WINED3D_STENCIL_OP_INCR_SAT = 4, + WINED3D_STENCIL_OP_DECR_SAT = 5, + WINED3D_STENCIL_OP_INVERT = 6, + WINED3D_STENCIL_OP_INCR = 7, + WINED3D_STENCIL_OP_DECR = 8, +}; -typedef enum _WINED3DMATERIALCOLORSOURCE +enum wined3d_material_color_source { - WINED3DMCS_MATERIAL = 0, - WINED3DMCS_COLOR1 = 1, - WINED3DMCS_COLOR2 = 2, - WINED3DMCS_FORCE_DWORD = 0x7fffffff -} WINED3DMATERIALCOLORSOURCE; + WINED3D_MCS_MATERIAL = 0, + WINED3D_MCS_COLOR1 = 1, + WINED3D_MCS_COLOR2 = 2, +}; -typedef enum _WINED3DPATCHEDGESTYLE +enum wined3d_patch_edge_style { - WINED3DPATCHEDGE_DISCRETE = 0, - WINED3DPATCHEDGE_CONTINUOUS = 1, - WINED3DPATCHEDGE_FORCE_DWORD = 0x7fffffff -} WINED3DPATCHEDGESTYLE; + WINED3D_PATCH_EDGE_DISCRETE = 0, + WINED3D_PATCH_EDGE_CONTINUOUS = 1, +}; -typedef enum _WINED3DBACKBUFFER_TYPE +enum wined3d_backbuffer_type { - WINED3DBACKBUFFER_TYPE_MONO = 0, - WINED3DBACKBUFFER_TYPE_LEFT = 1, - WINED3DBACKBUFFER_TYPE_RIGHT = 2, - WINED3DBACKBUFFER_TYPE_FORCE_DWORD = 0x7fffffff -} WINED3DBACKBUFFER_TYPE; + WINED3D_BACKBUFFER_TYPE_MONO = 0, + WINED3D_BACKBUFFER_TYPE_LEFT = 1, + WINED3D_BACKBUFFER_TYPE_RIGHT = 2, +}; -typedef enum _WINED3DSWAPEFFECT +enum wined3d_swap_effect { - WINED3DSWAPEFFECT_DISCARD = 1, - WINED3DSWAPEFFECT_FLIP = 2, - WINED3DSWAPEFFECT_COPY = 3, - WINED3DSWAPEFFECT_COPY_VSYNC = 4, - WINED3DSWAPEFFECT_FORCE_DWORD = 0xffffffff -} WINED3DSWAPEFFECT; + WINED3D_SWAP_EFFECT_DISCARD = 1, + WINED3D_SWAP_EFFECT_FLIP = 2, + WINED3D_SWAP_EFFECT_COPY = 3, + WINED3D_SWAP_EFFECT_COPY_VSYNC = 4, +}; -typedef enum _WINED3DSAMPLERSTATETYPE +enum wined3d_sampler_state { - WINED3DSAMP_ADDRESSU = 1, - WINED3DSAMP_ADDRESSV = 2, - WINED3DSAMP_ADDRESSW = 3, - WINED3DSAMP_BORDERCOLOR = 4, - WINED3DSAMP_MAGFILTER = 5, - WINED3DSAMP_MINFILTER = 6, - WINED3DSAMP_MIPFILTER = 7, - WINED3DSAMP_MIPMAPLODBIAS = 8, - WINED3DSAMP_MAXMIPLEVEL = 9, - WINED3DSAMP_MAXANISOTROPY = 10, - WINED3DSAMP_SRGBTEXTURE = 11, - WINED3DSAMP_ELEMENTINDEX = 12, - WINED3DSAMP_DMAPOFFSET = 13, - WINED3DSAMP_FORCE_DWORD = 0x7fffffff, -} WINED3DSAMPLERSTATETYPE; -#define WINED3D_HIGHEST_SAMPLER_STATE WINED3DSAMP_DMAPOFFSET + WINED3D_SAMP_ADDRESS_U = 1, + WINED3D_SAMP_ADDRESS_V = 2, + WINED3D_SAMP_ADDRESS_W = 3, + WINED3D_SAMP_BORDER_COLOR = 4, + WINED3D_SAMP_MAG_FILTER = 5, + WINED3D_SAMP_MIN_FILTER = 6, + WINED3D_SAMP_MIP_FILTER = 7, + WINED3D_SAMP_MIPMAP_LOD_BIAS = 8, + WINED3D_SAMP_MAX_MIP_LEVEL = 9, + WINED3D_SAMP_MAX_ANISOTROPY = 10, + WINED3D_SAMP_SRGB_TEXTURE = 11, + WINED3D_SAMP_ELEMENT_INDEX = 12, + WINED3D_SAMP_DMAP_OFFSET = 13, +}; +#define WINED3D_HIGHEST_SAMPLER_STATE WINED3D_SAMP_DMAP_OFFSET -typedef enum _WINED3DMULTISAMPLE_TYPE +enum wined3d_multisample_type { - WINED3DMULTISAMPLE_NONE = 0, - WINED3DMULTISAMPLE_NONMASKABLE = 1, - WINED3DMULTISAMPLE_2_SAMPLES = 2, - WINED3DMULTISAMPLE_3_SAMPLES = 3, - WINED3DMULTISAMPLE_4_SAMPLES = 4, - WINED3DMULTISAMPLE_5_SAMPLES = 5, - WINED3DMULTISAMPLE_6_SAMPLES = 6, - WINED3DMULTISAMPLE_7_SAMPLES = 7, - WINED3DMULTISAMPLE_8_SAMPLES = 8, - WINED3DMULTISAMPLE_9_SAMPLES = 9, - WINED3DMULTISAMPLE_10_SAMPLES = 10, - WINED3DMULTISAMPLE_11_SAMPLES = 11, - WINED3DMULTISAMPLE_12_SAMPLES = 12, - WINED3DMULTISAMPLE_13_SAMPLES = 13, - WINED3DMULTISAMPLE_14_SAMPLES = 14, - WINED3DMULTISAMPLE_15_SAMPLES = 15, - WINED3DMULTISAMPLE_16_SAMPLES = 16, - WINED3DMULTISAMPLE_FORCE_DWORD = 0xffffffff -} WINED3DMULTISAMPLE_TYPE; + WINED3D_MULTISAMPLE_NONE = 0, + WINED3D_MULTISAMPLE_NON_MASKABLE = 1, + WINED3D_MULTISAMPLE_2_SAMPLES = 2, + WINED3D_MULTISAMPLE_3_SAMPLES = 3, + WINED3D_MULTISAMPLE_4_SAMPLES = 4, + WINED3D_MULTISAMPLE_5_SAMPLES = 5, + WINED3D_MULTISAMPLE_6_SAMPLES = 6, + WINED3D_MULTISAMPLE_7_SAMPLES = 7, + WINED3D_MULTISAMPLE_8_SAMPLES = 8, + WINED3D_MULTISAMPLE_9_SAMPLES = 9, + WINED3D_MULTISAMPLE_10_SAMPLES = 10, + WINED3D_MULTISAMPLE_11_SAMPLES = 11, + WINED3D_MULTISAMPLE_12_SAMPLES = 12, + WINED3D_MULTISAMPLE_13_SAMPLES = 13, + WINED3D_MULTISAMPLE_14_SAMPLES = 14, + WINED3D_MULTISAMPLE_15_SAMPLES = 15, + WINED3D_MULTISAMPLE_16_SAMPLES = 16, +}; -typedef enum _WINED3DTEXTURESTAGESTATETYPE +enum wined3d_texture_stage_state { - WINED3DTSS_COLOROP = 0, - WINED3DTSS_COLORARG1 = 1, - WINED3DTSS_COLORARG2 = 2, - WINED3DTSS_ALPHAOP = 3, - WINED3DTSS_ALPHAARG1 = 4, - WINED3DTSS_ALPHAARG2 = 5, - WINED3DTSS_BUMPENVMAT00 = 6, - WINED3DTSS_BUMPENVMAT01 = 7, - WINED3DTSS_BUMPENVMAT10 = 8, - WINED3DTSS_BUMPENVMAT11 = 9, - WINED3DTSS_TEXCOORDINDEX = 10, - WINED3DTSS_BUMPENVLSCALE = 11, - WINED3DTSS_BUMPENVLOFFSET = 12, - WINED3DTSS_TEXTURETRANSFORMFLAGS = 13, - WINED3DTSS_COLORARG0 = 14, - WINED3DTSS_ALPHAARG0 = 15, - WINED3DTSS_RESULTARG = 16, - WINED3DTSS_CONSTANT = 17, - WINED3DTSS_FORCE_DWORD = 0x7fffffff -} WINED3DTEXTURESTAGESTATETYPE; -#define WINED3D_HIGHEST_TEXTURE_STATE WINED3DTSS_CONSTANT + WINED3D_TSS_COLOR_OP = 0, + WINED3D_TSS_COLOR_ARG1 = 1, + WINED3D_TSS_COLOR_ARG2 = 2, + WINED3D_TSS_ALPHA_OP = 3, + WINED3D_TSS_ALPHA_ARG1 = 4, + WINED3D_TSS_ALPHA_ARG2 = 5, + WINED3D_TSS_BUMPENV_MAT00 = 6, + WINED3D_TSS_BUMPENV_MAT01 = 7, + WINED3D_TSS_BUMPENV_MAT10 = 8, + WINED3D_TSS_BUMPENV_MAT11 = 9, + WINED3D_TSS_TEXCOORD_INDEX = 10, + WINED3D_TSS_BUMPENV_LSCALE = 11, + WINED3D_TSS_BUMPENV_LOFFSET = 12, + WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS = 13, + WINED3D_TSS_COLOR_ARG0 = 14, + WINED3D_TSS_ALPHA_ARG0 = 15, + WINED3D_TSS_RESULT_ARG = 16, + WINED3D_TSS_CONSTANT = 17, + WINED3D_TSS_INVALID = ~0U, +}; +#define WINED3D_HIGHEST_TEXTURE_STATE WINED3D_TSS_CONSTANT -typedef enum _WINED3DTEXTURETRANSFORMFLAGS +enum wined3d_texture_transform_flags { - WINED3DTTFF_DISABLE = 0, - WINED3DTTFF_COUNT1 = 1, - WINED3DTTFF_COUNT2 = 2, - WINED3DTTFF_COUNT3 = 3, - WINED3DTTFF_COUNT4 = 4, - WINED3DTTFF_PROJECTED = 256, - WINED3DTTFF_FORCE_DWORD = 0x7fffffff -} WINED3DTEXTURETRANSFORMFLAGS; + WINED3D_TTFF_DISABLE = 0, + WINED3D_TTFF_COUNT1 = 1, + WINED3D_TTFF_COUNT2 = 2, + WINED3D_TTFF_COUNT3 = 3, + WINED3D_TTFF_COUNT4 = 4, + WINED3D_TTFF_PROJECTED = 256, +}; -typedef enum _WINED3DTEXTUREOP +enum wined3d_texture_op { - WINED3DTOP_DISABLE = 1, - WINED3DTOP_SELECTARG1 = 2, - WINED3DTOP_SELECTARG2 = 3, - WINED3DTOP_MODULATE = 4, - WINED3DTOP_MODULATE2X = 5, - WINED3DTOP_MODULATE4X = 6, - WINED3DTOP_ADD = 7, - WINED3DTOP_ADDSIGNED = 8, - WINED3DTOP_ADDSIGNED2X = 9, - WINED3DTOP_SUBTRACT = 10, - WINED3DTOP_ADDSMOOTH = 11, - WINED3DTOP_BLENDDIFFUSEALPHA = 12, - WINED3DTOP_BLENDTEXTUREALPHA = 13, - WINED3DTOP_BLENDFACTORALPHA = 14, - WINED3DTOP_BLENDTEXTUREALPHAPM = 15, - WINED3DTOP_BLENDCURRENTALPHA = 16, - WINED3DTOP_PREMODULATE = 17, - WINED3DTOP_MODULATEALPHA_ADDCOLOR = 18, - WINED3DTOP_MODULATECOLOR_ADDALPHA = 19, - WINED3DTOP_MODULATEINVALPHA_ADDCOLOR = 20, - WINED3DTOP_MODULATEINVCOLOR_ADDALPHA = 21, - WINED3DTOP_BUMPENVMAP = 22, - WINED3DTOP_BUMPENVMAPLUMINANCE = 23, - WINED3DTOP_DOTPRODUCT3 = 24, - WINED3DTOP_MULTIPLYADD = 25, - WINED3DTOP_LERP = 26, - WINED3DTOP_FORCE_DWORD = 0x7fffffff, -} WINED3DTEXTUREOP; + WINED3D_TOP_DISABLE = 1, + WINED3D_TOP_SELECT_ARG1 = 2, + WINED3D_TOP_SELECT_ARG2 = 3, + WINED3D_TOP_MODULATE = 4, + WINED3D_TOP_MODULATE_2X = 5, + WINED3D_TOP_MODULATE_4X = 6, + WINED3D_TOP_ADD = 7, + WINED3D_TOP_ADD_SIGNED = 8, + WINED3D_TOP_ADD_SIGNED_2X = 9, + WINED3D_TOP_SUBTRACT = 10, + WINED3D_TOP_ADD_SMOOTH = 11, + WINED3D_TOP_BLEND_DIFFUSE_ALPHA = 12, + WINED3D_TOP_BLEND_TEXTURE_ALPHA = 13, + WINED3D_TOP_BLEND_FACTOR_ALPHA = 14, + WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM = 15, + WINED3D_TOP_BLEND_CURRENT_ALPHA = 16, + WINED3D_TOP_PREMODULATE = 17, + WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR = 18, + WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA = 19, + WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR = 20, + WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA = 21, + WINED3D_TOP_BUMPENVMAP = 22, + WINED3D_TOP_BUMPENVMAP_LUMINANCE = 23, + WINED3D_TOP_DOTPRODUCT3 = 24, + WINED3D_TOP_MULTIPLY_ADD = 25, + WINED3D_TOP_LERP = 26, +}; -typedef enum _WINED3DTEXTUREADDRESS +enum wined3d_texture_address { - WINED3DTADDRESS_WRAP = 1, - WINED3DTADDRESS_MIRROR = 2, - WINED3DTADDRESS_CLAMP = 3, - WINED3DTADDRESS_BORDER = 4, - WINED3DTADDRESS_MIRRORONCE = 5, - WINED3DTADDRESS_FORCE_DWORD = 0x7fffffff -} WINED3DTEXTUREADDRESS; + WINED3D_TADDRESS_WRAP = 1, + WINED3D_TADDRESS_MIRROR = 2, + WINED3D_TADDRESS_CLAMP = 3, + WINED3D_TADDRESS_BORDER = 4, + WINED3D_TADDRESS_MIRROR_ONCE = 5, +}; -typedef enum _WINED3DTRANSFORMSTATETYPE +enum wined3d_transform_state { - WINED3DTS_VIEW = 2, - WINED3DTS_PROJECTION = 3, - WINED3DTS_TEXTURE0 = 16, - WINED3DTS_TEXTURE1 = 17, - WINED3DTS_TEXTURE2 = 18, - WINED3DTS_TEXTURE3 = 19, - WINED3DTS_TEXTURE4 = 20, - WINED3DTS_TEXTURE5 = 21, - WINED3DTS_TEXTURE6 = 22, - WINED3DTS_TEXTURE7 = 23, - WINED3DTS_WORLD = 256, /*WINED3DTS_WORLDMATRIX(0)*/ - WINED3DTS_WORLD1 = 257, - WINED3DTS_WORLD2 = 258, - WINED3DTS_WORLD3 = 259, - WINED3DTS_FORCE_DWORD = 0x7fffffff -} WINED3DTRANSFORMSTATETYPE; + WINED3D_TS_VIEW = 2, + WINED3D_TS_PROJECTION = 3, + WINED3D_TS_TEXTURE0 = 16, + WINED3D_TS_TEXTURE1 = 17, + WINED3D_TS_TEXTURE2 = 18, + WINED3D_TS_TEXTURE3 = 19, + WINED3D_TS_TEXTURE4 = 20, + WINED3D_TS_TEXTURE5 = 21, + WINED3D_TS_TEXTURE6 = 22, + WINED3D_TS_TEXTURE7 = 23, + WINED3D_TS_WORLD = 256, /* WINED3D_TS_WORLD_MATRIX(0) */ + WINED3D_TS_WORLD1 = 257, + WINED3D_TS_WORLD2 = 258, + WINED3D_TS_WORLD3 = 259, +}; -#define WINED3DTS_WORLDMATRIX(index) (WINED3DTRANSFORMSTATETYPE)(index + 256) +#define WINED3D_TS_WORLD_MATRIX(index) (enum wined3d_transform_state)(index + 256) -typedef enum _WINED3DBASISTYPE +enum wined3d_basis_type { - WINED3DBASIS_BEZIER = 0, - WINED3DBASIS_BSPLINE = 1, - WINED3DBASIS_INTERPOLATE = 2, - WINED3DBASIS_FORCE_DWORD = 0x7fffffff -} WINED3DBASISTYPE; + WINED3D_BASIS_BEZIER = 0, + WINED3D_BASIS_BSPLINE = 1, + WINED3D_BASIS_INTERPOLATE = 2, +}; -typedef enum _WINED3DCUBEMAP_FACES +enum wined3d_cubemap_face { - WINED3DCUBEMAP_FACE_POSITIVE_X = 0, - WINED3DCUBEMAP_FACE_NEGATIVE_X = 1, - WINED3DCUBEMAP_FACE_POSITIVE_Y = 2, - WINED3DCUBEMAP_FACE_NEGATIVE_Y = 3, - WINED3DCUBEMAP_FACE_POSITIVE_Z = 4, - WINED3DCUBEMAP_FACE_NEGATIVE_Z = 5, - WINED3DCUBEMAP_FACE_FORCE_DWORD = 0xffffffff -} WINED3DCUBEMAP_FACES; + WINED3D_CUBEMAP_FACE_POSITIVE_X = 0, + WINED3D_CUBEMAP_FACE_NEGATIVE_X = 1, + WINED3D_CUBEMAP_FACE_POSITIVE_Y = 2, + WINED3D_CUBEMAP_FACE_NEGATIVE_Y = 3, + WINED3D_CUBEMAP_FACE_POSITIVE_Z = 4, + WINED3D_CUBEMAP_FACE_NEGATIVE_Z = 5, +}; -typedef enum _WINED3DTEXTUREFILTERTYPE +enum wined3d_texture_filter_type { - WINED3DTEXF_NONE = 0, - WINED3DTEXF_POINT = 1, - WINED3DTEXF_LINEAR = 2, - WINED3DTEXF_ANISOTROPIC = 3, - WINED3DTEXF_FLATCUBIC = 4, - WINED3DTEXF_GAUSSIANCUBIC = 5, - WINED3DTEXF_PYRAMIDALQUAD = 6, - WINED3DTEXF_GAUSSIANQUAD = 7, - WINED3DTEXF_FORCE_DWORD = 0x7fffffff -} WINED3DTEXTUREFILTERTYPE; + WINED3D_TEXF_NONE = 0, + WINED3D_TEXF_POINT = 1, + WINED3D_TEXF_LINEAR = 2, + WINED3D_TEXF_ANISOTROPIC = 3, + WINED3D_TEXF_FLAT_CUBIC = 4, + WINED3D_TEXF_GAUSSIAN_CUBIC = 5, + WINED3D_TEXF_PYRAMIDAL_QUAD = 6, + WINED3D_TEXF_GAUSSIAN_QUAD = 7, +}; -typedef enum _WINED3DRESOURCETYPE +enum wined3d_resource_type { - WINED3DRTYPE_SURFACE = 1, - WINED3DRTYPE_VOLUME = 2, - WINED3DRTYPE_TEXTURE = 3, - WINED3DRTYPE_VOLUMETEXTURE = 4, - WINED3DRTYPE_CUBETEXTURE = 5, - WINED3DRTYPE_BUFFER = 6, - WINED3DRTYPE_FORCE_DWORD = 0x7fffffff -} WINED3DRESOURCETYPE; -#define WINED3DRTYPECOUNT WINED3DRTYPE_BUFFER + WINED3D_RTYPE_SURFACE = 1, + WINED3D_RTYPE_VOLUME = 2, + WINED3D_RTYPE_TEXTURE = 3, + WINED3D_RTYPE_VOLUME_TEXTURE = 4, + WINED3D_RTYPE_CUBE_TEXTURE = 5, + WINED3D_RTYPE_BUFFER = 6, +}; -typedef enum _WINED3DPOOL +enum wined3d_pool { - WINED3DPOOL_DEFAULT = 0, - WINED3DPOOL_MANAGED = 1, - WINED3DPOOL_SYSTEMMEM = 2, - WINED3DPOOL_SCRATCH = 3, - WINED3DPOOL_FORCE_DWORD = 0x7fffffff -} WINED3DPOOL; + WINED3D_POOL_DEFAULT = 0, + WINED3D_POOL_MANAGED = 1, + WINED3D_POOL_SYSTEM_MEM = 2, + WINED3D_POOL_SCRATCH = 3, +}; -typedef enum _WINED3DQUERYTYPE +enum wined3d_query_type { - WINED3DQUERYTYPE_VCACHE = 4, - WINED3DQUERYTYPE_RESOURCEMANAGER = 5, - WINED3DQUERYTYPE_VERTEXSTATS = 6, - WINED3DQUERYTYPE_EVENT = 8, - WINED3DQUERYTYPE_OCCLUSION = 9, - WINED3DQUERYTYPE_TIMESTAMP = 10, - WINED3DQUERYTYPE_TIMESTAMPDISJOINT = 11, - WINED3DQUERYTYPE_TIMESTAMPFREQ = 12, - WINED3DQUERYTYPE_PIPELINETIMINGS = 13, - WINED3DQUERYTYPE_INTERFACETIMINGS = 14, - WINED3DQUERYTYPE_VERTEXTIMINGS = 15, - WINED3DQUERYTYPE_PIXELTIMINGS = 16, - WINED3DQUERYTYPE_BANDWIDTHTIMINGS = 17, - WINED3DQUERYTYPE_CACHEUTILIZATION = 18 -} WINED3DQUERYTYPE; + WINED3D_QUERY_TYPE_VCACHE = 4, + WINED3D_QUERY_TYPE_RESOURCE_MANAGER = 5, + WINED3D_QUERY_TYPE_VERTEX_STATS = 6, + WINED3D_QUERY_TYPE_EVENT = 8, + WINED3D_QUERY_TYPE_OCCLUSION = 9, + WINED3D_QUERY_TYPE_TIMESTAMP = 10, + WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT = 11, + WINED3D_QUERY_TYPE_TIMESTAMP_FREQ = 12, + WINED3D_QUERY_TYPE_PIPELINE_TIMINGS = 13, + WINED3D_QUERY_TYPE_INTERFACE_TIMINGS = 14, + WINED3D_QUERY_TYPE_VERTEX_TIMINGS = 15, + WINED3D_QUERY_TYPE_PIXEL_TIMINGS = 16, + WINED3D_QUERY_TYPE_BANDWIDTH_TIMINGS = 17, + WINED3D_QUERY_TYPE_CACHE_UTILIZATION = 18 +}; #define WINED3DISSUE_BEGIN (1 << 1) #define WINED3DISSUE_END (1 << 0) #define WINED3DGETDATA_FLUSH (1 << 0) -typedef enum _WINED3DSTATEBLOCKTYPE +enum wined3d_stateblock_type { - WINED3DSBT_INIT = 0, - WINED3DSBT_ALL = 1, - WINED3DSBT_PIXELSTATE = 2, - WINED3DSBT_VERTEXSTATE = 3, - WINED3DSBT_RECORDED = 4, /* WineD3D private */ - WINED3DSBT_FORCE_DWORD = 0xffffffff -} WINED3DSTATEBLOCKTYPE; + WINED3D_SBT_INIT = 0, + WINED3D_SBT_ALL = 1, + WINED3D_SBT_PIXEL_STATE = 2, + WINED3D_SBT_VERTEX_STATE = 3, + WINED3D_SBT_RECORDED = 4, /* WineD3D private */ +}; typedef enum _WINED3DDECLMETHOD { @@ -781,7 +750,6 @@ typedef enum _WINED3DDECLUSAGE typedef enum _WINED3DSURFTYPE { - SURFACE_UNKNOWN = 0, /* Default / Unknown surface type */ SURFACE_OPENGL, /* OpenGL surface: Renders using libGL, needed for 3D */ SURFACE_GDI, /* User surface. No 3D, DirectDraw rendering with GDI */ } WINED3DSURFTYPE; @@ -846,6 +814,7 @@ enum wined3d_sysval_semantic #define WINED3DUSAGE_AUTOGENMIPMAP 0x00000400 #define WINED3DUSAGE_DMAP 0x00004000 #define WINED3DUSAGE_MASK 0x00004fff +#define WINED3DUSAGE_OWNDC 0x20000000 #define WINED3DUSAGE_STATICDECL 0x40000000 #define WINED3DUSAGE_OVERLAY 0x80000000 @@ -1233,6 +1202,8 @@ enum wined3d_sysval_semantic #define WINED3DDEVCAPS_RTPATCHHANDLEZERO 0x00800000 #define WINED3DDEVCAPS_NPATCHES 0x01000000 +#define WINED3D_LEGACY_DEPTH_BIAS 0x00000001 + /* dwDDFX */ /* arithmetic stretching along y axis */ #define WINEDDBLTFX_ARITHSTRETCHY 0x00000001 @@ -1282,13 +1253,6 @@ enum wined3d_sysval_semantic #define WINEDDBLT_DEPTHFILL 0x02000000 #define WINEDDBLT_DONOTWAIT 0x08000000 -/* dwTrans for BltFast */ -#define WINEDDBLTFAST_NOCOLORKEY 0x00000000 -#define WINEDDBLTFAST_SRCCOLORKEY 0x00000001 -#define WINEDDBLTFAST_DESTCOLORKEY 0x00000002 -#define WINEDDBLTFAST_WAIT 0x00000010 -#define WINEDDBLTFAST_DONOTWAIT 0x00000020 - /* DDSURFACEDESC.dwFlags */ #define WINEDDSD_CAPS 0x00000001 #define WINEDDSD_HEIGHT 0x00000002 @@ -1514,30 +1478,34 @@ enum wined3d_sysval_semantic #define WINEDDPCAPS_2BIT 0x00000200 #define WINEDDPCAPS_ALPHA 0x00000400 -typedef struct _WINED3DDISPLAYMODE -{ - UINT Width; - UINT Height; - UINT RefreshRate; - enum wined3d_format_id Format; -} WINED3DDISPLAYMODE; +#define WINED3D_SURFACE_MAPPABLE 0x00000001 +#define WINED3D_SURFACE_DISCARD 0x00000002 +#define WINED3D_SURFACE_PIN_SYSMEM 0x00000004 -typedef struct _WINED3DCOLORVALUE +struct wined3d_display_mode +{ + UINT width; + UINT height; + UINT refresh_rate; + enum wined3d_format_id format_id; +}; + +struct wined3d_color { float r; float g; float b; float a; -} WINED3DCOLORVALUE; +}; -typedef struct _WINED3DVECTOR +struct wined3d_vec3 { float x; float y; float z; -} WINED3DVECTOR; +}; -typedef struct _WINED3DMATRIX +struct wined3d_matrix { union { @@ -1550,77 +1518,77 @@ typedef struct _WINED3DMATRIX } DUMMYSTRUCTNAME; float m[4][4]; } DUMMYUNIONNAME; -} WINED3DMATRIX; +}; -typedef struct _WINED3DLIGHT +struct wined3d_light { - WINED3DLIGHTTYPE Type; - WINED3DCOLORVALUE Diffuse; - WINED3DCOLORVALUE Specular; - WINED3DCOLORVALUE Ambient; - WINED3DVECTOR Position; - WINED3DVECTOR Direction; - float Range; - float Falloff; - float Attenuation0; - float Attenuation1; - float Attenuation2; - float Theta; - float Phi; -} WINED3DLIGHT; + enum wined3d_light_type type; + struct wined3d_color diffuse; + struct wined3d_color specular; + struct wined3d_color ambient; + struct wined3d_vec3 position; + struct wined3d_vec3 direction; + float range; + float falloff; + float attenuation0; + float attenuation1; + float attenuation2; + float theta; + float phi; +}; -typedef struct _WINED3DMATERIAL +struct wined3d_material { - WINED3DCOLORVALUE Diffuse; - WINED3DCOLORVALUE Ambient; - WINED3DCOLORVALUE Specular; - WINED3DCOLORVALUE Emissive; - float Power; -} WINED3DMATERIAL; + struct wined3d_color diffuse; + struct wined3d_color ambient; + struct wined3d_color specular; + struct wined3d_color emissive; + float power; +}; -typedef struct _WINED3DVIEWPORT +struct wined3d_viewport { - DWORD X; - DWORD Y; - DWORD Width; - DWORD Height; - float MinZ; - float MaxZ; -} WINED3DVIEWPORT; + UINT x; + UINT y; + UINT width; + UINT height; + float min_z; + float max_z; +}; -typedef struct _WINED3DGAMMARAMP +struct wined3d_gamma_ramp { WORD red[256]; WORD green[256]; WORD blue[256]; -} WINED3DGAMMARAMP; +}; -typedef struct _WINED3DLINEPATTERN +struct wined3d_line_pattern { - WORD wRepeatFactor; - WORD wLinePattern; -} WINED3DLINEPATTERN; + WORD repeat_factor; + WORD line_pattern; +}; -typedef struct _WINEDD3DRECTPATCH_INFO +struct wined3d_rect_patch_info { - UINT StartVertexOffsetWidth; - UINT StartVertexOffsetHeight; - UINT Width; - UINT Height; - UINT Stride; - WINED3DBASISTYPE Basis; - WINED3DDEGREETYPE Degree; -} WINED3DRECTPATCH_INFO; + UINT start_vertex_offset_width; + UINT start_vertex_offset_height; + UINT width; + UINT height; + UINT stride; + enum wined3d_basis_type basis; + enum wined3d_degree_type degree; +}; -typedef struct _WINED3DTRIPATCH_INFO +struct wined3d_tri_patch_info { - UINT StartVertexOffset; - UINT NumVertices; - WINED3DBASISTYPE Basis; - WINED3DDEGREETYPE Degree; -} WINED3DTRIPATCH_INFO; + UINT start_vertex_offset; + UINT vertex_count; + enum wined3d_basis_type basis; + enum wined3d_degree_type degree; +}; -typedef struct _WINED3DADAPTER_IDENTIFIER +struct wined3d_adapter_identifier { char *driver; UINT driver_size; @@ -1637,48 +1605,48 @@ typedef struct _WINED3DADAPTER_IDENTIFIER DWORD whql_level; LUID adapter_luid; SIZE_T video_memory; -} WINED3DADAPTER_IDENTIFIER; +}; -typedef struct _WINED3DPRESENT_PARAMETERS +struct wined3d_swapchain_desc { - UINT BackBufferWidth; - UINT BackBufferHeight; - enum wined3d_format_id BackBufferFormat; - UINT BackBufferCount; - WINED3DMULTISAMPLE_TYPE MultiSampleType; - DWORD MultiSampleQuality; - WINED3DSWAPEFFECT SwapEffect; - HWND hDeviceWindow; - BOOL Windowed; - BOOL EnableAutoDepthStencil; - enum wined3d_format_id AutoDepthStencilFormat; - DWORD Flags; - UINT FullScreen_RefreshRateInHz; - UINT PresentationInterval; - BOOL AutoRestoreDisplayMode; -} WINED3DPRESENT_PARAMETERS; + UINT backbuffer_width; + UINT backbuffer_height; + enum wined3d_format_id backbuffer_format; + UINT backbuffer_count; + enum wined3d_multisample_type multisample_type; + DWORD multisample_quality; + enum wined3d_swap_effect swap_effect; + HWND device_window; + BOOL windowed; + BOOL enable_auto_depth_stencil; + enum wined3d_format_id auto_depth_stencil_format; + DWORD flags; + UINT refresh_rate; + UINT swap_interval; + BOOL auto_restore_display_mode; +}; struct wined3d_resource_desc { - WINED3DRESOURCETYPE resource_type; + enum wined3d_resource_type resource_type; enum wined3d_format_id format; - WINED3DMULTISAMPLE_TYPE multisample_type; + enum wined3d_multisample_type multisample_type; UINT multisample_quality; DWORD usage; - WINED3DPOOL pool; + enum wined3d_pool pool; UINT width; UINT height; UINT depth; UINT size; }; -typedef struct _WINED3DCLIPSTATUS +struct wined3d_clip_status { - DWORD ClipUnion; - DWORD ClipIntersection; -} WINED3DCLIPSTATUS; + DWORD clip_union; + DWORD clip_intersection; +}; -typedef struct _WINED3DVERTEXELEMENT +struct wined3d_vertex_element { enum wined3d_format_id format; WORD input_slot; @@ -1687,178 +1655,104 @@ typedef struct _WINED3DVERTEXELEMENT BYTE method; BYTE usage; BYTE usage_idx; -} WINED3DVERTEXELEMENT; +}; -typedef struct _WINED3DDEVICE_CREATION_PARAMETERS +struct wined3d_device_creation_parameters { - UINT AdapterOrdinal; - WINED3DDEVTYPE DeviceType; - HWND hFocusWindow; - DWORD BehaviorFlags; -} WINED3DDEVICE_CREATION_PARAMETERS; + UINT adapter_idx; + enum wined3d_device_type device_type; + HWND focus_window; + DWORD flags; +}; -typedef struct _WINED3DDEVINFO_BANDWIDTHTIMINGS +struct wined3d_raster_status { - float MaxBandwidthUtilized; - float FrontEndUploadMemoryUtilizedPercent; - float VertexRateUtilizedPercent; - float TriangleSetupRateUtilizedPercent; - float FillRateUtilizedPercent; -} WINED3DDEVINFO_BANDWIDTHTIMINGS; + BOOL in_vblank; + UINT scan_line; +}; -typedef struct _WINED3DDEVINFO_CACHEUTILIZATION +struct wined3d_mapped_rect { - float TextureCacheHitRate; - float PostTransformVertexCacheHitRate; -} WINED3DDEVINFO_CACHEUTILIZATION; + UINT row_pitch; + void *data; +}; -typedef struct _WINED3DDEVINFO_INTERFACETIMINGS +struct wined3d_mapped_box { - float WaitingForGPUToUseApplicationResourceTimePercent; - float WaitingForGPUToAcceptMoreCommandsTimePercent; - float WaitingForGPUToStayWithinLatencyTimePercent; - float WaitingForGPUExclusiveResourceTimePercent; - float WaitingForGPUOtherTimePercent; -} WINED3DDEVINFO_INTERFACETIMINGS; + UINT row_pitch; + UINT slice_pitch; + void *data; +}; -typedef struct _WINED3DDEVINFO_PIPELINETIMINGS +struct wined3d_box { - float VertexProcessingTimePercent; - float PixelProcessingTimePercent; - float OtherGPUProcessingTimePercent; - float GPUIdleTimePercent; -} WINED3DDEVINFO_PIPELINETIMINGS; + UINT left; + UINT top; + UINT right; + UINT bottom; + UINT front; + UINT back; +}; -typedef struct _WINED3DDEVINFO_STAGETIMINGS +struct wined3d_strided_element { - float MemoryProcessingPercent; - float ComputationProcessingPercent; -} WINED3DDEVINFO_STAGETIMINGS; + enum wined3d_format_id format; /* Format of the data */ + const BYTE *data; /* Pointer to start of data */ + UINT stride; /* Stride between occurrences of this data */ +}; -typedef struct _WINED3DRASTER_STATUS +struct wined3d_strided_data { - BOOL InVBlank; - UINT ScanLine; -} WINED3DRASTER_STATUS; - -typedef struct WINED3DRESOURCESTATS -{ - BOOL bThrashing; - DWORD ApproxBytesDownloaded; - DWORD NumEvicts; - DWORD NumVidCreates; - DWORD LastPri; - DWORD NumUsed; - DWORD NumUsedInVidMem; - DWORD WorkingSet; - DWORD WorkingSetBytes; - DWORD TotalManaged; - DWORD TotalBytes; -} WINED3DRESOURCESTATS; - -typedef struct _WINED3DDEVINFO_RESOURCEMANAGER -{ - WINED3DRESOURCESTATS stats[WINED3DRTYPECOUNT]; -} WINED3DDEVINFO_RESOURCEMANAGER; - -typedef struct _WINED3DDEVINFO_VERTEXSTATS -{ - DWORD NumRenderedTriangles; - DWORD NumExtraClippingTriangles; -} WINED3DDEVINFO_VERTEXSTATS; - -typedef struct _WINED3DLOCKED_RECT -{ - INT Pitch; - void *pBits; -} WINED3DLOCKED_RECT; - -typedef struct _WINED3DLOCKED_BOX -{ - INT RowPitch; - INT SlicePitch; - void *pBits; -} WINED3DLOCKED_BOX; - -typedef struct _WINED3DBOX -{ - UINT Left; - UINT Top; - UINT Right; - UINT Bottom; - UINT Front; - UINT Back; -} WINED3DBOX; - -/*Vertex cache optimization hints.*/ -typedef struct WINED3DDEVINFO_VCACHE -{ - DWORD Pattern; /* Must be a 4 char code FOURCC (e.g. CACH) */ - DWORD OptMethod; /* 0 to get the longest strips, 1 vertex cache */ - DWORD CacheSize; /* Cache size to use (only valid if OptMethod==1) */ - DWORD MagicNumber; /* Internal for deciding when to restart strips, - non user modifiable (only valid if OptMethod==1) */ -} WINED3DDEVINFO_VCACHE; - -typedef struct WineDirect3DStridedData -{ - enum wined3d_format_id format; /* Format of the data */ - const BYTE *lpData; /* Pointer to start of data */ - DWORD dwStride; /* Stride between occurrences of this data */ -} WineDirect3DStridedData; - -typedef struct WineDirect3DVertexStridedData -{ - WineDirect3DStridedData position; - WineDirect3DStridedData normal; - WineDirect3DStridedData diffuse; - WineDirect3DStridedData specular; - WineDirect3DStridedData texCoords[WINED3DDP_MAXTEXCOORD]; + struct wined3d_strided_element position; + struct wined3d_strided_element normal; + struct wined3d_strided_element diffuse; + struct wined3d_strided_element specular; + struct wined3d_strided_element tex_coords[WINED3DDP_MAXTEXCOORD]; BOOL position_transformed; -} WineDirect3DVertexStridedData; +}; -typedef struct _WINED3DVSHADERCAPS2_0 +struct wined3d_vertex_shader_caps { - DWORD Caps; - INT DynamicFlowControlDepth; - INT NumTemps; - INT StaticFlowControlDepth; -} WINED3DVSHADERCAPS2_0; + DWORD caps; + INT dynamic_flow_control_depth; + INT temp_count; + INT static_flow_control_depth; +}; -typedef struct _WINED3DPSHADERCAPS2_0 +struct wined3d_pixel_shader_caps { - DWORD Caps; - INT DynamicFlowControlDepth; - INT NumTemps; - INT StaticFlowControlDepth; - INT NumInstructionSlots; -} WINED3DPSHADERCAPS2_0; + DWORD caps; + INT dynamic_flow_control_depth; + INT temp_count; + INT static_flow_control_depth; + INT instruction_slot_count; +}; -typedef struct _WINEDDCAPS +struct wined3d_ddraw_caps { - DWORD Caps; - DWORD Caps2; - DWORD CKeyCaps; - DWORD FXCaps; - DWORD FXAlphaCaps; - DWORD PalCaps; - DWORD SVCaps; - DWORD SVBCaps; - DWORD SVBCKeyCaps; - DWORD SVBFXCaps; - DWORD VSBCaps; - DWORD VSBCKeyCaps; - DWORD VSBFXCaps; - DWORD SSBCaps; - DWORD SSBCKeyCaps; - DWORD SSBFXCaps; - DWORD ddsCaps; - DWORD StrideAlign; -} WINEDDCAPS; + DWORD caps; + DWORD caps2; + DWORD color_key_caps; + DWORD fx_caps; + DWORD fx_alpha_caps; + DWORD pal_caps; + DWORD sv_caps; + DWORD svb_caps; + DWORD svb_color_key_caps; + DWORD svb_fx_caps; + DWORD vsb_caps; + DWORD vsb_color_key_caps; + DWORD vsb_fx_caps; + DWORD ssb_caps; + DWORD ssb_color_key_caps; + DWORD ssb_fx_caps; + DWORD dds_caps; + DWORD stride_align; +}; typedef struct _WINED3DCAPS { - WINED3DDEVTYPE DeviceType; + enum wined3d_device_type DeviceType; UINT AdapterOrdinal; DWORD Caps; @@ -1935,8 +1829,8 @@ typedef struct _WINED3DCAPS DWORD DeclTypes; DWORD NumSimultaneousRTs; DWORD StretchRectFilterCaps; - WINED3DVSHADERCAPS2_0 VS20Caps; - WINED3DPSHADERCAPS2_0 PS20Caps; + struct wined3d_vertex_shader_caps VS20Caps; + struct wined3d_pixel_shader_caps PS20Caps; DWORD VertexTextureFilterCaps; DWORD MaxVShaderInstructionsExecuted; DWORD MaxPShaderInstructionsExecuted; @@ -1945,18 +1839,16 @@ typedef struct _WINED3DCAPS DWORD Reserved2; /* Not in the microsoft headers but documented */ DWORD Reserved3; - WINEDDCAPS DirectDrawCaps; + struct wined3d_ddraw_caps ddraw_caps; } WINED3DCAPS; -/* DirectDraw types */ - -typedef struct _WINEDDCOLORKEY +struct wined3d_color_key { - DWORD dwColorSpaceLowValue; /* low boundary of color space that is to + DWORD color_space_low_value; /* low boundary of color space that is to * be treated as Color Key, inclusive */ - DWORD dwColorSpaceHighValue; /* high boundary of color space that is + DWORD color_space_high_value; /* high boundary of color space that is * to be treated as Color Key, inclusive */ -} WINEDDCOLORKEY,*LPWINEDDCOLORKEY; +}; typedef struct _WINEDDBLTFX { @@ -2003,8 +1895,8 @@ typedef struct _WINEDDBLTFX DWORD dwFillPixel; /* pixel val for RGBA or RGBZ */ struct wined3d_surface *lpDDSPattern; /* Surface to use as pattern */ } DUMMYUNIONNAME5; - WINEDDCOLORKEY ddckDestColorkey; /* DestColorkey override */ - WINEDDCOLORKEY ddckSrcColorkey; /* SrcColorkey override */ + struct wined3d_color_key ddckDestColorkey; /* DestColorkey override */ + struct wined3d_color_key ddckSrcColorkey; /* SrcColorkey override */ } WINEDDBLTFX,*LPWINEDDBLTFX; typedef struct _WINEDDOVERLAYFX @@ -2025,8 +1917,8 @@ typedef struct _WINEDDOVERLAYFX DWORD dwAlphaSrcConst; /* Constant to use as alpha channel for src */ struct wined3d_surface *lpDDSAlphaSrc; /* Surface to use as alpha channel for src */ } DUMMYUNIONNAME2; - WINEDDCOLORKEY dckDestColorkey; /* DestColorkey override */ - WINEDDCOLORKEY dckSrcColorkey; /* SrcColorkey override */ + struct wined3d_color_key dckDestColorkey; /* DestColorkey override */ + struct wined3d_color_key dckSrcColorkey; /* SrcColorkey override */ DWORD dwDDFX; /* Overlay FX */ DWORD dwFlags; /* flags */ } WINEDDOVERLAYFX; @@ -2064,7 +1956,6 @@ struct wined3d_parent_ops struct wined3d; struct wined3d_buffer; -struct wined3d_clipper; struct wined3d_device; struct wined3d_palette; struct wined3d_query; @@ -2086,210 +1977,201 @@ struct wined3d_device_parent struct wined3d_device_parent_ops { void (__cdecl *wined3d_device_created)(struct wined3d_device_parent *device_parent, struct wined3d_device *device); + void (__cdecl *mode_changed)(struct wined3d_device_parent *device_parent); HRESULT (__cdecl *create_surface)(struct wined3d_device_parent *device_parent, void *container_parent, - UINT width, UINT height, enum wined3d_format_id format_id, DWORD usage, WINED3DPOOL pool, - UINT level, WINED3DCUBEMAP_FACES face, struct wined3d_surface **surface); + UINT width, UINT height, enum wined3d_format_id format_id, DWORD usage, enum wined3d_pool pool, + UINT level, enum wined3d_cubemap_face face, struct wined3d_surface **surface); HRESULT (__cdecl *create_rendertarget)(struct wined3d_device_parent *device_parent, void *container_parent, - UINT width, UINT height, enum wined3d_format_id format_id, WINED3DMULTISAMPLE_TYPE multisample_type, + UINT width, UINT height, enum wined3d_format_id format_id, enum wined3d_multisample_type multisample_type, DWORD multisample_quality, BOOL lockable, struct wined3d_surface **surface); HRESULT (__cdecl *create_depth_stencil)(struct wined3d_device_parent *device_parent, - UINT width, UINT height, enum wined3d_format_id format_id, WINED3DMULTISAMPLE_TYPE multisample_type, + UINT width, UINT height, enum wined3d_format_id format_id, enum wined3d_multisample_type multisample_type, DWORD multisample_quality, BOOL discard, struct wined3d_surface **surface); HRESULT (__cdecl *create_volume)(struct wined3d_device_parent *device_parent, void *container_parent, - UINT width, UINT height, UINT depth, enum wined3d_format_id format_id, WINED3DPOOL pool, DWORD usage, + UINT width, UINT height, UINT depth, enum wined3d_format_id format_id, enum wined3d_pool pool, DWORD usage, struct wined3d_volume **volume); HRESULT (__cdecl *create_swapchain)(struct wined3d_device_parent *device_parent, - WINED3DPRESENT_PARAMETERS *present_parameters, struct wined3d_swapchain **swapchain); + struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain); }; -typedef HRESULT (__stdcall *D3DCB_ENUMRESOURCES)(struct wined3d_resource *resource, void *pData); +typedef HRESULT (CDECL *wined3d_device_reset_cb)(struct wined3d_resource *resource); void __stdcall wined3d_mutex_lock(void); void __stdcall wined3d_mutex_unlock(void); HRESULT __cdecl wined3d_check_depth_stencil_match(const struct wined3d *wined3d, UINT adapter_idx, - WINED3DDEVTYPE device_type, enum wined3d_format_id adapter_format_id, + enum wined3d_device_type device_type, enum wined3d_format_id adapter_format_id, enum wined3d_format_id render_target_format_id, enum wined3d_format_id depth_stencil_format_id); HRESULT __cdecl wined3d_check_device_format(const struct wined3d *wined3d, UINT adaper_idx, - WINED3DDEVTYPE device_type, enum wined3d_format_id adapter_format_id, DWORD usage, - WINED3DRESOURCETYPE resource_type, enum wined3d_format_id check_format_id, + enum wined3d_device_type device_type, enum wined3d_format_id adapter_format_id, DWORD usage, + enum wined3d_resource_type resource_type, enum wined3d_format_id check_format_id, WINED3DSURFTYPE surface_type); HRESULT __cdecl wined3d_check_device_format_conversion(const struct wined3d *wined3d, UINT adapter_idx, - WINED3DDEVTYPE device_type, enum wined3d_format_id source_format_id, + enum wined3d_device_type device_type, enum wined3d_format_id source_format_id, enum wined3d_format_id target_format_id); HRESULT __cdecl wined3d_check_device_multisample_type(const struct wined3d *wined3d, UINT adapter_idx, - WINED3DDEVTYPE device_type, enum wined3d_format_id surface_format_id, BOOL windowed, - WINED3DMULTISAMPLE_TYPE multisample_type, DWORD *quality_levels); + enum wined3d_device_type device_type, enum wined3d_format_id surface_format_id, BOOL windowed, + enum wined3d_multisample_type multisample_type, DWORD *quality_levels); HRESULT __cdecl wined3d_check_device_type(const struct wined3d *wined3d, UINT adapter_idx, - WINED3DDEVTYPE device_type, enum wined3d_format_id display_format_id, + enum wined3d_device_type device_type, enum wined3d_format_id display_format_id, enum wined3d_format_id backbuffer_format_id, BOOL windowed); -struct wined3d * __cdecl wined3d_create(UINT dxVersion, void *parent); +struct wined3d * __cdecl wined3d_create(UINT dxVersion, DWORD flags, void *parent); ULONG __cdecl wined3d_decref(struct wined3d *wined3d); HRESULT __cdecl wined3d_enum_adapter_modes(const struct wined3d *wined3d, UINT adapter_idx, - enum wined3d_format_id format_id, UINT mode_idx, WINED3DDISPLAYMODE *mode); + enum wined3d_format_id format_id, UINT mode_idx, struct wined3d_display_mode *mode); UINT __cdecl wined3d_get_adapter_count(const struct wined3d *wined3d); HRESULT __cdecl wined3d_get_adapter_display_mode(const struct wined3d *wined3d, UINT adapter_idx, - WINED3DDISPLAYMODE *mode); + struct wined3d_display_mode *mode); HRESULT __cdecl wined3d_get_adapter_identifier(const struct wined3d *wined3d, UINT adapter_idx, - DWORD flags, WINED3DADAPTER_IDENTIFIER *identifier); + DWORD flags, struct wined3d_adapter_identifier *identifier); UINT __cdecl wined3d_get_adapter_mode_count(const struct wined3d *wined3d, UINT adapter_idx, enum wined3d_format_id format_id); HMONITOR __cdecl wined3d_get_adapter_monitor(const struct wined3d *wined3d, UINT adapter_idx); HRESULT __cdecl wined3d_get_device_caps(const struct wined3d *wined3d, UINT adapter_idx, - WINED3DDEVTYPE device_type, WINED3DCAPS *caps); + enum wined3d_device_type device_type, WINED3DCAPS *caps); void * __cdecl wined3d_get_parent(const struct wined3d *wined3d); ULONG __cdecl wined3d_incref(struct wined3d *wined3d); HRESULT __cdecl wined3d_register_software_device(struct wined3d *wined3d, void *init_function); HRESULT __cdecl wined3d_buffer_create(struct wined3d_device *device, struct wined3d_buffer_desc *desc, const void *data, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_buffer **buffer); -HRESULT __cdecl wined3d_buffer_create_ib(struct wined3d_device *device, UINT length, DWORD usage, WINED3DPOOL pool, - void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_buffer **buffer); -HRESULT __cdecl wined3d_buffer_create_vb(struct wined3d_device *device, UINT length, DWORD usage, WINED3DPOOL pool, - void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_buffer **buffer); +HRESULT __cdecl wined3d_buffer_create_ib(struct wined3d_device *device, UINT length, DWORD usage, + enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops, + struct wined3d_buffer **buffer); +HRESULT __cdecl wined3d_buffer_create_vb(struct wined3d_device *device, UINT length, DWORD usage, + enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops, + struct wined3d_buffer **buffer); ULONG __cdecl wined3d_buffer_decref(struct wined3d_buffer *buffer); -HRESULT __cdecl wined3d_buffer_free_private_data(struct wined3d_buffer *buffer, REFGUID guid); void * __cdecl wined3d_buffer_get_parent(const struct wined3d_buffer *buffer); DWORD __cdecl wined3d_buffer_get_priority(const struct wined3d_buffer *buffer); -HRESULT __cdecl wined3d_buffer_get_private_data(const struct wined3d_buffer *buffer, - REFGUID guid, void *data, DWORD *data_size); struct wined3d_resource * __cdecl wined3d_buffer_get_resource(struct wined3d_buffer *buffer); ULONG __cdecl wined3d_buffer_incref(struct wined3d_buffer *buffer); HRESULT __cdecl wined3d_buffer_map(struct wined3d_buffer *buffer, UINT offset, UINT size, BYTE **data, DWORD flags); void __cdecl wined3d_buffer_preload(struct wined3d_buffer *buffer); DWORD __cdecl wined3d_buffer_set_priority(struct wined3d_buffer *buffer, DWORD new_priority); -HRESULT __cdecl wined3d_buffer_set_private_data(struct wined3d_buffer *buffer, - REFGUID guid, const void *data, DWORD data_size, DWORD flags); void __cdecl wined3d_buffer_unmap(struct wined3d_buffer *buffer); -struct wined3d_clipper * __cdecl wined3d_clipper_create(void); -ULONG __cdecl wined3d_clipper_decref(struct wined3d_clipper *clipper); -HRESULT __cdecl wined3d_clipper_get_clip_list(const struct wined3d_clipper *clipper, - const RECT *rect, RGNDATA *clip_list, DWORD *clip_list_size); -HRESULT __cdecl wined3d_clipper_get_window(const struct wined3d_clipper *clipper, HWND *hwnd); -ULONG __cdecl wined3d_clipper_incref(struct wined3d_clipper *clipper); -HRESULT __cdecl wined3d_clipper_is_clip_list_changed(const struct wined3d_clipper *clipper, BOOL *changed); -HRESULT __cdecl wined3d_clipper_set_clip_list(struct wined3d_clipper *clipper, const RGNDATA *clip_list, DWORD flags); -HRESULT __cdecl wined3d_clipper_set_window(struct wined3d_clipper *clipper, DWORD flags, HWND hwnd); - HRESULT __cdecl wined3d_device_acquire_focus_window(struct wined3d_device *device, HWND window); HRESULT __cdecl wined3d_device_begin_scene(struct wined3d_device *device); HRESULT __cdecl wined3d_device_begin_stateblock(struct wined3d_device *device); HRESULT __cdecl wined3d_device_clear(struct wined3d_device *device, DWORD rect_count, const RECT *rects, DWORD flags, - WINED3DCOLOR color, float z, DWORD stencil); + const struct wined3d_color *color, float z, DWORD stencil); void __cdecl wined3d_device_clear_rendertarget_view(struct wined3d_device *device, - struct wined3d_rendertarget_view *rendertarget_view, const WINED3DCOLORVALUE *color); + struct wined3d_rendertarget_view *rendertarget_view, const struct wined3d_color *color); HRESULT __cdecl wined3d_device_color_fill(struct wined3d_device *device, struct wined3d_surface *surface, - const RECT *rect, const WINED3DCOLORVALUE *color); + const RECT *rect, const struct wined3d_color *color); HRESULT __cdecl wined3d_device_create(struct wined3d *wined3d, UINT adapter_idx, - WINED3DDEVTYPE device_type, HWND focus_window, DWORD behaviour_flags, + enum wined3d_device_type device_type, HWND focus_window, DWORD behaviour_flags, BYTE surface_alignment, struct wined3d_device_parent *device_parent, struct wined3d_device **device); ULONG __cdecl wined3d_device_decref(struct wined3d_device *device); HRESULT __cdecl wined3d_device_delete_patch(struct wined3d_device *device, UINT handle); HRESULT __cdecl wined3d_device_draw_indexed_primitive(struct wined3d_device *device, UINT start_idx, UINT index_count); HRESULT __cdecl wined3d_device_draw_indexed_primitive_strided(struct wined3d_device *device, UINT index_count, - const WineDirect3DVertexStridedData *strided_data, UINT vertex_count, const void *index_data, + const struct wined3d_strided_data *strided_data, UINT vertex_count, const void *index_data, enum wined3d_format_id index_data_format_id); HRESULT __cdecl wined3d_device_draw_indexed_primitive_up(struct wined3d_device *device, UINT index_count, const void *index_data, enum wined3d_format_id index_data_format_id, const void *stream_data, UINT stream_stride); HRESULT __cdecl wined3d_device_draw_primitive(struct wined3d_device *device, UINT start_vertex, UINT vertex_count); HRESULT __cdecl wined3d_device_draw_primitive_strided(struct wined3d_device *device, - UINT vertex_count, const WineDirect3DVertexStridedData *strided_data); + UINT vertex_count, const struct wined3d_strided_data *strided_data); HRESULT __cdecl wined3d_device_draw_primitive_up(struct wined3d_device *device, UINT vertex_count, const void *stream_data, UINT stream_stride); HRESULT __cdecl wined3d_device_draw_rect_patch(struct wined3d_device *device, UINT handle, - const float *num_segs, const WINED3DRECTPATCH_INFO *rect_patch_info); + const float *num_segs, const struct wined3d_rect_patch_info *rect_patch_info); HRESULT __cdecl wined3d_device_draw_tri_patch(struct wined3d_device *device, UINT handle, - const float *num_segs, const WINED3DTRIPATCH_INFO *tri_patch_info); + const float *num_segs, const struct wined3d_tri_patch_info *tri_patch_info); HRESULT __cdecl wined3d_device_end_scene(struct wined3d_device *device); HRESULT __cdecl wined3d_device_end_stateblock(struct wined3d_device *device, struct wined3d_stateblock **stateblock); -HRESULT __cdecl wined3d_device_enum_resources(struct wined3d_device *device, D3DCB_ENUMRESOURCES callback, void *data); -HRESULT __cdecl wined3d_device_evict_managed_resources(struct wined3d_device *device); -UINT __cdecl wined3d_device_get_available_texture_mem(struct wined3d_device *device); -HRESULT __cdecl wined3d_device_get_back_buffer(struct wined3d_device *device, UINT swapchain_idx, - UINT backbuffer_idx, WINED3DBACKBUFFER_TYPE backbuffer_type, struct wined3d_surface **backbuffer); -INT __cdecl wined3d_device_get_base_vertex_index(struct wined3d_device *device); -HRESULT __cdecl wined3d_device_get_clip_plane(struct wined3d_device *device, UINT plane_idx, float *plane); -HRESULT __cdecl wined3d_device_get_clip_status(struct wined3d_device *device, WINED3DCLIPSTATUS *clip_status); -HRESULT __cdecl wined3d_device_get_creation_parameters(struct wined3d_device *device, - WINED3DDEVICE_CREATION_PARAMETERS *creation_parameters); -HRESULT __cdecl wined3d_device_get_current_texture_palette(struct wined3d_device *device, UINT *palette_idx); -HRESULT __cdecl wined3d_device_get_depth_stencil(struct wined3d_device *device, +void __cdecl wined3d_device_evict_managed_resources(struct wined3d_device *device); +UINT __cdecl wined3d_device_get_available_texture_mem(const struct wined3d_device *device); +HRESULT __cdecl wined3d_device_get_back_buffer(const struct wined3d_device *device, UINT swapchain_idx, + UINT backbuffer_idx, enum wined3d_backbuffer_type backbuffer_type, struct wined3d_surface **backbuffer); +INT __cdecl wined3d_device_get_base_vertex_index(const struct wined3d_device *device); +HRESULT __cdecl wined3d_device_get_clip_plane(const struct wined3d_device *device, UINT plane_idx, float *plane); +HRESULT __cdecl wined3d_device_get_clip_status(const struct wined3d_device *device, + struct wined3d_clip_status *clip_status); +HRESULT __cdecl wined3d_device_get_creation_parameters(const struct wined3d_device *device, + struct wined3d_device_creation_parameters *creation_parameters); +HRESULT __cdecl wined3d_device_get_depth_stencil(const struct wined3d_device *device, struct wined3d_surface **depth_stencil); -HRESULT __cdecl wined3d_device_get_device_caps(struct wined3d_device *device, WINED3DCAPS *caps); -HRESULT __cdecl wined3d_device_get_display_mode(struct wined3d_device *device, - UINT swapchain_idx, WINED3DDISPLAYMODE *mode); -HRESULT __cdecl wined3d_device_get_front_buffer_data(struct wined3d_device *device, +HRESULT __cdecl wined3d_device_get_device_caps(const struct wined3d_device *device, WINED3DCAPS *caps); +HRESULT __cdecl wined3d_device_get_display_mode(const struct wined3d_device *device, + UINT swapchain_idx, struct wined3d_display_mode *mode); +HRESULT __cdecl wined3d_device_get_front_buffer_data(const struct wined3d_device *device, UINT swapchain_idx, struct wined3d_surface *dst_surface); -void __cdecl wined3d_device_get_gamma_ramp(struct wined3d_device *device, UINT swapchain_idx, WINED3DGAMMARAMP *ramp); -HRESULT __cdecl wined3d_device_get_index_buffer(struct wined3d_device *device, struct wined3d_buffer **index_buffer); -HRESULT __cdecl wined3d_device_get_light(struct wined3d_device *device, UINT light_idx, WINED3DLIGHT *light); -HRESULT __cdecl wined3d_device_get_light_enable(struct wined3d_device *device, UINT light_idx, BOOL *enable); -HRESULT __cdecl wined3d_device_get_material(struct wined3d_device *device, WINED3DMATERIAL *material); -float __cdecl wined3d_device_get_npatch_mode(struct wined3d_device *device); -HRESULT __cdecl wined3d_device_get_palette_entries(struct wined3d_device *device, - UINT palette_idx, PALETTEENTRY *entries); -struct wined3d_shader * __cdecl wined3d_device_get_pixel_shader(struct wined3d_device *device); -void __cdecl wined3d_device_get_primitive_type(struct wined3d_device *device, WINED3DPRIMITIVETYPE *primitive_topology); -HRESULT __cdecl wined3d_device_get_ps_consts_b(struct wined3d_device *device, +void __cdecl wined3d_device_get_gamma_ramp(const struct wined3d_device *device, + UINT swapchain_idx, struct wined3d_gamma_ramp *ramp); +HRESULT __cdecl wined3d_device_get_index_buffer(const struct wined3d_device *device, + struct wined3d_buffer **index_buffer); +HRESULT __cdecl wined3d_device_get_light(const struct wined3d_device *device, + UINT light_idx, struct wined3d_light *light); +HRESULT __cdecl wined3d_device_get_light_enable(const struct wined3d_device *device, UINT light_idx, BOOL *enable); +HRESULT __cdecl wined3d_device_get_material(const struct wined3d_device *device, struct wined3d_material *material); +float __cdecl wined3d_device_get_npatch_mode(const struct wined3d_device *device); +struct wined3d_shader * __cdecl wined3d_device_get_pixel_shader(const struct wined3d_device *device); +void __cdecl wined3d_device_get_primitive_type(const struct wined3d_device *device, + enum wined3d_primitive_type *primitive_topology); +HRESULT __cdecl wined3d_device_get_ps_consts_b(const struct wined3d_device *device, UINT start_register, BOOL *constants, UINT bool_count); -HRESULT __cdecl wined3d_device_get_ps_consts_f(struct wined3d_device *device, +HRESULT __cdecl wined3d_device_get_ps_consts_f(const struct wined3d_device *device, UINT start_register, float *constants, UINT vector4f_count); -HRESULT __cdecl wined3d_device_get_ps_consts_i(struct wined3d_device *device, +HRESULT __cdecl wined3d_device_get_ps_consts_i(const struct wined3d_device *device, UINT start_register, int *constants, UINT vector4i_count); -HRESULT __cdecl wined3d_device_get_raster_status(struct wined3d_device *device, - UINT swapchain_idx, WINED3DRASTER_STATUS *raster_status); -HRESULT __cdecl wined3d_device_get_render_state(struct wined3d_device *device, - WINED3DRENDERSTATETYPE state, DWORD *value); -HRESULT __cdecl wined3d_device_get_render_target(struct wined3d_device *device, +HRESULT __cdecl wined3d_device_get_raster_status(const struct wined3d_device *device, + UINT swapchain_idx, struct wined3d_raster_status *raster_status); +HRESULT __cdecl wined3d_device_get_render_state(const struct wined3d_device *device, + enum wined3d_render_state state, DWORD *value); +HRESULT __cdecl wined3d_device_get_render_target(const struct wined3d_device *device, UINT render_target_idx, struct wined3d_surface **render_target); -HRESULT __cdecl wined3d_device_get_sampler_state(struct wined3d_device *device, - UINT sampler_idx, WINED3DSAMPLERSTATETYPE state, DWORD *value); -HRESULT __cdecl wined3d_device_get_scissor_rect(struct wined3d_device *device, RECT *rect); -BOOL __cdecl wined3d_device_get_software_vertex_processing(struct wined3d_device *device); -HRESULT __cdecl wined3d_device_get_stream_source(struct wined3d_device *device, +HRESULT __cdecl wined3d_device_get_sampler_state(const struct wined3d_device *device, + UINT sampler_idx, enum wined3d_sampler_state state, DWORD *value); +HRESULT __cdecl wined3d_device_get_scissor_rect(const struct wined3d_device *device, RECT *rect); +BOOL __cdecl wined3d_device_get_software_vertex_processing(const struct wined3d_device *device); +HRESULT __cdecl wined3d_device_get_stream_source(const struct wined3d_device *device, UINT stream_idx, struct wined3d_buffer **buffer, UINT *offset, UINT *stride); -HRESULT __cdecl wined3d_device_get_stream_source_freq(struct wined3d_device *device, UINT stream_idx, UINT *divider); -HRESULT __cdecl wined3d_device_get_surface_from_dc(struct wined3d_device *device, +HRESULT __cdecl wined3d_device_get_stream_source_freq(const struct wined3d_device *device, + UINT stream_idx, UINT *divider); +HRESULT __cdecl wined3d_device_get_surface_from_dc(const struct wined3d_device *device, HDC dc, struct wined3d_surface **surface); -HRESULT __cdecl wined3d_device_get_swapchain(struct wined3d_device *device, +HRESULT __cdecl wined3d_device_get_swapchain(const struct wined3d_device *device, UINT swapchain_idx, struct wined3d_swapchain **swapchain); -UINT __cdecl wined3d_device_get_swapchain_count(struct wined3d_device *device); -HRESULT __cdecl wined3d_device_get_texture(struct wined3d_device *device, +UINT __cdecl wined3d_device_get_swapchain_count(const struct wined3d_device *device); +HRESULT __cdecl wined3d_device_get_texture(const struct wined3d_device *device, UINT stage, struct wined3d_texture **texture); -HRESULT __cdecl wined3d_device_get_texture_stage_state(struct wined3d_device *device, - UINT stage, WINED3DTEXTURESTAGESTATETYPE state, DWORD *value); -HRESULT __cdecl wined3d_device_get_transform(struct wined3d_device *device, - WINED3DTRANSFORMSTATETYPE state, WINED3DMATRIX *matrix); -HRESULT __cdecl wined3d_device_get_vertex_declaration(struct wined3d_device *device, +HRESULT __cdecl wined3d_device_get_texture_stage_state(const struct wined3d_device *device, + UINT stage, enum wined3d_texture_stage_state state, DWORD *value); +HRESULT __cdecl wined3d_device_get_transform(const struct wined3d_device *device, + enum wined3d_transform_state state, struct wined3d_matrix *matrix); +HRESULT __cdecl wined3d_device_get_vertex_declaration(const struct wined3d_device *device, struct wined3d_vertex_declaration **declaration); -struct wined3d_shader * __cdecl wined3d_device_get_vertex_shader(struct wined3d_device *device); -HRESULT __cdecl wined3d_device_get_viewport(struct wined3d_device *device, WINED3DVIEWPORT *viewport); -HRESULT __cdecl wined3d_device_get_vs_consts_b(struct wined3d_device *device, +struct wined3d_shader * __cdecl wined3d_device_get_vertex_shader(const struct wined3d_device *device); +HRESULT __cdecl wined3d_device_get_viewport(const struct wined3d_device *device, struct wined3d_viewport *viewport); +HRESULT __cdecl wined3d_device_get_vs_consts_b(const struct wined3d_device *device, UINT start_register, BOOL *constants, UINT bool_count); -HRESULT __cdecl wined3d_device_get_vs_consts_f(struct wined3d_device *device, +HRESULT __cdecl wined3d_device_get_vs_consts_f(const struct wined3d_device *device, UINT start_register, float *constants, UINT vector4f_count); -HRESULT __cdecl wined3d_device_get_vs_consts_i(struct wined3d_device *device, +HRESULT __cdecl wined3d_device_get_vs_consts_i(const struct wined3d_device *device, UINT start_register, int *constants, UINT vector4i_count); -HRESULT __cdecl wined3d_device_get_wined3d(struct wined3d_device *device, struct wined3d **d3d); +HRESULT __cdecl wined3d_device_get_wined3d(const struct wined3d_device *device, struct wined3d **wined3d); ULONG __cdecl wined3d_device_incref(struct wined3d_device *device); -HRESULT __cdecl wined3d_device_init_3d(struct wined3d_device *device, WINED3DPRESENT_PARAMETERS *present_parameters); -HRESULT __cdecl wined3d_device_init_gdi(struct wined3d_device *device, WINED3DPRESENT_PARAMETERS *present_parameters); +HRESULT __cdecl wined3d_device_init_3d(struct wined3d_device *device, struct wined3d_swapchain_desc *swapchain_desc); +HRESULT __cdecl wined3d_device_init_gdi(struct wined3d_device *device, struct wined3d_swapchain_desc *swapchain_desc); HRESULT __cdecl wined3d_device_multiply_transform(struct wined3d_device *device, - WINED3DTRANSFORMSTATETYPE state, const WINED3DMATRIX *matrix); -HRESULT __cdecl wined3d_device_present(struct wined3d_device *device, const RECT *src_rect, + enum wined3d_transform_state state, const struct wined3d_matrix *matrix); +HRESULT __cdecl wined3d_device_present(const struct wined3d_device *device, const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override, const RGNDATA *dirty_region); HRESULT __cdecl wined3d_device_process_vertices(struct wined3d_device *device, UINT src_start_idx, UINT dst_idx, UINT vertex_count, struct wined3d_buffer *dst_buffer, - struct wined3d_vertex_declaration *declaration, DWORD flags, DWORD dst_fvf); + const struct wined3d_vertex_declaration *declaration, DWORD flags, DWORD dst_fvf); void __cdecl wined3d_device_release_focus_window(struct wined3d_device *device); -HRESULT __cdecl wined3d_device_reset(struct wined3d_device *device, WINED3DPRESENT_PARAMETERS *present_parameters); +HRESULT __cdecl wined3d_device_reset(struct wined3d_device *device, + const struct wined3d_swapchain_desc *swapchain_desc, wined3d_device_reset_cb callback); void __cdecl wined3d_device_restore_fullscreen_window(struct wined3d_device *device, HWND window); HRESULT __cdecl wined3d_device_set_base_vertex_index(struct wined3d_device *device, INT base_index); HRESULT __cdecl wined3d_device_set_clip_plane(struct wined3d_device *device, UINT plane_idx, const float *plane); -HRESULT __cdecl wined3d_device_set_clip_status(struct wined3d_device *device, const WINED3DCLIPSTATUS *clip_status); -HRESULT __cdecl wined3d_device_set_current_texture_palette(struct wined3d_device *device, UINT palette_idx); +HRESULT __cdecl wined3d_device_set_clip_status(struct wined3d_device *device, + const struct wined3d_clip_status *clip_status); void __cdecl wined3d_device_set_cursor_position(struct wined3d_device *device, int x_screen_space, int y_screen_space, DWORD flags); HRESULT __cdecl wined3d_device_set_cursor_properties(struct wined3d_device *device, @@ -2297,20 +2179,20 @@ HRESULT __cdecl wined3d_device_set_cursor_properties(struct wined3d_device *devi HRESULT __cdecl wined3d_device_set_depth_stencil(struct wined3d_device *device, struct wined3d_surface *depth_stencil); HRESULT __cdecl wined3d_device_set_dialog_box_mode(struct wined3d_device *device, BOOL enable_dialogs); HRESULT __cdecl wined3d_device_set_display_mode(struct wined3d_device *device, - UINT swapchain_idx, const WINED3DDISPLAYMODE *mode); -void __cdecl wined3d_device_set_gamma_ramp(struct wined3d_device *device, - UINT swapchain_idx, DWORD flags, const WINED3DGAMMARAMP *ramp); + UINT swapchain_idx, const struct wined3d_display_mode *mode); +void __cdecl wined3d_device_set_gamma_ramp(const struct wined3d_device *device, + UINT swapchain_idx, DWORD flags, const struct wined3d_gamma_ramp *ramp); HRESULT __cdecl wined3d_device_set_index_buffer(struct wined3d_device *device, struct wined3d_buffer *index_buffer, enum wined3d_format_id format_id); -HRESULT __cdecl wined3d_device_set_light(struct wined3d_device *device, UINT light_idx, const WINED3DLIGHT *light); +HRESULT __cdecl wined3d_device_set_light(struct wined3d_device *device, + UINT light_idx, const struct wined3d_light *light); HRESULT __cdecl wined3d_device_set_light_enable(struct wined3d_device *device, UINT light_idx, BOOL enable); -HRESULT __cdecl wined3d_device_set_material(struct wined3d_device *device, const WINED3DMATERIAL *material); +HRESULT __cdecl wined3d_device_set_material(struct wined3d_device *device, const struct wined3d_material *material); void __cdecl wined3d_device_set_multithreaded(struct wined3d_device *device); HRESULT __cdecl wined3d_device_set_npatch_mode(struct wined3d_device *device, float segments); -HRESULT __cdecl wined3d_device_set_palette_entries(struct wined3d_device *device, - UINT palette_idx, const PALETTEENTRY *entries); HRESULT __cdecl wined3d_device_set_pixel_shader(struct wined3d_device *device, struct wined3d_shader *shader); -void __cdecl wined3d_device_set_primitive_type(struct wined3d_device *device, WINED3DPRIMITIVETYPE primitive_topology); +void __cdecl wined3d_device_set_primitive_type(struct wined3d_device *device, + enum wined3d_primitive_type primitive_topology); HRESULT __cdecl wined3d_device_set_ps_consts_b(struct wined3d_device *device, UINT start_register, const BOOL *constants, UINT bool_count); HRESULT __cdecl wined3d_device_set_ps_consts_f(struct wined3d_device *device, @@ -2318,11 +2200,11 @@ HRESULT __cdecl wined3d_device_set_ps_consts_f(struct wined3d_device *device, HRESULT __cdecl wined3d_device_set_ps_consts_i(struct wined3d_device *device, UINT start_register, const int *constants, UINT vector4i_count); HRESULT __cdecl wined3d_device_set_render_state(struct wined3d_device *device, - WINED3DRENDERSTATETYPE state, DWORD value); + enum wined3d_render_state state, DWORD value); HRESULT __cdecl wined3d_device_set_render_target(struct wined3d_device *device, UINT render_target_idx, struct wined3d_surface *render_target, BOOL set_viewport); HRESULT __cdecl wined3d_device_set_sampler_state(struct wined3d_device *device, - UINT sampler_idx, WINED3DSAMPLERSTATETYPE state, DWORD value); + UINT sampler_idx, enum wined3d_sampler_state state, DWORD value); HRESULT __cdecl wined3d_device_set_scissor_rect(struct wined3d_device *device, const RECT *rect); HRESULT __cdecl wined3d_device_set_software_vertex_processing(struct wined3d_device *device, BOOL software); HRESULT __cdecl wined3d_device_set_stream_source(struct wined3d_device *device, @@ -2330,13 +2212,13 @@ HRESULT __cdecl wined3d_device_set_stream_source(struct wined3d_device *device, HRESULT __cdecl wined3d_device_set_stream_source_freq(struct wined3d_device *device, UINT stream_idx, UINT divider); HRESULT __cdecl wined3d_device_set_texture(struct wined3d_device *device, UINT stage, struct wined3d_texture *texture); HRESULT __cdecl wined3d_device_set_texture_stage_state(struct wined3d_device *device, - UINT stage, WINED3DTEXTURESTAGESTATETYPE state, DWORD value); + UINT stage, enum wined3d_texture_stage_state state, DWORD value); HRESULT __cdecl wined3d_device_set_transform(struct wined3d_device *device, - WINED3DTRANSFORMSTATETYPE state, const WINED3DMATRIX *matrix); + enum wined3d_transform_state state, const struct wined3d_matrix *matrix); HRESULT __cdecl wined3d_device_set_vertex_declaration(struct wined3d_device *device, struct wined3d_vertex_declaration *declaration); HRESULT __cdecl wined3d_device_set_vertex_shader(struct wined3d_device *device, struct wined3d_shader *shader); -HRESULT __cdecl wined3d_device_set_viewport(struct wined3d_device *device, const WINED3DVIEWPORT *viewport); +HRESULT __cdecl wined3d_device_set_viewport(struct wined3d_device *device, const struct wined3d_viewport *viewport); HRESULT __cdecl wined3d_device_set_vs_consts_b(struct wined3d_device *device, UINT start_register, const BOOL *constants, UINT bool_count); HRESULT __cdecl wined3d_device_set_vs_consts_f(struct wined3d_device *device, @@ -2351,7 +2233,7 @@ HRESULT __cdecl wined3d_device_update_surface(struct wined3d_device *device, str const RECT *src_rect, struct wined3d_surface *dst_surface, const POINT *dst_point); HRESULT __cdecl wined3d_device_update_texture(struct wined3d_device *device, struct wined3d_texture *src_texture, struct wined3d_texture *dst_texture); -HRESULT __cdecl wined3d_device_validate_device(struct wined3d_device *device, DWORD *num_passes); +HRESULT __cdecl wined3d_device_validate_device(const struct wined3d_device *device, DWORD *num_passes); HRESULT __cdecl wined3d_palette_create(struct wined3d_device *device, DWORD flags, const PALETTEENTRY *entries, void *parent, struct wined3d_palette **palette); @@ -2365,17 +2247,22 @@ HRESULT __cdecl wined3d_palette_set_entries(struct wined3d_palette *palette, DWORD flags, DWORD start, DWORD count, const PALETTEENTRY *entries); HRESULT __cdecl wined3d_query_create(struct wined3d_device *device, - WINED3DQUERYTYPE type, struct wined3d_query **query); + enum wined3d_query_type type, struct wined3d_query **query); ULONG __cdecl wined3d_query_decref(struct wined3d_query *query); HRESULT __cdecl wined3d_query_get_data(struct wined3d_query *query, void *data, UINT data_size, DWORD flags); UINT __cdecl wined3d_query_get_data_size(const struct wined3d_query *query); -WINED3DQUERYTYPE __cdecl wined3d_query_get_type(const struct wined3d_query *query); +enum wined3d_query_type __cdecl wined3d_query_get_type(const struct wined3d_query *query); ULONG __cdecl wined3d_query_incref(struct wined3d_query *query); HRESULT __cdecl wined3d_query_issue(struct wined3d_query *query, DWORD flags); +HRESULT __cdecl wined3d_resource_free_private_data(struct wined3d_resource *resource, REFGUID guid); void __cdecl wined3d_resource_get_desc(const struct wined3d_resource *resource, struct wined3d_resource_desc *desc); void * __cdecl wined3d_resource_get_parent(const struct wined3d_resource *resource); +HRESULT __cdecl wined3d_resource_get_private_data(const struct wined3d_resource *resource, + REFGUID guid, void *data, DWORD *data_size); +HRESULT __cdecl wined3d_resource_set_private_data(struct wined3d_resource *resource, + REFGUID guid, const void *data, DWORD data_size, DWORD flags); HRESULT __cdecl wined3d_rendertarget_view_create(struct wined3d_resource *resource, void *parent, struct wined3d_rendertarget_view **rendertarget_view); @@ -2386,13 +2273,13 @@ ULONG __cdecl wined3d_rendertarget_view_incref(struct wined3d_rendertarget_view HRESULT __cdecl wined3d_shader_create_gs(struct wined3d_device *device, const DWORD *byte_code, const struct wined3d_shader_signature *output_signature, void *parent, - const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader); + const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader, unsigned int max_version); HRESULT __cdecl wined3d_shader_create_ps(struct wined3d_device *device, const DWORD *byte_code, const struct wined3d_shader_signature *output_signature, void *parent, - const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader); + const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader, unsigned int max_version); HRESULT __cdecl wined3d_shader_create_vs(struct wined3d_device *device, const DWORD *byte_code, const struct wined3d_shader_signature *output_signature, void *parent, - const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader); + const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader, unsigned int max_version); ULONG __cdecl wined3d_shader_decref(struct wined3d_shader *shader); HRESULT __cdecl wined3d_shader_get_byte_code(const struct wined3d_shader *shader, void *byte_code, UINT *byte_code_size); @@ -2404,118 +2291,108 @@ HRESULT __cdecl wined3d_shader_set_local_constants_float(struct wined3d_shader * HRESULT __cdecl wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock); HRESULT __cdecl wined3d_stateblock_capture(struct wined3d_stateblock *stateblock); HRESULT __cdecl wined3d_stateblock_create(struct wined3d_device *device, - WINED3DSTATEBLOCKTYPE type, struct wined3d_stateblock **stateblock); + enum wined3d_stateblock_type type, struct wined3d_stateblock **stateblock); ULONG __cdecl wined3d_stateblock_decref(struct wined3d_stateblock *stateblock); ULONG __cdecl wined3d_stateblock_incref(struct wined3d_stateblock *stateblock); HRESULT __cdecl wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst_rect, struct wined3d_surface *src_surface, const RECT *src_rect, DWORD flags, - const WINEDDBLTFX *blt_fx, WINED3DTEXTUREFILTERTYPE filter); -HRESULT __cdecl wined3d_surface_bltfast(struct wined3d_surface *dst_surface, DWORD dst_x, DWORD dst_y, - struct wined3d_surface *src_surface, const RECT *src_rect, DWORD trans); + const WINEDDBLTFX *blt_fx, enum wined3d_texture_filter_type filter); HRESULT __cdecl wined3d_surface_create(struct wined3d_device *device, UINT width, UINT height, - enum wined3d_format_id format_id, BOOL lockable, BOOL discard, UINT level, DWORD usage, WINED3DPOOL pool, - WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, WINED3DSURFTYPE surface_type, - void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_surface **surface); + enum wined3d_format_id format_id, UINT level, DWORD usage, enum wined3d_pool pool, + enum wined3d_multisample_type multisample_type, DWORD multisample_quality, WINED3DSURFTYPE surface_type, + DWORD flags, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_surface **surface); ULONG __cdecl wined3d_surface_decref(struct wined3d_surface *surface); HRESULT __cdecl wined3d_surface_flip(struct wined3d_surface *surface, struct wined3d_surface *override, DWORD flags); -HRESULT __cdecl wined3d_surface_free_private_data(struct wined3d_surface *surface, REFGUID guid); HRESULT __cdecl wined3d_surface_get_blt_status(const struct wined3d_surface *surface, DWORD flags); -struct wined3d_clipper * __cdecl wined3d_surface_get_clipper(const struct wined3d_surface *surface); HRESULT __cdecl wined3d_surface_get_flip_status(const struct wined3d_surface *surface, DWORD flags); HRESULT __cdecl wined3d_surface_get_overlay_position(const struct wined3d_surface *surface, LONG *x, LONG *y); struct wined3d_palette * __cdecl wined3d_surface_get_palette(const struct wined3d_surface *surface); void * __cdecl wined3d_surface_get_parent(const struct wined3d_surface *surface); DWORD __cdecl wined3d_surface_get_pitch(const struct wined3d_surface *surface); DWORD __cdecl wined3d_surface_get_priority(const struct wined3d_surface *surface); -HRESULT __cdecl wined3d_surface_get_private_data(const struct wined3d_surface *surface, - REFGUID guid, void *data, DWORD *data_size); +HRESULT __cdecl wined3d_surface_get_render_target_data(struct wined3d_surface *surface, + struct wined3d_surface *render_target); struct wined3d_resource * __cdecl wined3d_surface_get_resource(struct wined3d_surface *surface); HRESULT __cdecl wined3d_surface_getdc(struct wined3d_surface *surface, HDC *dc); ULONG __cdecl wined3d_surface_incref(struct wined3d_surface *surface); HRESULT __cdecl wined3d_surface_is_lost(const struct wined3d_surface *surface); HRESULT __cdecl wined3d_surface_map(struct wined3d_surface *surface, - WINED3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags); + struct wined3d_mapped_rect *mapped_rect, const RECT *rect, DWORD flags); void __cdecl wined3d_surface_preload(struct wined3d_surface *surface); HRESULT __cdecl wined3d_surface_releasedc(struct wined3d_surface *surface, HDC dc); HRESULT __cdecl wined3d_surface_restore(struct wined3d_surface *surface); -HRESULT __cdecl wined3d_surface_set_clipper(struct wined3d_surface *surface, struct wined3d_clipper *clipper); HRESULT __cdecl wined3d_surface_set_color_key(struct wined3d_surface *surface, - DWORD flags, const WINEDDCOLORKEY *color_key); -HRESULT __cdecl wined3d_surface_set_format(struct wined3d_surface *surface, enum wined3d_format_id format_id); + DWORD flags, const struct wined3d_color_key *color_key); HRESULT __cdecl wined3d_surface_set_mem(struct wined3d_surface *surface, void *mem); HRESULT __cdecl wined3d_surface_set_overlay_position(struct wined3d_surface *surface, LONG x, LONG y); HRESULT __cdecl wined3d_surface_set_palette(struct wined3d_surface *surface, struct wined3d_palette *palette); DWORD __cdecl wined3d_surface_set_priority(struct wined3d_surface *surface, DWORD new_priority); -HRESULT __cdecl wined3d_surface_set_private_data(struct wined3d_surface *surface, - REFGUID guid, const void *data, DWORD data_size, DWORD flags); HRESULT __cdecl wined3d_surface_unmap(struct wined3d_surface *surface); +HRESULT __cdecl wined3d_surface_update_desc(struct wined3d_surface *surface, + UINT width, UINT height, enum wined3d_format_id format_id, + enum wined3d_multisample_type multisample_type, UINT multisample_quality); HRESULT __cdecl wined3d_surface_update_overlay(struct wined3d_surface *surface, const RECT *src_rect, struct wined3d_surface *dst_surface, const RECT *dst_rect, DWORD flags, const WINEDDOVERLAYFX *fx); HRESULT __cdecl wined3d_surface_update_overlay_z_order(struct wined3d_surface *surface, DWORD flags, struct wined3d_surface *ref); HRESULT __cdecl wined3d_swapchain_create(struct wined3d_device *device, - WINED3DPRESENT_PARAMETERS *present_parameters, WINED3DSURFTYPE surface_type, void *parent, + struct wined3d_swapchain_desc *desc, WINED3DSURFTYPE surface_type, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_swapchain **swapchain); ULONG __cdecl wined3d_swapchain_decref(struct wined3d_swapchain *swapchain); HRESULT __cdecl wined3d_swapchain_get_back_buffer(const struct wined3d_swapchain *swapchain, - UINT backbuffer_idx, WINED3DBACKBUFFER_TYPE backbuffer_type, struct wined3d_surface **backbuffer); + UINT backbuffer_idx, enum wined3d_backbuffer_type backbuffer_type, struct wined3d_surface **backbuffer); struct wined3d_device * __cdecl wined3d_swapchain_get_device(const struct wined3d_swapchain *swapchain); HRESULT __cdecl wined3d_swapchain_get_display_mode(const struct wined3d_swapchain *swapchain, - WINED3DDISPLAYMODE *mode); + struct wined3d_display_mode *mode); HRESULT __cdecl wined3d_swapchain_get_front_buffer_data(const struct wined3d_swapchain *swapchain, struct wined3d_surface *dst_surface); HRESULT __cdecl wined3d_swapchain_get_gamma_ramp(const struct wined3d_swapchain *swapchain, - WINED3DGAMMARAMP *ramp); + struct wined3d_gamma_ramp *ramp); void * __cdecl wined3d_swapchain_get_parent(const struct wined3d_swapchain *swapchain); -HRESULT __cdecl wined3d_swapchain_get_present_parameters(const struct wined3d_swapchain *swapchain, - WINED3DPRESENT_PARAMETERS *present_parameters); +HRESULT __cdecl wined3d_swapchain_get_desc(const struct wined3d_swapchain *swapchain, + struct wined3d_swapchain_desc *desc); HRESULT __cdecl wined3d_swapchain_get_raster_status(const struct wined3d_swapchain *swapchain, - WINED3DRASTER_STATUS *raster_status); + struct wined3d_raster_status *raster_status); ULONG __cdecl wined3d_swapchain_incref(struct wined3d_swapchain *swapchain); HRESULT __cdecl wined3d_swapchain_present(struct wined3d_swapchain *swapchain, const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override, const RGNDATA *dirty_region, DWORD flags); HRESULT __cdecl wined3d_swapchain_set_gamma_ramp(const struct wined3d_swapchain *swapchain, - DWORD flags, const WINED3DGAMMARAMP *ramp); + DWORD flags, const struct wined3d_gamma_ramp *ramp); HRESULT __cdecl wined3d_swapchain_set_window(struct wined3d_swapchain *swapchain, HWND window); HRESULT __cdecl wined3d_texture_add_dirty_region(struct wined3d_texture *texture, - UINT layer, const WINED3DBOX *dirty_region); + UINT layer, const struct wined3d_box *dirty_region); HRESULT __cdecl wined3d_texture_create_2d(struct wined3d_device *device, UINT width, UINT height, - UINT level_count, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool, void *parent, + UINT level_count, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture); HRESULT __cdecl wined3d_texture_create_3d(struct wined3d_device *device, UINT width, UINT height, UINT depth, - UINT level_count, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool, void *parent, + UINT level_count, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture); HRESULT __cdecl wined3d_texture_create_cube(struct wined3d_device *device, UINT edge_length, - UINT level_count, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool, void *parent, + UINT level_count, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture); ULONG __cdecl wined3d_texture_decref(struct wined3d_texture *texture); -HRESULT __cdecl wined3d_texture_free_private_data(struct wined3d_texture *texture, REFGUID guid); void __cdecl wined3d_texture_generate_mipmaps(struct wined3d_texture *texture); -WINED3DTEXTUREFILTERTYPE __cdecl wined3d_texture_get_autogen_filter_type(const struct wined3d_texture *texture); +enum wined3d_texture_filter_type __cdecl wined3d_texture_get_autogen_filter_type(const struct wined3d_texture *texture); DWORD __cdecl wined3d_texture_get_level_count(const struct wined3d_texture *texture); DWORD __cdecl wined3d_texture_get_lod(const struct wined3d_texture *texture); void * __cdecl wined3d_texture_get_parent(const struct wined3d_texture *texture); DWORD __cdecl wined3d_texture_get_priority(const struct wined3d_texture *texture); -HRESULT __cdecl wined3d_texture_get_private_data(const struct wined3d_texture *texture, - REFGUID guid, void *data, DWORD *data_size); +struct wined3d_resource * __cdecl wined3d_texture_get_resource(struct wined3d_texture *texture); struct wined3d_resource * __cdecl wined3d_texture_get_sub_resource(struct wined3d_texture *texture, UINT sub_resource_idx); -WINED3DRESOURCETYPE __cdecl wined3d_texture_get_type(const struct wined3d_texture *texture); ULONG __cdecl wined3d_texture_incref(struct wined3d_texture *texture); void __cdecl wined3d_texture_preload(struct wined3d_texture *texture); HRESULT __cdecl wined3d_texture_set_autogen_filter_type(struct wined3d_texture *texture, - WINED3DTEXTUREFILTERTYPE filter_type); + enum wined3d_texture_filter_type filter_type); DWORD __cdecl wined3d_texture_set_lod(struct wined3d_texture *texture, DWORD lod); DWORD __cdecl wined3d_texture_set_priority(struct wined3d_texture *texture, DWORD priority); -HRESULT __cdecl wined3d_texture_set_private_data(struct wined3d_texture *texture, - REFGUID guid, const void *data, DWORD data_size, DWORD flags); HRESULT __cdecl wined3d_vertex_declaration_create(struct wined3d_device *device, - const WINED3DVERTEXELEMENT *elements, UINT element_count, void *parent, + const struct wined3d_vertex_element *elements, UINT element_count, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_vertex_declaration **declaration); HRESULT __cdecl wined3d_vertex_declaration_create_from_fvf(struct wined3d_device *device, DWORD fvf, void *parent, const struct wined3d_parent_ops *parent_ops, @@ -2525,23 +2402,18 @@ void * __cdecl wined3d_vertex_declaration_get_parent(const struct wined3d_vertex ULONG __cdecl wined3d_vertex_declaration_incref(struct wined3d_vertex_declaration *declaration); HRESULT __cdecl wined3d_volume_create(struct wined3d_device *device, UINT width, UINT height, UINT depth, - DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool, void *parent, + DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_volume **volume); ULONG __cdecl wined3d_volume_decref(struct wined3d_volume *volume); -HRESULT __cdecl wined3d_volume_free_private_data(struct wined3d_volume *volume, REFGUID guid); struct wined3d_volume * __cdecl wined3d_volume_from_resource(struct wined3d_resource *resource); void * __cdecl wined3d_volume_get_parent(const struct wined3d_volume *volume); DWORD __cdecl wined3d_volume_get_priority(const struct wined3d_volume *volume); -HRESULT __cdecl wined3d_volume_get_private_data(const struct wined3d_volume *volume, - REFGUID guid, void *data, DWORD *data_size); struct wined3d_resource * __cdecl wined3d_volume_get_resource(struct wined3d_volume *volume); ULONG __cdecl wined3d_volume_incref(struct wined3d_volume *volume); HRESULT __cdecl wined3d_volume_map(struct wined3d_volume *volume, - WINED3DLOCKED_BOX *locked_box, const WINED3DBOX *box, DWORD flags); + struct wined3d_mapped_box *mapped_box, const struct wined3d_box *box, DWORD flags); void __cdecl wined3d_volume_preload(struct wined3d_volume *volume); DWORD __cdecl wined3d_volume_set_priority(struct wined3d_volume *volume, DWORD new_priority); -HRESULT __cdecl wined3d_volume_set_private_data(struct wined3d_volume *volume, - REFGUID guid, const void *data, DWORD data_size, DWORD flags); HRESULT __cdecl wined3d_volume_unmap(struct wined3d_volume *volume); #endif /* __WINE_WINED3D_H */