Commit 3d452ed9 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

ddraw: Create wined3d textures before ddraw surfaces.

parent 80dbeb96
......@@ -3116,8 +3116,15 @@ static HRESULT CreateSurface(struct ddraw *ddraw, DDSURFACEDESC2 *DDSD,
}
}
/* Create the first surface */
if (FAILED(hr = ddraw_create_surface(ddraw, &desc2, flags, &object, version)))
if (desc2.ddsCaps.dwCaps & DDSCAPS_TEXTURE)
{
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);
return hr;
......@@ -3168,22 +3175,6 @@ static HRESULT CreateSurface(struct ddraw *ddraw, DDSURFACEDESC2 *DDSD,
}
}
if (desc2.ddsCaps.dwCaps & DDSCAPS_TEXTURE)
{
hr = ddraw_surface_create_texture(object, flags);
if (FAILED(hr))
{
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 (desc2.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
ddraw->primary = object;
......@@ -5160,13 +5151,6 @@ static HRESULT CDECL device_parent_create_texture_surface(struct wined3d_device_
TRACE("device_parent %p, container_parent %p, wined3d_desc %p, sub_resource_idx %u, flags %#x, surface %p.\n",
device_parent, container_parent, wined3d_desc, sub_resource_idx, flags, surface);
/* The ddraw root surface is created before the wined3d texture. */
if (!sub_resource_idx)
{
ddraw_surface = texture->root;
goto done;
}
desc.dwWidth = wined3d_desc->width;
desc.dwHeight = wined3d_desc->height;
......@@ -5174,7 +5158,6 @@ static HRESULT CDECL device_parent_create_texture_surface(struct wined3d_device_
if (FAILED(hr = ddraw_create_surface(ddraw, &desc, flags, &ddraw_surface, texture->version)))
return hr;
done:
*surface = ddraw_surface->wined3d_surface;
wined3d_surface_incref(*surface);
......
......@@ -193,7 +193,8 @@ struct ddraw_texture
struct ddraw_surface *root;
};
HRESULT ddraw_surface_create_texture(struct ddraw_surface *surface, DWORD surface_flags) DECLSPEC_HIDDEN;
HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, const DDSURFACEDESC2 *desc,
unsigned int version, DWORD surface_flags, struct ddraw_surface **surface) DECLSPEC_HIDDEN;
HRESULT ddraw_surface_init(struct ddraw_surface *surface, struct ddraw *ddraw,
DDSURFACEDESC2 *desc, DWORD flags, UINT version) DECLSPEC_HIDDEN;
ULONG ddraw_surface_release_iface(struct ddraw_surface *This) DECLSPEC_HIDDEN;
......
......@@ -5588,11 +5588,12 @@ static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops =
ddraw_texture_wined3d_object_destroyed,
};
HRESULT ddraw_surface_create_texture(struct ddraw_surface *surface, DWORD surface_flags)
HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, const DDSURFACEDESC2 *desc,
unsigned int version, DWORD surface_flags, struct ddraw_surface **surface)
{
const DDSURFACEDESC2 *desc = &surface->surface_desc;
struct ddraw_surface *root, *mip, **attach;
struct wined3d_resource_desc wined3d_desc;
struct ddraw_surface *mip, **attach;
struct wined3d_texture *wined3d_texture;
struct wined3d_resource *resource;
struct ddraw_texture *texture;
UINT layers, levels, i, j;
......@@ -5603,9 +5604,8 @@ HRESULT ddraw_surface_create_texture(struct ddraw_surface *surface, DWORD surfac
if (!(texture = HeapAlloc(GetProcessHeap(), 0, sizeof(*texture))))
return E_OUTOFMEMORY;
texture->version = surface->version;
texture->version = version;
texture->surface_desc = *desc;
texture->root = surface;
if (desc->ddsCaps.dwCaps & DDSCAPS_MIPMAP)
levels = desc->u2.dwMipMapCount;
......@@ -5636,7 +5636,7 @@ HRESULT ddraw_surface_create_texture(struct ddraw_surface *surface, DWORD surfac
pool = WINED3D_POOL_DEFAULT;
}
wined3d_desc.format = wined3dformat_from_ddrawformat(&surface->surface_desc.u4.ddpfPixelFormat);
wined3d_desc.format = wined3dformat_from_ddrawformat(&desc->u4.ddpfPixelFormat);
wined3d_desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
wined3d_desc.multisample_quality = 0;
wined3d_desc.pool = pool;
......@@ -5648,14 +5648,14 @@ HRESULT ddraw_surface_create_texture(struct ddraw_surface *surface, DWORD surfac
if (desc->ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP)
{
wined3d_desc.resource_type = WINED3D_RTYPE_CUBE_TEXTURE;
hr = wined3d_texture_create_cube(surface->ddraw->wined3d_device, &wined3d_desc, levels,
surface_flags, texture, &ddraw_texture_wined3d_parent_ops, &surface->wined3d_texture);
hr = wined3d_texture_create_cube(ddraw->wined3d_device, &wined3d_desc, levels,
surface_flags, texture, &ddraw_texture_wined3d_parent_ops, &wined3d_texture);
}
else
{
wined3d_desc.resource_type = WINED3D_RTYPE_TEXTURE;
hr = wined3d_texture_create_2d(surface->ddraw->wined3d_device, &wined3d_desc, levels,
surface_flags, texture, &ddraw_texture_wined3d_parent_ops, &surface->wined3d_texture);
hr = wined3d_texture_create_2d(ddraw->wined3d_device, &wined3d_desc, levels,
surface_flags, texture, &ddraw_texture_wined3d_parent_ops, &wined3d_texture);
}
if (FAILED(hr))
......@@ -5675,16 +5675,21 @@ HRESULT ddraw_surface_create_texture(struct ddraw_surface *surface, DWORD surfac
return hr;
}
resource = wined3d_texture_get_sub_resource(wined3d_texture, 0);
root = wined3d_resource_get_parent(resource);
root->wined3d_texture = wined3d_texture;
texture->root = root;
for (i = 0; i < layers; ++i)
{
attach = &surface->complex_array[layers - 1 - i];
attach = &root->complex_array[layers - 1 - i];
for (j = 0; j < levels; ++j)
{
resource = wined3d_texture_get_sub_resource(surface->wined3d_texture, i * levels + j);
resource = wined3d_texture_get_sub_resource(wined3d_texture, i * levels + j);
mip = wined3d_resource_get_parent(resource);
if (mip == surface)
if (mip == root)
continue;
mip_desc = &mip->surface_desc;
......@@ -5727,6 +5732,8 @@ HRESULT ddraw_surface_create_texture(struct ddraw_surface *surface, DWORD surfac
}
}
*surface = root;
return DD_OK;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment