Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/wined3d/buffer.c | 17 ++--------------- dlls/wined3d/device.c | 12 ++++++++++++ dlls/wined3d/texture.c | 39 ++++++++++++++------------------------- 3 files changed, 28 insertions(+), 40 deletions(-)
diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 142cce0299f..20057b4127f 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -875,21 +875,8 @@ static HRESULT buffer_resource_sub_resource_map(struct wined3d_resource *resourc TRACE("resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n", resource, sub_resource_idx, map_desc, debug_box(box), flags);
- if (sub_resource_idx) - { - WARN("Invalid sub_resource_idx %u.\n", sub_resource_idx); - return E_INVALIDARG; - } - - if (box) - { - offset = box->left; - size = box->right - box->left; - } - else - { - offset = size = 0; - } + offset = box->left; + size = box->right - box->left;
map_desc->row_pitch = map_desc->slice_pitch = resource->size;
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 6d749269c18..55407516446 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -4834,6 +4834,9 @@ HRESULT CDECL wined3d_device_context_map(struct wined3d_device_context *context, struct wined3d_resource *resource, unsigned int sub_resource_idx, struct wined3d_map_desc *map_desc, const struct wined3d_box *box, unsigned int flags) { + struct wined3d_sub_resource_desc desc; + struct wined3d_box b; + TRACE("context %p, resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n", context, resource, sub_resource_idx, map_desc, debug_box(box), flags);
@@ -4857,6 +4860,15 @@ HRESULT CDECL wined3d_device_context_map(struct wined3d_device_context *context,
flags = sanitise_map_flags(resource, flags);
+ if (FAILED(wined3d_resource_get_sub_resource_desc(resource, sub_resource_idx, &desc))) + return E_INVALIDARG; + + if (!box) + { + wined3d_box_set(&b, 0, 0, desc.width, desc.height, 0, desc.depth); + box = &b; + } + return context->ops->map(context, resource, sub_resource_idx, map_desc, box, flags); }
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index 5f02bcfed8f..c09a9f619ac 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -3532,11 +3532,10 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour resource, sub_resource_idx, map_desc, debug_box(box), flags);
texture = texture_from_resource(resource); - if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx))) - return E_INVALIDARG; + sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx);
texture_level = sub_resource_idx % texture->level_count; - if (box && FAILED(wined3d_texture_check_box_dimensions(texture, texture_level, box))) + if (FAILED(wined3d_texture_check_box_dimensions(texture, texture_level, box))) { WARN("Map box is invalid.\n"); if (((fmt_flags & WINED3DFMT_FLAG_BLOCKS) && !(resource->access & WINED3D_RESOURCE_ACCESS_CPU)) @@ -3605,38 +3604,28 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour wined3d_texture_get_pitch(texture, texture_level, &map_desc->row_pitch, &map_desc->slice_pitch); }
- if (!box) + if ((fmt_flags & (WINED3DFMT_FLAG_BLOCKS | WINED3DFMT_FLAG_BROKEN_PITCH)) == WINED3DFMT_FLAG_BLOCKS) { - map_desc->data = base_memory; + /* Compressed textures are block based, so calculate the offset of + * the block that contains the top-left pixel of the mapped box. */ + map_desc->data = base_memory + + (box->front * map_desc->slice_pitch) + + ((box->top / format->block_height) * map_desc->row_pitch) + + ((box->left / format->block_width) * format->block_byte_count); } else { - if ((fmt_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 mapped box. */ - map_desc->data = base_memory - + (box->front * map_desc->slice_pitch) - + ((box->top / format->block_height) * map_desc->row_pitch) - + ((box->left / format->block_width) * format->block_byte_count); - } - else - { - map_desc->data = base_memory - + (box->front * map_desc->slice_pitch) - + (box->top * map_desc->row_pitch) - + (box->left * format->byte_count); - } + map_desc->data = base_memory + + (box->front * map_desc->slice_pitch) + + (box->top * map_desc->row_pitch) + + (box->left * format->byte_count); }
if (texture->swapchain && texture->swapchain->front_buffer == texture) { RECT *r = &texture->swapchain->front_buffer_update;
- if (!box) - SetRect(r, 0, 0, resource->width, resource->height); - else - SetRect(r, box->left, box->top, box->right, box->bottom); + SetRect(r, box->left, box->top, box->right, box->bottom); TRACE("Mapped front buffer %s.\n", wine_dbgstr_rect(r)); }