Commit fb7135ef authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Introduce struct wined3d_rendertarget_view_desc.

parent eb24c957
......@@ -654,9 +654,73 @@ static const struct ID3D10RenderTargetViewVtbl d3d10_rendertarget_view_vtbl =
d3d10_rendertarget_view_GetDesc,
};
static void wined3d_rendertarget_view_desc_from_d3d10core(struct wined3d_rendertarget_view_desc *wined3d_desc,
const D3D10_RENDER_TARGET_VIEW_DESC *desc)
{
wined3d_desc->format_id = wined3dformat_from_dxgi_format(desc->Format);
switch (desc->ViewDimension)
{
case D3D10_RTV_DIMENSION_BUFFER:
wined3d_desc->u.buffer.start_idx = desc->u.Buffer.ElementOffset;
wined3d_desc->u.buffer.count = desc->u.Buffer.ElementWidth;
break;
case D3D10_RTV_DIMENSION_TEXTURE1D:
wined3d_desc->u.texture.level_idx = desc->u.Texture1D.MipSlice;
wined3d_desc->u.texture.layer_idx = 0;
wined3d_desc->u.texture.layer_count = 1;
break;
case D3D10_RTV_DIMENSION_TEXTURE1DARRAY:
wined3d_desc->u.texture.level_idx = desc->u.Texture1DArray.MipSlice;
wined3d_desc->u.texture.layer_idx = desc->u.Texture1DArray.FirstArraySlice;
wined3d_desc->u.texture.layer_count = desc->u.Texture1DArray.ArraySize;
break;
case D3D10_RTV_DIMENSION_TEXTURE2D:
wined3d_desc->u.texture.level_idx = desc->u.Texture2D.MipSlice;
wined3d_desc->u.texture.layer_idx = 0;
wined3d_desc->u.texture.layer_count = 1;
break;
case D3D10_RTV_DIMENSION_TEXTURE2DARRAY:
wined3d_desc->u.texture.level_idx = desc->u.Texture2DArray.MipSlice;
wined3d_desc->u.texture.layer_idx = desc->u.Texture2DArray.FirstArraySlice;
wined3d_desc->u.texture.layer_count = desc->u.Texture2DArray.ArraySize;
break;
case D3D10_RTV_DIMENSION_TEXTURE2DMS:
wined3d_desc->u.texture.level_idx = 0;
wined3d_desc->u.texture.layer_idx = 0;
wined3d_desc->u.texture.layer_count = 1;
break;
case D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY:
wined3d_desc->u.texture.level_idx = 0;
wined3d_desc->u.texture.layer_idx = desc->u.Texture2DMSArray.FirstArraySlice;
wined3d_desc->u.texture.layer_count = desc->u.Texture2DMSArray.ArraySize;
break;
case D3D10_RTV_DIMENSION_TEXTURE3D:
wined3d_desc->u.texture.level_idx = desc->u.Texture3D.MipSlice;
wined3d_desc->u.texture.layer_idx = desc->u.Texture3D.FirstWSlice;
wined3d_desc->u.texture.layer_count = desc->u.Texture3D.WSize;
break;
default:
FIXME("Unhandled view dimension %#x.\n", desc->ViewDimension);
wined3d_desc->u.texture.level_idx = 0;
wined3d_desc->u.texture.layer_idx = 0;
wined3d_desc->u.texture.layer_count = 1;
break;
}
}
HRESULT d3d10_rendertarget_view_init(struct d3d10_rendertarget_view *view, struct d3d10_device *device,
ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc)
{
struct wined3d_rendertarget_view_desc wined3d_desc;
struct wined3d_resource *wined3d_resource;
HRESULT hr;
......@@ -680,8 +744,8 @@ HRESULT d3d10_rendertarget_view_init(struct d3d10_rendertarget_view *view, struc
return E_FAIL;
}
hr = wined3d_rendertarget_view_create(wined3d_resource, view, &view->wined3d_view);
if (FAILED(hr))
wined3d_rendertarget_view_desc_from_d3d10core(&wined3d_desc, &view->desc);
if (FAILED(hr = wined3d_rendertarget_view_create(&wined3d_desc, wined3d_resource, view, &view->wined3d_view)))
{
WARN("Failed to create a wined3d rendertarget view, hr %#x.\n", hr);
return hr;
......
......@@ -63,30 +63,54 @@ struct wined3d_resource * CDECL wined3d_rendertarget_view_get_resource(const str
}
static void wined3d_rendertarget_view_init(struct wined3d_rendertarget_view *view,
struct wined3d_resource *resource, void *parent)
const struct wined3d_rendertarget_view_desc *desc, struct wined3d_resource *resource, void *parent)
{
const struct wined3d_gl_info *gl_info = &resource->device->adapter->gl_info;
view->refcount = 1;
view->resource = resource;
wined3d_resource_incref(resource);
view->parent = parent;
view->format = wined3d_get_format(gl_info, desc->format_id);
if (resource->type == WINED3D_RTYPE_BUFFER)
{
view->sub_resource_idx = 0;
view->buffer_offset = desc->u.buffer.start_idx;
view->width = desc->u.buffer.count;
view->height = 1;
view->depth = 1;
}
else
{
struct wined3d_texture *texture = wined3d_texture_from_resource(resource);
struct wined3d_resource *sub_resource;
view->sub_resource_idx = desc->u.texture.layer_idx * texture->level_count + desc->u.texture.level_idx;
sub_resource = wined3d_texture_get_sub_resource(texture, view->sub_resource_idx);
view->buffer_offset = 0;
view->width = sub_resource->width;
view->height = sub_resource->height;
view->depth = desc->u.texture.layer_count;
}
}
HRESULT CDECL wined3d_rendertarget_view_create(struct wined3d_resource *resource,
void *parent, struct wined3d_rendertarget_view **rendertarget_view)
HRESULT CDECL wined3d_rendertarget_view_create(const struct wined3d_rendertarget_view_desc *desc,
struct wined3d_resource *resource, void *parent, struct wined3d_rendertarget_view **view)
{
struct wined3d_rendertarget_view *object;
TRACE("resource %p, parent %p, rendertarget_view %p.\n",
resource, parent, rendertarget_view);
TRACE("desc %p, resource %p, parent %p, view %p.\n",
desc, resource, parent, view);
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if (!object)
if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
return E_OUTOFMEMORY;
wined3d_rendertarget_view_init(object, resource, parent);
wined3d_rendertarget_view_init(object, desc, resource, parent);
TRACE("Created render target view %p.\n", object);
*rendertarget_view = object;
*view = object;
return WINED3D_OK;
}
......@@ -177,7 +177,7 @@
@ cdecl wined3d_resource_set_parent(ptr ptr)
@ cdecl wined3d_resource_set_priority(ptr long)
@ cdecl wined3d_rendertarget_view_create(ptr ptr ptr)
@ cdecl wined3d_rendertarget_view_create(ptr ptr ptr ptr)
@ cdecl wined3d_rendertarget_view_decref(ptr)
@ cdecl wined3d_rendertarget_view_get_parent(ptr)
@ cdecl wined3d_rendertarget_view_get_resource(ptr)
......
......@@ -2617,6 +2617,14 @@ struct wined3d_rendertarget_view
struct wined3d_resource *resource;
void *parent;
const struct wined3d_format *format;
unsigned int sub_resource_idx;
unsigned int buffer_offset;
unsigned int width;
unsigned int height;
unsigned int depth;
};
struct wined3d_swapchain_ops
......
......@@ -1934,6 +1934,25 @@ struct wined3d_buffer_desc
UINT misc_flags;
};
struct wined3d_rendertarget_view_desc
{
enum wined3d_format_id format_id;
union
{
struct
{
unsigned int start_idx;
unsigned int count;
} buffer;
struct
{
unsigned int level_idx;
unsigned int layer_idx;
unsigned int layer_count;
} texture;
} u;
};
struct wined3d_shader_signature_element
{
const char *semantic_name;
......@@ -2357,8 +2376,8 @@ DWORD __cdecl wined3d_resource_get_priority(const struct wined3d_resource *resou
void __cdecl wined3d_resource_set_parent(struct wined3d_resource *resource, void *parent);
DWORD __cdecl wined3d_resource_set_priority(struct wined3d_resource *resource, DWORD priority);
HRESULT __cdecl wined3d_rendertarget_view_create(struct wined3d_resource *resource,
void *parent, struct wined3d_rendertarget_view **rendertarget_view);
HRESULT __cdecl wined3d_rendertarget_view_create(const struct wined3d_rendertarget_view_desc *desc,
struct wined3d_resource *resource, void *parent, struct wined3d_rendertarget_view **view);
ULONG __cdecl wined3d_rendertarget_view_decref(struct wined3d_rendertarget_view *view);
void * __cdecl wined3d_rendertarget_view_get_parent(const struct wined3d_rendertarget_view *view);
struct wined3d_resource * __cdecl wined3d_rendertarget_view_get_resource(const struct wined3d_rendertarget_view *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