Commit 62658ec5 authored by Józef Kucia's avatar Józef Kucia Committed by Alexandre Julliard

wined3d: Add support for buffers in wined3d_device_update_sub_resource().

parent 798b1e06
......@@ -1113,6 +1113,33 @@ void CDECL wined3d_buffer_unmap(struct wined3d_buffer *buffer)
}
}
HRESULT wined3d_buffer_upload_data(struct wined3d_buffer *buffer,
const struct wined3d_box *box, const void *data)
{
UINT offset, size;
HRESULT hr;
BYTE *ptr;
if (box)
{
offset = box->left;
size = box->right - box->left;
}
else
{
offset = 0;
size = buffer->resource.size;
}
if (FAILED(hr = wined3d_buffer_map(buffer, offset, size, &ptr, 0)))
return hr;
memcpy(ptr, data, size);
wined3d_buffer_unmap(buffer);
return WINED3D_OK;
}
static ULONG buffer_resource_incref(struct wined3d_resource *resource)
{
return wined3d_buffer_incref(buffer_from_resource(resource));
......@@ -1240,20 +1267,13 @@ static HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device
if (data)
{
BYTE *ptr;
hr = wined3d_buffer_map(buffer, 0, size, &ptr, 0);
if (FAILED(hr))
if (FAILED(hr = wined3d_buffer_upload_data(buffer, NULL, data->data)))
{
ERR("Failed to map buffer, hr %#x\n", hr);
ERR("Failed to upload data, hr %#x.\n", hr);
buffer_unload(&buffer->resource);
resource_cleanup(&buffer->resource);
return hr;
}
memcpy(ptr, data->data, size);
wined3d_buffer_unmap(buffer);
}
buffer->maps = HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer->maps));
......
......@@ -3989,6 +3989,23 @@ void CDECL wined3d_device_update_sub_resource(struct wined3d_device *device, str
TRACE("device %p, resource %p, sub_resource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
device, resource, sub_resource_idx, box, data, row_pitch, depth_pitch);
if (resource->type == WINED3D_RTYPE_BUFFER)
{
struct wined3d_buffer *buffer = buffer_from_resource(resource);
HRESULT hr;
if (sub_resource_idx > 0)
{
WARN("Invalid sub_resource_idx %u.\n", sub_resource_idx);
return;
}
if (FAILED(hr = wined3d_buffer_upload_data(buffer, box, data)))
WARN("Failed to update buffer data, hr %#x.\n", hr);
return;
}
if (resource->type != WINED3D_RTYPE_TEXTURE)
{
FIXME("Not implemented for %s resources.\n", debug_d3dresourcetype(resource->type));
......
......@@ -2758,6 +2758,8 @@ BYTE *buffer_get_sysmem(struct wined3d_buffer *This, struct wined3d_context *con
void buffer_internal_preload(struct wined3d_buffer *buffer, struct wined3d_context *context,
const struct wined3d_state *state) DECLSPEC_HIDDEN;
void buffer_mark_used(struct wined3d_buffer *buffer) DECLSPEC_HIDDEN;
HRESULT wined3d_buffer_upload_data(struct wined3d_buffer *buffer,
const struct wined3d_box *box, const void *data) DECLSPEC_HIDDEN;
struct wined3d_rendertarget_view
{
......
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