From: Zebediah Figura zfigura@codeweavers.com
--- dlls/d3d8/d3d8_private.h | 13 +++-- dlls/d3d8/device.c | 6 +- dlls/d3d8/texture.c | 119 +++++++++++++-------------------------- 3 files changed, 49 insertions(+), 89 deletions(-)
diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h index 656f7f1859d..976f545d556 100644 --- a/dlls/d3d8/d3d8_private.h +++ b/dlls/d3d8/d3d8_private.h @@ -247,12 +247,13 @@ struct d3d8_texture struct list rtv_list; };
-HRESULT cubetexture_init(struct d3d8_texture *texture, struct d3d8_device *device, - UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN; -HRESULT texture_init(struct d3d8_texture *texture, struct d3d8_device *device, - UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN; -HRESULT volumetexture_init(struct d3d8_texture *texture, struct d3d8_device *device, - UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN; +HRESULT d3d8_texture_2d_init(struct d3d8_texture *texture, struct d3d8_device *device, unsigned int width, + unsigned int height, unsigned int level_count, DWORD usage, D3DFORMAT format, D3DPOOL pool); +HRESULT d3d8_texture_3d_init(struct d3d8_texture *texture, struct d3d8_device *device, unsigned int width, + unsigned int height, unsigned int depth, unsigned int levels, DWORD usage, D3DFORMAT format, D3DPOOL pool); +HRESULT d3d8_texture_cube_init(struct d3d8_texture *texture, struct d3d8_device *device, + unsigned int edge_length, unsigned int level_count, DWORD usage, D3DFORMAT format, D3DPOOL pool); + struct d3d8_texture *unsafe_impl_from_IDirect3DBaseTexture8(IDirect3DBaseTexture8 *iface) DECLSPEC_HIDDEN;
struct d3d8_vertex_declaration diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c index 5113e11fb33..11b3b6cc941 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -1097,7 +1097,7 @@ static HRESULT WINAPI d3d8_device_CreateTexture(IDirect3DDevice8 *iface, if (!(object = heap_alloc_zero(sizeof(*object)))) return D3DERR_OUTOFVIDEOMEMORY;
- hr = texture_init(object, device, width, height, levels, usage, format, pool); + hr = d3d8_texture_2d_init(object, device, width, height, levels, usage, format, pool); if (FAILED(hr)) { WARN("Failed to initialize texture, hr %#x.\n", hr); @@ -1129,7 +1129,7 @@ static HRESULT WINAPI d3d8_device_CreateVolumeTexture(IDirect3DDevice8 *iface, if (!(object = heap_alloc_zero(sizeof(*object)))) return D3DERR_OUTOFVIDEOMEMORY;
- hr = volumetexture_init(object, device, width, height, depth, levels, usage, format, pool); + hr = d3d8_texture_3d_init(object, device, width, height, depth, levels, usage, format, pool); if (FAILED(hr)) { WARN("Failed to initialize volume texture, hr %#x.\n", hr); @@ -1160,7 +1160,7 @@ static HRESULT WINAPI d3d8_device_CreateCubeTexture(IDirect3DDevice8 *iface, UIN if (!(object = heap_alloc_zero(sizeof(*object)))) return D3DERR_OUTOFVIDEOMEMORY;
- hr = cubetexture_init(object, device, edge_length, levels, usage, format, pool); + hr = d3d8_texture_cube_init(object, device, edge_length, levels, usage, format, pool); if (FAILED(hr)) { WARN("Failed to initialize cube texture, hr %#x.\n", hr); diff --git a/dlls/d3d8/texture.c b/dlls/d3d8/texture.c index 5f96336f2d8..5946f6aa2fd 100644 --- a/dlls/d3d8/texture.c +++ b/dlls/d3d8/texture.c @@ -1090,43 +1090,23 @@ static const struct wined3d_parent_ops d3d8_texture_wined3d_parent_ops = d3d8_texture_wined3d_object_destroyed, };
-HRESULT texture_init(struct d3d8_texture *texture, struct d3d8_device *device, - UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) +static HRESULT d3d8_texture_init(struct d3d8_texture *texture, struct d3d8_device *device, + const struct wined3d_resource_desc *desc, D3DPOOL pool, unsigned int layer_count, unsigned int level_count) { - struct wined3d_resource_desc desc; - DWORD flags = 0; + unsigned int flags = 0; HRESULT hr;
- texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DTexture8_Vtbl; d3d8_resource_init(&texture->resource); list_init(&texture->rtv_list);
- desc.resource_type = WINED3D_RTYPE_TEXTURE_2D; - desc.format = wined3dformat_from_d3dformat(format); - desc.multisample_type = WINED3D_MULTISAMPLE_NONE; - desc.multisample_quality = 0; - desc.usage = wined3d_usage_from_d3d(pool, usage); - desc.bind_flags = wined3d_bind_flags_from_d3d8_usage(usage) | WINED3D_BIND_SHADER_RESOURCE; - desc.access = wined3daccess_from_d3dpool(pool, usage); - desc.width = width; - desc.height = height; - desc.depth = 1; - desc.size = 0; - - if (usage & D3DUSAGE_WRITEONLY) - { - WARN("Texture can't be created with the D3DUSAGE_WRITEONLY flag, returning D3DERR_INVALIDCALL.\n"); - return D3DERR_INVALIDCALL; - } - - if (!levels) - levels = wined3d_log2i(max(width, height)) + 1; + if (!level_count) + level_count = wined3d_log2i(max(max(desc->width, desc->height), desc->depth)) + 1;
if (pool == D3DPOOL_SYSTEMMEM) flags |= WINED3D_TEXTURE_CREATE_RECORD_DIRTY_REGIONS;
wined3d_mutex_lock(); - hr = wined3d_texture_create(device->wined3d_device, &desc, 1, levels, flags, + hr = wined3d_texture_create(device->wined3d_device, desc, layer_count, level_count, flags, NULL, texture, &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture); wined3d_mutex_unlock(); if (FAILED(hr)) @@ -1141,26 +1121,20 @@ HRESULT texture_init(struct d3d8_texture *texture, struct d3d8_device *device, return D3D_OK; }
-HRESULT cubetexture_init(struct d3d8_texture *texture, struct d3d8_device *device, - UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) +HRESULT d3d8_texture_2d_init(struct d3d8_texture *texture, struct d3d8_device *device, unsigned int width, + unsigned int height, unsigned int level_count, DWORD usage, D3DFORMAT format, D3DPOOL pool) { struct wined3d_resource_desc desc; - DWORD flags = 0; - HRESULT hr; - - texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DCubeTexture8_Vtbl; - d3d8_resource_init(&texture->resource); - list_init(&texture->rtv_list);
desc.resource_type = WINED3D_RTYPE_TEXTURE_2D; desc.format = wined3dformat_from_d3dformat(format); desc.multisample_type = WINED3D_MULTISAMPLE_NONE; desc.multisample_quality = 0; - desc.usage = wined3d_usage_from_d3d(pool, usage) | WINED3DUSAGE_LEGACY_CUBEMAP; + desc.usage = wined3d_usage_from_d3d(pool, usage); desc.bind_flags = wined3d_bind_flags_from_d3d8_usage(usage) | WINED3D_BIND_SHADER_RESOURCE; desc.access = wined3daccess_from_d3dpool(pool, usage); - desc.width = edge_length; - desc.height = edge_length; + desc.width = width; + desc.height = height; desc.depth = 1; desc.size = 0;
@@ -1170,43 +1144,46 @@ HRESULT cubetexture_init(struct d3d8_texture *texture, struct d3d8_device *devic return D3DERR_INVALIDCALL; }
- if (!levels) - levels = wined3d_log2i(edge_length) + 1; + texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DTexture8_Vtbl; + return d3d8_texture_init(texture, device, &desc, pool, 1, level_count); +}
- if (pool == D3DPOOL_SYSTEMMEM) - flags |= WINED3D_TEXTURE_CREATE_RECORD_DIRTY_REGIONS; +HRESULT d3d8_texture_cube_init(struct d3d8_texture *texture, struct d3d8_device *device, + unsigned int edge_length, unsigned int level_count, DWORD usage, D3DFORMAT format, D3DPOOL pool) +{ + struct wined3d_resource_desc desc;
- wined3d_mutex_lock(); - hr = wined3d_texture_create(device->wined3d_device, &desc, 6, levels, flags, - NULL, texture, &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture); - wined3d_mutex_unlock(); - if (FAILED(hr)) + desc.resource_type = WINED3D_RTYPE_TEXTURE_2D; + desc.format = wined3dformat_from_d3dformat(format); + desc.multisample_type = WINED3D_MULTISAMPLE_NONE; + desc.multisample_quality = 0; + desc.usage = wined3d_usage_from_d3d(pool, usage) | WINED3DUSAGE_LEGACY_CUBEMAP; + desc.bind_flags = wined3d_bind_flags_from_d3d8_usage(usage) | WINED3D_BIND_SHADER_RESOURCE; + desc.access = wined3daccess_from_d3dpool(pool, usage); + desc.width = edge_length; + desc.height = edge_length; + desc.depth = 1; + desc.size = 0; + + if (usage & D3DUSAGE_WRITEONLY) { - WARN("Failed to create wined3d cube texture, hr %#x.\n", hr); - return hr; + WARN("Texture can't be created with the D3DUSAGE_WRITEONLY flag, returning D3DERR_INVALIDCALL.\n"); + return D3DERR_INVALIDCALL; }
- texture->parent_device = &device->IDirect3DDevice8_iface; - IDirect3DDevice8_AddRef(texture->parent_device); - - return D3D_OK; + texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DCubeTexture8_Vtbl; + return d3d8_texture_init(texture, device, &desc, pool, 6, level_count); }
-HRESULT volumetexture_init(struct d3d8_texture *texture, struct d3d8_device *device, - UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) +HRESULT d3d8_texture_3d_init(struct d3d8_texture *texture, struct d3d8_device *device, unsigned int width, + unsigned int height, unsigned int depth, unsigned int level_count, DWORD usage, D3DFORMAT format, D3DPOOL pool) { struct wined3d_resource_desc desc; - DWORD flags = 0; - HRESULT hr;
/* In d3d8, 3D textures can't be used as rendertarget or depth/stencil buffer. */ if (usage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL)) return D3DERR_INVALIDCALL;
- texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DVolumeTexture8_Vtbl; - d3d8_resource_init(&texture->resource); - list_init(&texture->rtv_list); - desc.resource_type = WINED3D_RTYPE_TEXTURE_3D; desc.format = wined3dformat_from_d3dformat(format); desc.multisample_type = WINED3D_MULTISAMPLE_NONE; @@ -1225,24 +1202,6 @@ HRESULT volumetexture_init(struct d3d8_texture *texture, struct d3d8_device *dev return D3DERR_INVALIDCALL; }
- if (!levels) - levels = wined3d_log2i(max(max(width, height), depth)) + 1; - - if (pool == D3DPOOL_SYSTEMMEM) - flags |= WINED3D_TEXTURE_CREATE_RECORD_DIRTY_REGIONS; - - wined3d_mutex_lock(); - hr = wined3d_texture_create(device->wined3d_device, &desc, 1, levels, flags, - NULL, texture, &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture); - wined3d_mutex_unlock(); - if (FAILED(hr)) - { - WARN("Failed to create wined3d volume texture, hr %#x.\n", hr); - return hr; - } - - texture->parent_device = &device->IDirect3DDevice8_iface; - IDirect3DDevice8_AddRef(texture->parent_device); - - return D3D_OK; + texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DVolumeTexture8_Vtbl; + return d3d8_texture_init(texture, device, &desc, pool, 1, level_count); }