wined3d: Pass a wined3d_resource_desc structure to wined3d_texture_create_3d().

This commit is contained in:
Henri Verbeet 2013-06-06 10:51:46 +02:00 committed by Alexandre Julliard
parent 145c417e98
commit 91096dd7ad
6 changed files with 70 additions and 54 deletions

View File

@ -475,6 +475,7 @@ static const struct wined3d_parent_ops d3d10_texture3d_wined3d_parent_ops =
HRESULT d3d10_texture3d_init(struct d3d10_texture3d *texture, struct d3d10_device *device, HRESULT d3d10_texture3d_init(struct d3d10_texture3d *texture, struct d3d10_device *device,
const D3D10_TEXTURE3D_DESC *desc) const D3D10_TEXTURE3D_DESC *desc)
{ {
struct wined3d_resource_desc wined3d_desc;
HRESULT hr; HRESULT hr;
texture->ID3D10Texture3D_iface.lpVtbl = &d3d10_texture3d_vtbl; texture->ID3D10Texture3D_iface.lpVtbl = &d3d10_texture3d_vtbl;
@ -483,10 +484,19 @@ HRESULT d3d10_texture3d_init(struct d3d10_texture3d *texture, struct d3d10_devic
FIXME("Implement DXGI<->wined3d usage conversion.\n"); FIXME("Implement DXGI<->wined3d usage conversion.\n");
hr = wined3d_texture_create_3d(device->wined3d_device, desc->Width, desc->Height, desc->Depth, wined3d_desc.resource_type = WINED3D_RTYPE_VOLUME_TEXTURE;
desc->MipLevels, desc->Usage, wined3dformat_from_dxgi_format(desc->Format), WINED3D_POOL_DEFAULT, wined3d_desc.format = wined3dformat_from_dxgi_format(desc->Format);
texture, &d3d10_texture3d_wined3d_parent_ops, &texture->wined3d_texture); wined3d_desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
if (FAILED(hr)) wined3d_desc.multisample_quality = 0;
wined3d_desc.usage = desc->Usage;
wined3d_desc.pool = WINED3D_POOL_DEFAULT;
wined3d_desc.width = desc->Width;
wined3d_desc.height = desc->Height;
wined3d_desc.depth = desc->Depth;
wined3d_desc.size = 0;
if (FAILED(hr = wined3d_texture_create_3d(device->wined3d_device, &wined3d_desc, desc->MipLevels,
texture, &d3d10_texture3d_wined3d_parent_ops, &texture->wined3d_texture)))
{ {
WARN("Failed to create wined3d texture, hr %#x.\n", hr); WARN("Failed to create wined3d texture, hr %#x.\n", hr);
return hr; return hr;

View File

@ -1257,15 +1257,26 @@ HRESULT cubetexture_init(struct d3d8_texture *texture, struct d3d8_device *devic
HRESULT volumetexture_init(struct d3d8_texture *texture, struct d3d8_device *device, 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) UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
{ {
struct wined3d_resource_desc desc;
HRESULT hr; HRESULT hr;
texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DVolumeTexture8_Vtbl; texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DVolumeTexture8_Vtbl;
texture->refcount = 1; texture->refcount = 1;
desc.resource_type = WINED3D_RTYPE_VOLUME_TEXTURE;
desc.format = wined3dformat_from_d3dformat(format);
desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
desc.multisample_quality = 0;
desc.usage = usage & WINED3DUSAGE_MASK;
desc.pool = pool;
desc.width = width;
desc.height = height;
desc.depth = depth;
desc.size = 0;
wined3d_mutex_lock(); wined3d_mutex_lock();
hr = wined3d_texture_create_3d(device->wined3d_device, width, height, depth, levels, hr = wined3d_texture_create_3d(device->wined3d_device, &desc, levels,
usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture, texture, &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture);
&d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture);
wined3d_mutex_unlock(); wined3d_mutex_unlock();
if (FAILED(hr)) if (FAILED(hr))
{ {

View File

@ -1381,15 +1381,26 @@ HRESULT cubetexture_init(struct d3d9_texture *texture, struct d3d9_device *devic
HRESULT volumetexture_init(struct d3d9_texture *texture, struct d3d9_device *device, HRESULT volumetexture_init(struct d3d9_texture *texture, struct d3d9_device *device,
UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
{ {
struct wined3d_resource_desc desc;
HRESULT hr; HRESULT hr;
texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_3d_vtbl; texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_3d_vtbl;
texture->refcount = 1; texture->refcount = 1;
desc.resource_type = WINED3D_RTYPE_VOLUME_TEXTURE;
desc.format = wined3dformat_from_d3dformat(format);
desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
desc.multisample_quality = 0;
desc.usage = usage & WINED3DUSAGE_MASK;
desc.pool = pool;
desc.width = width;
desc.height = height;
desc.depth = depth;
desc.size = 0;
wined3d_mutex_lock(); wined3d_mutex_lock();
hr = wined3d_texture_create_3d(device->wined3d_device, width, height, depth, levels, hr = wined3d_texture_create_3d(device->wined3d_device, &desc, levels,
usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture, texture, &d3d9_texture_wined3d_parent_ops, &texture->wined3d_texture);
&d3d9_texture_wined3d_parent_ops, &texture->wined3d_texture);
wined3d_mutex_unlock(); wined3d_mutex_unlock();
if (FAILED(hr)) if (FAILED(hr))
{ {

View File

@ -1153,19 +1153,17 @@ static const struct wined3d_resource_ops texture3d_resource_ops =
texture3d_unload, texture3d_unload,
}; };
static HRESULT volumetexture_init(struct wined3d_texture *texture, UINT width, UINT height, static HRESULT volumetexture_init(struct wined3d_texture *texture, const struct wined3d_resource_desc *desc,
UINT depth, UINT levels, struct wined3d_device *device, DWORD usage, enum wined3d_format_id format_id, UINT levels, struct wined3d_device *device, 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_gl_info *gl_info = &device->adapter->gl_info;
struct wined3d_resource_desc desc;
UINT tmp_w, tmp_h, tmp_d; UINT tmp_w, tmp_h, tmp_d;
unsigned int i; unsigned int i;
HRESULT hr; HRESULT hr;
/* TODO: It should only be possible to create textures for formats /* TODO: It should only be possible to create textures for formats
* that are reported as supported. */ * that are reported as supported. */
if (WINED3DFMT_UNKNOWN >= format_id) if (WINED3DFMT_UNKNOWN >= desc->format)
{ {
WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture); WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
return WINED3DERR_INVALIDCALL; return WINED3DERR_INVALIDCALL;
@ -1178,7 +1176,7 @@ static HRESULT volumetexture_init(struct wined3d_texture *texture, UINT width, U
} }
/* Calculate levels for mip mapping. */ /* Calculate levels for mip mapping. */
if (usage & WINED3DUSAGE_AUTOGENMIPMAP) if (desc->usage & WINED3DUSAGE_AUTOGENMIPMAP)
{ {
if (!gl_info->supported[SGIS_GENERATE_MIPMAP]) if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
{ {
@ -1196,7 +1194,7 @@ static HRESULT volumetexture_init(struct wined3d_texture *texture, UINT width, U
} }
else if (!levels) else if (!levels)
{ {
levels = wined3d_log2i(max(max(width, height), depth)) + 1; levels = wined3d_log2i(max(max(desc->width, desc->height), desc->depth)) + 1;
TRACE("Calculated levels = %u.\n", levels); TRACE("Calculated levels = %u.\n", levels);
} }
@ -1204,40 +1202,32 @@ static HRESULT volumetexture_init(struct wined3d_texture *texture, UINT width, U
{ {
UINT pow2_w, pow2_h, pow2_d; UINT pow2_w, pow2_h, pow2_d;
pow2_w = 1; pow2_w = 1;
while (pow2_w < width) pow2_w <<= 1; while (pow2_w < desc->width)
pow2_w <<= 1;
pow2_h = 1; pow2_h = 1;
while (pow2_h < height) pow2_h <<= 1; while (pow2_h < desc->height)
pow2_h <<= 1;
pow2_d = 1; pow2_d = 1;
while (pow2_d < depth) pow2_d <<= 1; while (pow2_d < desc->depth)
pow2_d <<= 1;
if (pow2_w != width || pow2_h != height || pow2_d != depth) if (pow2_w != desc->width || pow2_h != desc->height || pow2_d != desc->depth)
{ {
if (pool == WINED3D_POOL_SCRATCH) if (desc->pool == WINED3D_POOL_SCRATCH)
{ {
WARN("Creating a scratch NPOT volume texture despite lack of HW support.\n"); WARN("Creating a scratch NPOT volume texture despite lack of HW support.\n");
} }
else else
{ {
WARN("Attempted to create a NPOT volume texture (%u,%u,%u) without GL support.\n", WARN("Attempted to create a NPOT volume texture (%u, %u, %u) without GL support.\n",
width, height, depth); desc->width, desc->height, desc->depth);
return WINED3DERR_INVALIDCALL; return WINED3DERR_INVALIDCALL;
} }
} }
} }
desc.resource_type = WINED3D_RTYPE_VOLUME_TEXTURE;
desc.format = format_id;
desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
desc.multisample_quality = 0;
desc.usage = usage;
desc.pool = pool;
desc.width = width;
desc.height = height;
desc.depth = depth;
desc.size = 0;
if (FAILED(hr = wined3d_texture_init(texture, &texture3d_ops, 1, levels, if (FAILED(hr = wined3d_texture_init(texture, &texture3d_ops, 1, levels,
&desc, device, parent, parent_ops, &texture3d_resource_ops))) desc, device, parent, parent_ops, &texture3d_resource_ops)))
{ {
WARN("Failed to initialize texture, returning %#x.\n", hr); WARN("Failed to initialize texture, returning %#x.\n", hr);
return hr; return hr;
@ -1250,9 +1240,9 @@ static HRESULT volumetexture_init(struct wined3d_texture *texture, UINT width, U
texture->target = GL_TEXTURE_3D; texture->target = GL_TEXTURE_3D;
/* Generate all the surfaces. */ /* Generate all the surfaces. */
tmp_w = width; tmp_w = desc->width;
tmp_h = height; tmp_h = desc->height;
tmp_d = depth; tmp_d = desc->depth;
for (i = 0; i < texture->level_count; ++i) for (i = 0; i < texture->level_count; ++i)
{ {
@ -1260,7 +1250,7 @@ static HRESULT volumetexture_init(struct wined3d_texture *texture, UINT width, U
/* Create the volume. */ /* Create the volume. */
hr = device->device_parent->ops->create_volume(device->device_parent, parent, hr = device->device_parent->ops->create_volume(device->device_parent, parent,
tmp_w, tmp_h, tmp_d, format_id, pool, usage, &volume); tmp_w, tmp_h, tmp_d, desc->format, desc->pool, desc->usage, &volume);
if (FAILED(hr)) if (FAILED(hr))
{ {
ERR("Creating a volume for the volume texture failed, hr %#x.\n", hr); ERR("Creating a volume for the volume texture failed, hr %#x.\n", hr);
@ -1311,17 +1301,14 @@ HRESULT CDECL wined3d_texture_create_2d(struct wined3d_device *device, const str
return WINED3D_OK; return WINED3D_OK;
} }
HRESULT CDECL wined3d_texture_create_3d(struct wined3d_device *device, UINT width, UINT height, UINT depth, HRESULT CDECL wined3d_texture_create_3d(struct wined3d_device *device, const struct wined3d_resource_desc *desc,
UINT level_count, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool, void *parent, UINT level_count, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture)
const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture)
{ {
struct wined3d_texture *object; struct wined3d_texture *object;
HRESULT hr; HRESULT hr;
TRACE("device %p, width %u, height %u, depth %u, level_count %u, usage %#x\n", TRACE("device %p, desc %p, level_count %u, parent %p, parent_ops %p, texture %p.\n",
device, width, height, depth, level_count, usage); device, desc, level_count, parent, parent_ops, texture);
TRACE("format %s, pool %#x, parent %p, parent_ops %p, texture %p.\n",
debug_d3dformat(format_id), pool, parent, parent_ops, texture);
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if (!object) if (!object)
@ -1330,9 +1317,7 @@ HRESULT CDECL wined3d_texture_create_3d(struct wined3d_device *device, UINT widt
return WINED3DERR_OUTOFVIDEOMEMORY; return WINED3DERR_OUTOFVIDEOMEMORY;
} }
hr = volumetexture_init(object, width, height, depth, level_count, if (FAILED(hr = volumetexture_init(object, desc, level_count, device, parent, parent_ops)))
device, usage, format_id, pool, parent, parent_ops);
if (FAILED(hr))
{ {
WARN("Failed to initialize volumetexture, returning %#x\n", hr); WARN("Failed to initialize volumetexture, returning %#x\n", hr);
HeapFree(GetProcessHeap(), 0, object); HeapFree(GetProcessHeap(), 0, object);

View File

@ -252,7 +252,7 @@
@ cdecl wined3d_texture_add_dirty_region(ptr long ptr) @ cdecl wined3d_texture_add_dirty_region(ptr long ptr)
@ cdecl wined3d_texture_create_2d(ptr ptr long ptr ptr ptr) @ cdecl wined3d_texture_create_2d(ptr ptr long ptr ptr ptr)
@ cdecl wined3d_texture_create_3d(ptr long long long long long long long ptr ptr ptr) @ cdecl wined3d_texture_create_3d(ptr ptr long ptr ptr ptr)
@ cdecl wined3d_texture_create_cube(ptr ptr long ptr ptr ptr) @ cdecl wined3d_texture_create_cube(ptr ptr long ptr ptr ptr)
@ cdecl wined3d_texture_decref(ptr) @ cdecl wined3d_texture_decref(ptr)
@ cdecl wined3d_texture_generate_mipmaps(ptr) @ cdecl wined3d_texture_generate_mipmaps(ptr)

View File

@ -2373,9 +2373,8 @@ HRESULT __cdecl wined3d_texture_add_dirty_region(struct wined3d_texture *texture
UINT layer, const struct wined3d_box *dirty_region); UINT layer, const struct wined3d_box *dirty_region);
HRESULT __cdecl wined3d_texture_create_2d(struct wined3d_device *device, const struct wined3d_resource_desc *desc, HRESULT __cdecl wined3d_texture_create_2d(struct wined3d_device *device, const struct wined3d_resource_desc *desc,
UINT level_count, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture); UINT level_count, 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, HRESULT __cdecl wined3d_texture_create_3d(struct wined3d_device *device, const struct wined3d_resource_desc *desc,
UINT level_count, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool, void *parent, UINT level_count, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture);
const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture);
HRESULT __cdecl wined3d_texture_create_cube(struct wined3d_device *device, const struct wined3d_resource_desc *desc, HRESULT __cdecl wined3d_texture_create_cube(struct wined3d_device *device, const struct wined3d_resource_desc *desc,
UINT level_count, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture); UINT level_count, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture);
ULONG __cdecl wined3d_texture_decref(struct wined3d_texture *texture); ULONG __cdecl wined3d_texture_decref(struct wined3d_texture *texture);