From 6ea9afe7011a65f6c7f67b303f13e672907a93f2 Mon Sep 17 00:00:00 2001 From: Henri Verbeet <hverbeet@codeweavers.com> Date: Wed, 13 Nov 2013 10:12:07 +0100 Subject: [PATCH] ddraw: Create textures for "standalone" surfaces. --- dlls/ddraw/ddraw.c | 12 ++---------- dlls/ddraw/device.c | 8 +++++--- dlls/ddraw/surface.c | 19 ++++++++++++++++--- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c index 6496ac3ed1f..f924a096418 100644 --- a/dlls/ddraw/ddraw.c +++ b/dlls/ddraw/ddraw.c @@ -3116,17 +3116,9 @@ static HRESULT CreateSurface(struct ddraw *ddraw, DDSURFACEDESC2 *DDSD, } } - if (desc2.ddsCaps.dwCaps & DDSCAPS_TEXTURE) + if (FAILED(hr = ddraw_surface_create_texture(ddraw, &desc2, version, flags, &object))) { - if (FAILED(hr = ddraw_surface_create_texture(ddraw, &desc2, version, flags, &object))) - { - WARN("Failed to create texture, hr %#x.\n", hr); - return hr; - } - } - else if (FAILED(hr = ddraw_create_surface(ddraw, &desc2, flags, &object, version))) - { - WARN("ddraw_create_surface failed, hr %#x.\n", hr); + WARN("Failed to create texture, hr %#x.\n", hr); return hr; } object->is_complex_root = TRUE; diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c index b7511bc02d3..874d78d4a00 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -4668,14 +4668,16 @@ static HRESULT d3d_device7_SetTexture(IDirect3DDevice7 *iface, { struct d3d_device *device = impl_from_IDirect3DDevice7(iface); struct ddraw_surface *surf = unsafe_impl_from_IDirectDrawSurface7(texture); + struct wined3d_texture *wined3d_texture = NULL; HRESULT hr; TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture); - /* Texture may be NULL here */ + if (surf && (surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_TEXTURE)) + wined3d_texture = surf->wined3d_texture; + wined3d_mutex_lock(); - hr = wined3d_device_set_texture(device->wined3d_device, - stage, surf ? surf->wined3d_texture : NULL); + hr = wined3d_device_set_texture(device->wined3d_device, stage, wined3d_texture); wined3d_mutex_unlock(); return hr; diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c index 808cd5f95b1..5b34ec7b1c3 100644 --- a/dlls/ddraw/surface.c +++ b/dlls/ddraw/surface.c @@ -484,6 +484,9 @@ static void ddraw_surface_cleanup(struct ddraw_surface *surface) surface, surface->ref7, surface->ref4, surface->ref3, surface->ref2, surface->ref1); } + if (surface->wined3d_texture + && !(surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_TEXTURE)) + wined3d_texture_decref(surface->wined3d_texture); if (surface->wined3d_surface) wined3d_surface_decref(surface->wined3d_surface); } @@ -505,7 +508,8 @@ ULONG ddraw_surface_release_iface(struct ddraw_surface *This) wined3d_mutex_unlock(); return iface_count; } - if (This->wined3d_texture) /* If it's a texture, destroy the wined3d texture. */ + /* If it's a texture, destroy the wined3d texture. */ + if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_TEXTURE) wined3d_texture_decref(This->wined3d_texture); else ddraw_surface_cleanup(This); @@ -5579,7 +5583,8 @@ static void STDMETHODCALLTYPE ddraw_texture_wined3d_object_destroyed(void *paren TRACE("texture %p.\n", texture); - ddraw_surface_cleanup(texture->root); + if (texture->surface_desc.ddsCaps.dwCaps & DDSCAPS_TEXTURE) + ddraw_surface_cleanup(texture->root); HeapFree(GetProcessHeap(), 0, parent); } @@ -5632,11 +5637,19 @@ HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, const DDSURFACEDESC2 * } else { - wined3d_desc.usage = WINED3DUSAGE_TEXTURE | WINED3DUSAGE_DYNAMIC; + wined3d_desc.usage = WINED3DUSAGE_DYNAMIC; + if (desc->ddsCaps.dwCaps & DDSCAPS_TEXTURE) + wined3d_desc.usage |= WINED3DUSAGE_TEXTURE; pool = WINED3D_POOL_DEFAULT; } wined3d_desc.format = wined3dformat_from_ddrawformat(&desc->u4.ddpfPixelFormat); + if (wined3d_desc.format == WINED3DFMT_UNKNOWN) + { + WARN("Unsupported / unknown pixelformat.\n"); + return DDERR_INVALIDPIXELFORMAT; + } + wined3d_desc.multisample_type = WINED3D_MULTISAMPLE_NONE; wined3d_desc.multisample_quality = 0; wined3d_desc.pool = pool;