Commit 339f7ef1 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Introduce basetexture_get_sub_resource() to simplify retrieving texture sub-resources.

parent 9308c549
......@@ -81,6 +81,23 @@ void basetexture_cleanup(IWineD3DBaseTexture *iface)
resource_cleanup((IWineD3DResource *)iface);
}
IWineD3DResourceImpl *basetexture_get_sub_resource(IWineD3DBaseTextureImpl *texture, UINT layer, UINT level)
{
if (layer >= texture->baseTexture.layer_count)
{
WARN("layer %u >= layer_count %u.\n", layer, texture->baseTexture.layer_count);
return NULL;
}
if (level >= texture->baseTexture.level_count)
{
WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
return NULL;
}
return texture->baseTexture.sub_resources[layer * texture->baseTexture.level_count + level];
}
/* A GL context is provided by the caller */
static void gltexture_delete(struct gl_texture *tex)
{
......
......@@ -319,42 +319,37 @@ static BOOL WINAPI IWineD3DCubeTextureImpl_IsCondNP2(IWineD3DCubeTexture *iface)
static HRESULT WINAPI IWineD3DCubeTextureImpl_GetLevelDesc(IWineD3DCubeTexture *iface,
UINT level, WINED3DSURFACE_DESC *desc)
{
IWineD3DCubeTextureImpl *texture = (IWineD3DCubeTextureImpl *)iface;
IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
IWineD3DSurface *surface;
TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
if (level >= texture->baseTexture.level_count)
if (!(surface = (IWineD3DSurface *)basetexture_get_sub_resource(texture, 0, level)))
{
WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
WARN("Failed to get sub-resource.\n");
return WINED3DERR_INVALIDCALL;
}
return IWineD3DSurface_GetDesc((IWineD3DSurface *)texture->baseTexture.sub_resources[level], desc);
return IWineD3DSurface_GetDesc(surface, desc);
}
static HRESULT WINAPI IWineD3DCubeTextureImpl_GetCubeMapSurface(IWineD3DCubeTexture *iface,
WINED3DCUBEMAP_FACES face, UINT level, IWineD3DSurface **surface)
{
IWineD3DCubeTextureImpl *texture = (IWineD3DCubeTextureImpl *)iface;
UINT idx = face * texture->baseTexture.level_count + level;
IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
IWineD3DSurface *s;
TRACE("iface %p, face %u, level %u, surface %p.\n",
iface, face, level, surface);
if (level >= texture->baseTexture.level_count)
if (!(s = (IWineD3DSurface *)basetexture_get_sub_resource(texture, face, level)))
{
WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
WARN("Failed to get sub-resource.\n");
return WINED3DERR_INVALIDCALL;
}
if (face >= texture->baseTexture.layer_count)
{
WARN("face %u >= layer_count %u.\n", face, texture->baseTexture.layer_count);
return WINED3DERR_INVALIDCALL;
}
*surface = (IWineD3DSurface *)texture->baseTexture.sub_resources[idx];
IWineD3DSurface_AddRef(*surface);
IWineD3DSurface_AddRef(s);
*surface = s;
TRACE("Returning surface %p.\n", *surface);
......@@ -364,70 +359,57 @@ static HRESULT WINAPI IWineD3DCubeTextureImpl_GetCubeMapSurface(IWineD3DCubeText
static HRESULT WINAPI IWineD3DCubeTextureImpl_LockRect(IWineD3DCubeTexture *iface,
WINED3DCUBEMAP_FACES face, UINT level, WINED3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags)
{
IWineD3DCubeTextureImpl *texture = (IWineD3DCubeTextureImpl *)iface;
UINT idx = face * texture->baseTexture.level_count + level;
IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
IWineD3DSurface *surface;
TRACE("iface %p, face %u, level %u, locked_rect %p, rect %s, flags %#x.\n",
iface, face, level, locked_rect, wine_dbgstr_rect(rect), flags);
if (level >= texture->baseTexture.level_count)
{
WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
return WINED3DERR_INVALIDCALL;
}
if (face >= texture->baseTexture.layer_count)
if (!(surface = (IWineD3DSurface *)basetexture_get_sub_resource(texture, face, level)))
{
WARN("face %u >= layer_count %u.\n", face, texture->baseTexture.layer_count);
WARN("Failed to get sub-resource.\n");
return WINED3DERR_INVALIDCALL;
}
return IWineD3DSurface_LockRect((IWineD3DSurface *)texture->baseTexture.sub_resources[idx],
locked_rect, rect, flags);
return IWineD3DSurface_LockRect(surface, locked_rect, rect, flags);
}
static HRESULT WINAPI IWineD3DCubeTextureImpl_UnlockRect(IWineD3DCubeTexture *iface,
WINED3DCUBEMAP_FACES face, UINT level)
{
IWineD3DCubeTextureImpl *texture = (IWineD3DCubeTextureImpl *)iface;
UINT idx = face * texture->baseTexture.level_count + level;
IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
IWineD3DSurface *surface;
TRACE("iface %p, face %u, level %u.\n",
iface, face, level);
if (level >= texture->baseTexture.level_count)
{
WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
return WINED3DERR_INVALIDCALL;
}
if (face >= texture->baseTexture.layer_count)
if (!(surface = (IWineD3DSurface *)basetexture_get_sub_resource(texture, face, level)))
{
WARN("face %u >= layer_count %u.\n", face, texture->baseTexture.layer_count);
WARN("Failed to get sub-resource.\n");
return WINED3DERR_INVALIDCALL;
}
return IWineD3DSurface_UnlockRect((IWineD3DSurface *)texture->baseTexture.sub_resources[idx]);
return IWineD3DSurface_UnlockRect(surface);
}
static HRESULT WINAPI IWineD3DCubeTextureImpl_AddDirtyRect(IWineD3DCubeTexture *iface,
WINED3DCUBEMAP_FACES face, const RECT *dirty_rect)
{
IWineD3DCubeTextureImpl *texture = (IWineD3DCubeTextureImpl *)iface;
UINT idx = face * texture->baseTexture.level_count;
IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
IWineD3DSurface *surface;
TRACE("iface %p, face %u, dirty_rect %s.\n",
iface, face, wine_dbgstr_rect(dirty_rect));
if (face >= texture->baseTexture.layer_count)
if (!(surface = (IWineD3DSurface *)basetexture_get_sub_resource(texture, face, 0)))
{
WARN("face %u >= layer_count %u.\n", face, texture->baseTexture.layer_count);
WARN("Failed to get sub-resource.\n");
return WINED3DERR_INVALIDCALL;
}
texture->baseTexture.texture_rgb.dirty = TRUE;
texture->baseTexture.texture_srgb.dirty = TRUE;
surface_add_dirty_rect((IWineD3DSurface *)texture->baseTexture.sub_resources[idx], dirty_rect);
surface_add_dirty_rect(surface, dirty_rect);
return WINED3D_OK;
}
......
......@@ -333,78 +333,94 @@ static BOOL WINAPI IWineD3DTextureImpl_IsCondNP2(IWineD3DTexture *iface) {
/* *******************************************
IWineD3DTexture IWineD3DTexture parts follow
******************************************* */
static HRESULT WINAPI IWineD3DTextureImpl_GetLevelDesc(IWineD3DTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
static HRESULT WINAPI IWineD3DTextureImpl_GetLevelDesc(IWineD3DTexture *iface, UINT level, WINED3DSURFACE_DESC *desc)
{
IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
IWineD3DSurface *surface;
TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
if (Level < This->baseTexture.level_count)
if (!(surface = (IWineD3DSurface *)basetexture_get_sub_resource(texture, 0, level)))
{
TRACE("(%p) Level (%d)\n", This, Level);
return IWineD3DSurface_GetDesc((IWineD3DSurface *)This->baseTexture.sub_resources[Level], pDesc);
WARN("Failed to get sub-resource.\n");
return WINED3DERR_INVALIDCALL;
}
WARN("(%p) level %u >= level_count %u.\n", This, Level, This->baseTexture.level_count);
return WINED3DERR_INVALIDCALL;
return IWineD3DSurface_GetDesc(surface, desc);
}
static HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface, UINT Level, IWineD3DSurface** ppSurfaceLevel) {
IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
HRESULT hr = WINED3DERR_INVALIDCALL;
static HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface,
UINT level, IWineD3DSurface **surface)
{
IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
IWineD3DSurface *s;
if (Level < This->baseTexture.level_count)
TRACE("iface %p, level %u, surface %p.\n", iface, level, surface);
if (!(s = (IWineD3DSurface *)basetexture_get_sub_resource(texture, 0, level)))
{
*ppSurfaceLevel = (IWineD3DSurface *)This->baseTexture.sub_resources[Level];
IWineD3DSurface_AddRef(*ppSurfaceLevel);
hr = WINED3D_OK;
TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level);
}
if (WINED3D_OK != hr) {
WARN("(%p) level %u >= level_count %u.\n", This, Level, This->baseTexture.level_count);
*ppSurfaceLevel = NULL; /* Just to be on the safe side.. */
WARN("Failed to get sub-resource.\n");
return WINED3DERR_INVALIDCALL;
}
return hr;
IWineD3DSurface_AddRef(s);
*surface = s;
TRACE("Returning surface %p.\n", *surface);
return WINED3D_OK;
}
static HRESULT WINAPI IWineD3DTextureImpl_LockRect(IWineD3DTexture *iface, UINT Level, WINED3DLOCKED_RECT *pLockedRect,
CONST RECT *pRect, DWORD Flags) {
IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
HRESULT hr = WINED3DERR_INVALIDCALL;
static HRESULT WINAPI IWineD3DTextureImpl_LockRect(IWineD3DTexture *iface,
UINT level, WINED3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags)
{
IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
IWineD3DSurface *surface;
TRACE("iface %p, level %u, locked_rect %p, rect %s, flags %#x.\n",
iface, level, locked_rect, wine_dbgstr_rect(rect), flags);
if (Level < This->baseTexture.level_count)
if (!(surface = (IWineD3DSurface *)basetexture_get_sub_resource(texture, 0, level)))
{
IWineD3DSurface *surface = (IWineD3DSurface *)This->baseTexture.sub_resources[Level];
hr = IWineD3DSurface_LockRect(surface, pLockedRect, pRect, Flags);
}
if (WINED3D_OK == hr) {
TRACE("(%p) Level (%d) success\n", This, Level);
} else {
WARN("(%p) level %u >= level_count %u.\n", This, Level, This->baseTexture.level_count);
WARN("Failed to get sub-resource.\n");
return WINED3DERR_INVALIDCALL;
}
return hr;
return IWineD3DSurface_LockRect(surface, locked_rect, rect, flags);
}
static HRESULT WINAPI IWineD3DTextureImpl_UnlockRect(IWineD3DTexture *iface, UINT Level) {
IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
HRESULT hr = WINED3DERR_INVALIDCALL;
static HRESULT WINAPI IWineD3DTextureImpl_UnlockRect(IWineD3DTexture *iface, UINT level)
{
IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
IWineD3DSurface *surface;
TRACE("iface %p, level %u.\n", iface, level);
if (Level < This->baseTexture.level_count)
if (!(surface = (IWineD3DSurface *)basetexture_get_sub_resource(texture, 0, level)))
{
IWineD3DSurface *surface = (IWineD3DSurface *)This->baseTexture.sub_resources[Level];
hr = IWineD3DSurface_UnlockRect(surface);
}
if ( WINED3D_OK == hr) {
TRACE("(%p) Level (%d) success\n", This, Level);
} else {
WARN("(%p) level %u >= level_count %u.\n", This, Level, This->baseTexture.level_count);
WARN("Failed to get sub-resource.\n");
return WINED3DERR_INVALIDCALL;
}
return hr;
return IWineD3DSurface_UnlockRect(surface);
}
static HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, CONST RECT* pDirtyRect) {
IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
This->baseTexture.texture_rgb.dirty = TRUE;
This->baseTexture.texture_srgb.dirty = TRUE;
TRACE("(%p) : dirtyfication of surface Level (0)\n", This);
surface_add_dirty_rect((IWineD3DSurface *)This->baseTexture.sub_resources[0], pDirtyRect);
static HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, const RECT *dirty_rect)
{
IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
IWineD3DSurface *surface;
TRACE("iface %p, dirty_rect %s.\n", iface, wine_dbgstr_rect(dirty_rect));
if (!(surface = (IWineD3DSurface *)basetexture_get_sub_resource(texture, 0, 0)))
{
WARN("Failed to get sub-resource.\n");
return WINED3DERR_INVALIDCALL;
}
texture->baseTexture.texture_rgb.dirty = TRUE;
texture->baseTexture.texture_srgb.dirty = TRUE;
surface_add_dirty_rect(surface, dirty_rect);
return WINED3D_OK;
}
......
......@@ -256,82 +256,92 @@ static BOOL WINAPI IWineD3DVolumeTextureImpl_IsCondNP2(IWineD3DVolumeTexture *if
static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetLevelDesc(IWineD3DVolumeTexture *iface,
UINT level, WINED3DVOLUME_DESC *desc)
{
IWineD3DVolumeTextureImpl *texture = (IWineD3DVolumeTextureImpl *)iface;
IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
IWineD3DVolume *volume;
TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
if (level >= texture->baseTexture.level_count)
if (!(volume = (IWineD3DVolume *)basetexture_get_sub_resource(texture, 0, level)))
{
WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
WARN("Failed to get sub-resource.\n");
return WINED3DERR_INVALIDCALL;
}
return IWineD3DVolume_GetDesc((IWineD3DVolume *)texture->baseTexture.sub_resources[level], desc);
return IWineD3DVolume_GetDesc(volume, desc);
}
static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetVolumeLevel(IWineD3DVolumeTexture *iface,
UINT level, IWineD3DVolume **volume)
{
IWineD3DVolumeTextureImpl *texture = (IWineD3DVolumeTextureImpl *)iface;
IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
IWineD3DVolume *v;
TRACE("iface %p, level %u, volume %p.\n", iface, level, volume);
if (level >= texture->baseTexture.level_count)
if (!(v = (IWineD3DVolume *)basetexture_get_sub_resource(texture, 0, level)))
{
WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
WARN("Failed to get sub-resource.\n");
return WINED3DERR_INVALIDCALL;
}
*volume = (IWineD3DVolume *)texture->baseTexture.sub_resources[level];
IWineD3DVolume_AddRef(*volume);
IWineD3DVolume_AddRef(v);
*volume = v;
TRACE("Returning volume %p.\n", *volume);
return WINED3D_OK;
}
static HRESULT WINAPI IWineD3DVolumeTextureImpl_LockBox(IWineD3DVolumeTexture *iface,
UINT level, WINED3DLOCKED_BOX *locked_box, const WINED3DBOX *box, DWORD flags)
{
IWineD3DVolumeTextureImpl *texture = (IWineD3DVolumeTextureImpl *)iface;
IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
IWineD3DVolume *volume;
TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
iface, level, locked_box, box, flags);
if (level >= texture->baseTexture.level_count)
if (!(volume = (IWineD3DVolume *)basetexture_get_sub_resource(texture, 0, level)))
{
WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
WARN("Failed to get sub-resource.\n");
return WINED3DERR_INVALIDCALL;
}
return IWineD3DVolume_LockBox((IWineD3DVolume *)texture->baseTexture.sub_resources[level], locked_box, box, flags);
return IWineD3DVolume_LockBox(volume, locked_box, box, flags);
}
static HRESULT WINAPI IWineD3DVolumeTextureImpl_UnlockBox(IWineD3DVolumeTexture *iface, UINT level)
{
IWineD3DVolumeTextureImpl *texture = (IWineD3DVolumeTextureImpl *)iface;
IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
IWineD3DVolume *volume;
TRACE("iface %p, level %u.\n", iface, level);
if (level >= texture->baseTexture.level_count)
if (!(volume = (IWineD3DVolume *)basetexture_get_sub_resource(texture, 0, level)))
{
WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
WARN("Failed to get sub-resource.\n");
return WINED3DERR_INVALIDCALL;
}
return IWineD3DVolume_UnlockBox((IWineD3DVolume *)texture->baseTexture.sub_resources[level]);
return IWineD3DVolume_UnlockBox(volume);
}
static HRESULT WINAPI IWineD3DVolumeTextureImpl_AddDirtyBox(IWineD3DVolumeTexture *iface, const WINED3DBOX *dirty_box)
{
IWineD3DVolumeTextureImpl *texture = (IWineD3DVolumeTextureImpl *)iface;
IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface;
IWineD3DVolume *volume;
TRACE("iface %p, dirty_box %p.\n", iface, dirty_box);
if (!(volume = (IWineD3DVolume *)basetexture_get_sub_resource(texture, 0, 0)))
{
WARN("Failed to get sub-resource.\n");
return WINED3DERR_INVALIDCALL;
}
texture->baseTexture.texture_rgb.dirty = TRUE;
texture->baseTexture.texture_srgb.dirty = TRUE;
volume_add_dirty_box((IWineD3DVolume *)texture->baseTexture.sub_resources[0], dirty_box);
volume_add_dirty_box(volume, dirty_box);
return WINED3D_OK;
}
......
......@@ -1901,6 +1901,8 @@ WINED3DTEXTUREFILTERTYPE basetexture_get_autogen_filter_type(IWineD3DBaseTexture
BOOL basetexture_get_dirty(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
DWORD basetexture_get_level_count(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
DWORD basetexture_get_lod(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
IWineD3DResourceImpl *basetexture_get_sub_resource(IWineD3DBaseTextureImpl *texture,
UINT layer, UINT level) DECLSPEC_HIDDEN;
HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT layer_count, UINT level_count,
WINED3DRESOURCETYPE resource_type, IWineD3DDeviceImpl *device, UINT size, DWORD usage,
const struct wined3d_format_desc *format_desc, WINED3DPOOL pool, IUnknown *parent,
......
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