Commit 958b5237 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Store texture sub-resources in IWineD3DBaseTextureClass.

parent 11c7a67a
...@@ -27,9 +27,10 @@ ...@@ -27,9 +27,10 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture); WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT levels, WINED3DRESOURCETYPE resource_type, HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT layer_count, UINT level_count,
IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct wined3d_format_desc *format_desc, WINED3DRESOURCETYPE resource_type, IWineD3DDeviceImpl *device, UINT size, DWORD usage,
WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops) const struct wined3d_format_desc *format_desc, WINED3DPOOL pool, IUnknown *parent,
const struct wined3d_parent_ops *parent_ops)
{ {
HRESULT hr; HRESULT hr;
...@@ -41,7 +42,17 @@ HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT levels, WINED3DR ...@@ -41,7 +42,17 @@ HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT levels, WINED3DR
return hr; return hr;
} }
texture->baseTexture.levels = levels; texture->baseTexture.sub_resources = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
level_count * layer_count * sizeof(*texture->baseTexture.sub_resources));
if (!texture->baseTexture.sub_resources)
{
ERR("Failed to allocate sub-resource array.\n");
resource_cleanup((IWineD3DResource *)texture);
return E_OUTOFMEMORY;
}
texture->baseTexture.layer_count = layer_count;
texture->baseTexture.level_count = level_count;
texture->baseTexture.filterType = (usage & WINED3DUSAGE_AUTOGENMIPMAP) ? WINED3DTEXF_LINEAR : WINED3DTEXF_NONE; texture->baseTexture.filterType = (usage & WINED3DUSAGE_AUTOGENMIPMAP) ? WINED3DTEXF_LINEAR : WINED3DTEXF_NONE;
texture->baseTexture.LOD = 0; texture->baseTexture.LOD = 0;
texture->baseTexture.texture_rgb.dirty = TRUE; texture->baseTexture.texture_rgb.dirty = TRUE;
...@@ -66,6 +77,7 @@ HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT levels, WINED3DR ...@@ -66,6 +77,7 @@ HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT levels, WINED3DR
void basetexture_cleanup(IWineD3DBaseTexture *iface) void basetexture_cleanup(IWineD3DBaseTexture *iface)
{ {
basetexture_unload(iface); basetexture_unload(iface);
HeapFree(GetProcessHeap(), 0, ((IWineD3DBaseTextureImpl *)iface)->baseTexture.sub_resources);
resource_cleanup((IWineD3DResource *)iface); resource_cleanup((IWineD3DResource *)iface);
} }
...@@ -115,8 +127,8 @@ DWORD basetexture_set_lod(IWineD3DBaseTexture *iface, DWORD LODNew) ...@@ -115,8 +127,8 @@ DWORD basetexture_set_lod(IWineD3DBaseTexture *iface, DWORD LODNew)
return 0; return 0;
} }
if(LODNew >= This->baseTexture.levels) if (LODNew >= This->baseTexture.level_count)
LODNew = This->baseTexture.levels - 1; LODNew = This->baseTexture.level_count - 1;
if(This->baseTexture.LOD != LODNew) { if(This->baseTexture.LOD != LODNew) {
This->baseTexture.LOD = LODNew; This->baseTexture.LOD = LODNew;
...@@ -145,8 +157,8 @@ DWORD basetexture_get_lod(IWineD3DBaseTexture *iface) ...@@ -145,8 +157,8 @@ DWORD basetexture_get_lod(IWineD3DBaseTexture *iface)
DWORD basetexture_get_level_count(IWineD3DBaseTexture *iface) DWORD basetexture_get_level_count(IWineD3DBaseTexture *iface)
{ {
IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface; IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
TRACE("(%p) : returning %d\n", This, This->baseTexture.levels); TRACE("iface %p, returning %u.\n", iface, This->baseTexture.level_count);
return This->baseTexture.levels; return This->baseTexture.level_count;
} }
HRESULT basetexture_set_autogen_filter_type(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) HRESULT basetexture_set_autogen_filter_type(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType)
...@@ -301,10 +313,11 @@ HRESULT basetexture_bind(IWineD3DBaseTexture *iface, BOOL srgb, BOOL *set_surfac ...@@ -301,10 +313,11 @@ HRESULT basetexture_bind(IWineD3DBaseTexture *iface, BOOL srgb, BOOL *set_surfac
* relying on the partial GL_ARB_texture_non_power_of_two emulation with texture rectangles * relying on the partial GL_ARB_texture_non_power_of_two emulation with texture rectangles
* (ie, do not care for cond_np2 here, just look for GL_TEXTURE_RECTANGLE_ARB) * (ie, do not care for cond_np2 here, just look for GL_TEXTURE_RECTANGLE_ARB)
*/ */
if(textureDimensions != GL_TEXTURE_RECTANGLE_ARB) { if (textureDimensions != GL_TEXTURE_RECTANGLE_ARB)
TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->baseTexture.levels - 1); {
glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, This->baseTexture.levels - 1); TRACE("Setting GL_TEXTURE_MAX_LEVEL to %u.\n", This->baseTexture.level_count - 1);
checkGLcall("glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, This->baseTexture.levels)"); glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, This->baseTexture.level_count - 1);
checkGLcall("glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, This->baseTexture.level_count)");
} }
if(textureDimensions==GL_TEXTURE_CUBE_MAP_ARB) { if(textureDimensions==GL_TEXTURE_CUBE_MAP_ARB) {
/* Cubemaps are always set to clamp, regardless of the sampler state. */ /* Cubemaps are always set to clamp, regardless of the sampler state. */
...@@ -444,17 +457,18 @@ void basetexture_apply_state_changes(IWineD3DBaseTexture *iface, ...@@ -444,17 +457,18 @@ void basetexture_apply_state_changes(IWineD3DBaseTexture *iface,
glTexParameteri(textureDimensions, GL_TEXTURE_MIN_FILTER, glValue); glTexParameteri(textureDimensions, GL_TEXTURE_MIN_FILTER, glValue);
checkGLcall("glTexParameter GL_TEXTURE_MIN_FILTER, ..."); checkGLcall("glTexParameter GL_TEXTURE_MIN_FILTER, ...");
if(!cond_np2) { if (!cond_np2)
if(gl_tex->states[WINED3DTEXSTA_MIPFILTER] == WINED3DTEXF_NONE) { {
if (gl_tex->states[WINED3DTEXSTA_MIPFILTER] == WINED3DTEXF_NONE)
glValue = This->baseTexture.LOD; glValue = This->baseTexture.LOD;
} else if(gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] >= This->baseTexture.levels) { else if (gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] >= This->baseTexture.level_count)
glValue = This->baseTexture.levels - 1; glValue = This->baseTexture.level_count - 1;
} else if(gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] < This->baseTexture.LOD) { else if (gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] < This->baseTexture.LOD)
/* baseTexture.LOD is already clamped in the setter */ /* baseTexture.LOD is already clamped in the setter */
glValue = This->baseTexture.LOD; glValue = This->baseTexture.LOD;
} else { else
glValue = gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL]; glValue = gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL];
}
/* Note that D3DSAMP_MAXMIPLEVEL specifies the biggest mipmap(default 0), while /* Note that D3DSAMP_MAXMIPLEVEL specifies the biggest mipmap(default 0), while
* GL_TEXTURE_MAX_LEVEL specifies the smallest mimap used(default 1000). * GL_TEXTURE_MAX_LEVEL specifies the smallest mimap used(default 1000).
* So D3DSAMP_MAXMIPLEVEL is the same as GL_TEXTURE_BASE_LEVEL. * So D3DSAMP_MAXMIPLEVEL is the same as GL_TEXTURE_BASE_LEVEL.
......
...@@ -31,11 +31,12 @@ static void cubetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3 ...@@ -31,11 +31,12 @@ static void cubetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3
{ {
/* Override the IWineD3DResource Preload method. */ /* Override the IWineD3DResource Preload method. */
IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface; IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
UINT sub_count = This->baseTexture.level_count * This->baseTexture.layer_count;
IWineD3DDeviceImpl *device = This->resource.device; IWineD3DDeviceImpl *device = This->resource.device;
struct wined3d_context *context = NULL; struct wined3d_context *context = NULL;
unsigned int i, j;
BOOL srgb_mode; BOOL srgb_mode;
BOOL *dirty; BOOL *dirty;
UINT i;
switch (srgb) switch (srgb)
{ {
...@@ -72,19 +73,18 @@ static void cubetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3 ...@@ -72,19 +73,18 @@ static void cubetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3
if (This->resource.format_desc->format == WINED3DFMT_P8_UINT if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
|| This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM) || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
{ {
for (i = 0; i < This->baseTexture.levels; ++i) for (i = 0; i < sub_count; ++i)
{ {
for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z; ++j) IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)This->baseTexture.sub_resources[i];
if (palette9_changed(surface))
{ {
if (palette9_changed((IWineD3DSurfaceImpl *)This->surfaces[j][i])) TRACE("Reloading surface %p because the d3d8/9 palette was changed.\n", surface);
{ /* TODO: This is not necessarily needed with hw palettized texture support. */
TRACE("Reloading surface because the d3d8/9 palette was changed.\n"); IWineD3DSurface_LoadLocation((IWineD3DSurface *)surface, SFLAG_INSYSMEM, NULL);
/* TODO: This is not necessarily needed with hw palettized texture support. */ /* Make sure the texture is reloaded because of the palette change,
IWineD3DSurface_LoadLocation(This->surfaces[j][i], SFLAG_INSYSMEM, NULL); * this kills performance though :( */
/* Make sure the texture is reloaded because of the palette change, IWineD3DSurface_ModifyLocation((IWineD3DSurface *)surface, SFLAG_INTEXTURE, FALSE);
* this kills performance though :( */
IWineD3DSurface_ModifyLocation(This->surfaces[j][i], SFLAG_INTEXTURE, FALSE);
}
} }
} }
} }
...@@ -93,12 +93,9 @@ static void cubetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3 ...@@ -93,12 +93,9 @@ static void cubetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3
* since the last load then reload the surfaces. */ * since the last load then reload the surfaces. */
if (*dirty) if (*dirty)
{ {
for (i = 0; i < This->baseTexture.levels; ++i) for (i = 0; i < sub_count; ++i)
{ {
for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z; ++j) IWineD3DSurface_LoadTexture((IWineD3DSurface *)This->baseTexture.sub_resources[i], srgb_mode);
{
IWineD3DSurface_LoadTexture(This->surfaces[j][i], srgb_mode);
}
} }
} }
else else
...@@ -114,26 +111,24 @@ static void cubetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3 ...@@ -114,26 +111,24 @@ static void cubetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3
static void cubetexture_cleanup(IWineD3DCubeTextureImpl *This) static void cubetexture_cleanup(IWineD3DCubeTextureImpl *This)
{ {
unsigned int i, j; UINT sub_count = This->baseTexture.level_count * This->baseTexture.layer_count;
UINT i;
TRACE("(%p) : Cleaning up.\n", This); TRACE("(%p) : Cleaning up.\n", This);
for (i = 0; i < This->baseTexture.levels; ++i) for (i = 0; i < sub_count; ++i)
{ {
for (j = 0; j < 6; ++j) IWineD3DSurface *surface = (IWineD3DSurface *)This->baseTexture.sub_resources[i];
{
IWineD3DSurface *surface = This->surfaces[j][i];
if (surface) if (surface)
{ {
/* Clean out the texture name we gave to the surface so that the /* Clean out the texture name we gave to the surface so that the
* surface doesn't try and release it. */ * surface doesn't try and release it. */
surface_set_texture_name(surface, 0, TRUE); surface_set_texture_name(surface, 0, TRUE);
surface_set_texture_name(surface, 0, FALSE); surface_set_texture_name(surface, 0, FALSE);
surface_set_texture_target(surface, 0); surface_set_texture_target(surface, 0);
IWineD3DSurface_SetContainer(surface, NULL); IWineD3DSurface_SetContainer(surface, NULL);
IWineD3DSurface_Release(surface); IWineD3DSurface_Release(surface);
}
} }
} }
basetexture_cleanup((IWineD3DBaseTexture *)This); basetexture_cleanup((IWineD3DBaseTexture *)This);
...@@ -207,21 +202,25 @@ static void WINAPI IWineD3DCubeTextureImpl_PreLoad(IWineD3DCubeTexture *iface) { ...@@ -207,21 +202,25 @@ static void WINAPI IWineD3DCubeTextureImpl_PreLoad(IWineD3DCubeTexture *iface) {
cubetexture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY); cubetexture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY);
} }
static void WINAPI IWineD3DCubeTextureImpl_UnLoad(IWineD3DCubeTexture *iface) { static void WINAPI IWineD3DCubeTextureImpl_UnLoad(IWineD3DCubeTexture *iface)
unsigned int i, j; {
IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface; IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
TRACE("(%p)\n", This); UINT sub_count = This->baseTexture.level_count * This->baseTexture.layer_count;
UINT i;
TRACE("iface %p.\n", iface);
/* Unload all the surfaces and reset the texture name. If UnLoad was called on the /* Unload all the surfaces and reset the texture name. If UnLoad was called on the
* surface before, this one will be a NOP and vice versa. Unloading an unloaded * surface before, this one will be a NOP and vice versa. Unloading an unloaded
* surface is fine * surface is fine. */
*/
for (i = 0; i < This->baseTexture.levels; i++) { for (i = 0; i < sub_count; ++i)
for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z ; j++) { {
IWineD3DSurface_UnLoad(This->surfaces[j][i]); IWineD3DSurface *surface = (IWineD3DSurface *)This->baseTexture.sub_resources[i];
surface_set_texture_name(This->surfaces[j][i], 0, TRUE);
surface_set_texture_name(This->surfaces[j][i], 0, FALSE); IWineD3DSurface_UnLoad(surface);
} surface_set_texture_name(surface, 0, TRUE);
surface_set_texture_name(surface, 0, FALSE);
} }
basetexture_unload((IWineD3DBaseTexture *)iface); basetexture_unload((IWineD3DBaseTexture *)iface);
...@@ -281,16 +280,19 @@ static HRESULT WINAPI IWineD3DCubeTextureImpl_BindTexture(IWineD3DCubeTexture *i ...@@ -281,16 +280,19 @@ static HRESULT WINAPI IWineD3DCubeTextureImpl_BindTexture(IWineD3DCubeTexture *i
TRACE("(%p) : relay to BaseTexture\n", This); TRACE("(%p) : relay to BaseTexture\n", This);
hr = basetexture_bind((IWineD3DBaseTexture *)iface, srgb, &set_gl_texture_desc); hr = basetexture_bind((IWineD3DBaseTexture *)iface, srgb, &set_gl_texture_desc);
if (set_gl_texture_desc && SUCCEEDED(hr)) { if (set_gl_texture_desc && SUCCEEDED(hr))
UINT i, j; {
for (i = 0; i < This->baseTexture.levels; ++i) { UINT sub_count = This->baseTexture.level_count * This->baseTexture.layer_count;
for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z; ++j) { UINT i;
if(This->baseTexture.is_srgb) {
surface_set_texture_name(This->surfaces[j][i], This->baseTexture.texture_srgb.name, TRUE); for (i = 0; i < sub_count; ++i)
} else { {
surface_set_texture_name(This->surfaces[j][i], This->baseTexture.texture_rgb.name, FALSE); IWineD3DSurface *surface = (IWineD3DSurface *)This->baseTexture.sub_resources[i];
}
} if (This->baseTexture.is_srgb)
surface_set_texture_name(surface, This->baseTexture.texture_srgb.name, TRUE);
else
surface_set_texture_name(surface, This->baseTexture.texture_rgb.name, FALSE);
} }
} }
...@@ -314,82 +316,120 @@ static BOOL WINAPI IWineD3DCubeTextureImpl_IsCondNP2(IWineD3DCubeTexture *iface) ...@@ -314,82 +316,120 @@ static BOOL WINAPI IWineD3DCubeTextureImpl_IsCondNP2(IWineD3DCubeTexture *iface)
/* ******************************************* /* *******************************************
IWineD3DCubeTexture IWineD3DCubeTexture parts follow IWineD3DCubeTexture IWineD3DCubeTexture parts follow
******************************************* */ ******************************************* */
static HRESULT WINAPI IWineD3DCubeTextureImpl_GetLevelDesc(IWineD3DCubeTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) { static HRESULT WINAPI IWineD3DCubeTextureImpl_GetLevelDesc(IWineD3DCubeTexture *iface,
IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface; UINT level, WINED3DSURFACE_DESC *desc)
{
IWineD3DCubeTextureImpl *texture = (IWineD3DCubeTextureImpl *)iface;
TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
if (Level < This->baseTexture.levels) { if (level >= texture->baseTexture.level_count)
TRACE("(%p) level (%d)\n", This, Level); {
return IWineD3DSurface_GetDesc(This->surfaces[0][Level], pDesc); WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
return WINED3DERR_INVALIDCALL;
} }
WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
return WINED3DERR_INVALIDCALL; return IWineD3DSurface_GetDesc((IWineD3DSurface *)texture->baseTexture.sub_resources[level], desc);
} }
static HRESULT WINAPI IWineD3DCubeTextureImpl_GetCubeMapSurface(IWineD3DCubeTexture *iface, WINED3DCUBEMAP_FACES FaceType, UINT Level, IWineD3DSurface** ppCubeMapSurface) { static HRESULT WINAPI IWineD3DCubeTextureImpl_GetCubeMapSurface(IWineD3DCubeTexture *iface,
IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface; WINED3DCUBEMAP_FACES face, UINT level, IWineD3DSurface **surface)
HRESULT hr = WINED3DERR_INVALIDCALL; {
IWineD3DCubeTextureImpl *texture = (IWineD3DCubeTextureImpl *)iface;
UINT idx = face * texture->baseTexture.level_count + level;
if (Level < This->baseTexture.levels && FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) { TRACE("iface %p, face %u, level %u, surface %p.\n",
*ppCubeMapSurface = This->surfaces[FaceType][Level]; iface, face, level, surface);
IWineD3DSurface_AddRef(*ppCubeMapSurface);
hr = WINED3D_OK; if (level >= texture->baseTexture.level_count)
{
WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
return WINED3DERR_INVALIDCALL;
} }
if (WINED3D_OK == hr) {
TRACE("(%p) -> faceType(%d) level(%d) returning surface@%p\n", This, FaceType, Level, This->surfaces[FaceType][Level]); if (face >= texture->baseTexture.layer_count)
} else { {
WARN("(%p) level(%d) overflow Levels(%d) Or FaceType(%d)\n", This, Level, This->baseTexture.levels, FaceType); WARN("face %u >= layer_count %u.\n", face, texture->baseTexture.layer_count);
return WINED3DERR_INVALIDCALL;
} }
return hr; *surface = (IWineD3DSurface *)texture->baseTexture.sub_resources[idx];
IWineD3DSurface_AddRef(*surface);
TRACE("Returning surface %p.\n", *surface);
return WINED3D_OK;
} }
static HRESULT WINAPI IWineD3DCubeTextureImpl_LockRect(IWineD3DCubeTexture *iface, WINED3DCUBEMAP_FACES FaceType, UINT Level, WINED3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) { static HRESULT WINAPI IWineD3DCubeTextureImpl_LockRect(IWineD3DCubeTexture *iface,
HRESULT hr = WINED3DERR_INVALIDCALL; WINED3DCUBEMAP_FACES face, UINT level, WINED3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags)
IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface; {
IWineD3DCubeTextureImpl *texture = (IWineD3DCubeTextureImpl *)iface;
UINT idx = face * texture->baseTexture.level_count + level;
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 < This->baseTexture.levels && FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) { if (level >= texture->baseTexture.level_count)
hr = IWineD3DSurface_LockRect(This->surfaces[FaceType][Level], pLockedRect, pRect, Flags); {
WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
return WINED3DERR_INVALIDCALL;
} }
if (WINED3D_OK == hr) { if (face >= texture->baseTexture.layer_count)
TRACE("(%p) -> faceType(%d) level(%d) returning memory@%p success(%u)\n", This, FaceType, Level, pLockedRect->pBits, hr); {
} else { WARN("face %u >= layer_count %u.\n", face, texture->baseTexture.layer_count);
WARN("(%p) level(%d) overflow Levels(%d) Or FaceType(%d)\n", This, Level, This->baseTexture.levels, FaceType); return WINED3DERR_INVALIDCALL;
} }
return hr; return IWineD3DSurface_LockRect((IWineD3DSurface *)texture->baseTexture.sub_resources[idx],
locked_rect, rect, flags);
} }
static HRESULT WINAPI IWineD3DCubeTextureImpl_UnlockRect(IWineD3DCubeTexture *iface, WINED3DCUBEMAP_FACES FaceType, UINT Level) { static HRESULT WINAPI IWineD3DCubeTextureImpl_UnlockRect(IWineD3DCubeTexture *iface,
HRESULT hr = WINED3DERR_INVALIDCALL; WINED3DCUBEMAP_FACES face, UINT level)
IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface; {
IWineD3DCubeTextureImpl *texture = (IWineD3DCubeTextureImpl *)iface;
UINT idx = face * texture->baseTexture.level_count + level;
TRACE("iface %p, face %u, level %u.\n",
iface, face, level);
if (Level < This->baseTexture.levels && FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) { if (level >= texture->baseTexture.level_count)
hr = IWineD3DSurface_UnlockRect(This->surfaces[FaceType][Level]); {
WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
return WINED3DERR_INVALIDCALL;
} }
if (WINED3D_OK == hr) { if (face >= texture->baseTexture.layer_count)
TRACE("(%p) -> faceType(%d) level(%d) success(%u)\n", This, FaceType, Level, hr); {
} else { WARN("face %u >= layer_count %u.\n", face, texture->baseTexture.layer_count);
WARN("(%p) level(%d) overflow Levels(%d) Or FaceType(%d)\n", This, Level, This->baseTexture.levels, FaceType); return WINED3DERR_INVALIDCALL;
} }
return hr;
return IWineD3DSurface_UnlockRect((IWineD3DSurface *)texture->baseTexture.sub_resources[idx]);
} }
static HRESULT WINAPI IWineD3DCubeTextureImpl_AddDirtyRect(IWineD3DCubeTexture *iface, WINED3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) { static HRESULT WINAPI IWineD3DCubeTextureImpl_AddDirtyRect(IWineD3DCubeTexture *iface,
HRESULT hr = WINED3DERR_INVALIDCALL; WINED3DCUBEMAP_FACES face, const RECT *dirty_rect)
IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface; {
This->baseTexture.texture_rgb.dirty = TRUE; IWineD3DCubeTextureImpl *texture = (IWineD3DCubeTextureImpl *)iface;
This->baseTexture.texture_srgb.dirty = TRUE; UINT idx = face * texture->baseTexture.level_count;
TRACE("(%p) : dirtyfication of faceType(%d) Level (0)\n", This, FaceType);
if (FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) { TRACE("iface %p, face %u, dirty_rect %s.\n",
surface_add_dirty_rect(This->surfaces[FaceType][0], pDirtyRect); iface, face, wine_dbgstr_rect(dirty_rect));
hr = WINED3D_OK;
} else { if (face >= texture->baseTexture.layer_count)
WARN("(%p) overflow FaceType(%d)\n", This, FaceType); {
WARN("face %u >= layer_count %u.\n", face, texture->baseTexture.layer_count);
return WINED3DERR_INVALIDCALL;
} }
return hr;
texture->baseTexture.texture_rgb.dirty = TRUE;
texture->baseTexture.texture_srgb.dirty = TRUE;
surface_add_dirty_rect((IWineD3DSurface *)texture->baseTexture.sub_resources[idx], dirty_rect);
return WINED3D_OK;
} }
static const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl = static const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl =
...@@ -478,8 +518,8 @@ HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UIN ...@@ -478,8 +518,8 @@ HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UIN
texture->lpVtbl = &IWineD3DCubeTexture_Vtbl; texture->lpVtbl = &IWineD3DCubeTexture_Vtbl;
hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_CUBETEXTURE, hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, 6, levels,
device, 0, usage, format_desc, pool, parent, parent_ops); WINED3DRTYPE_CUBETEXTURE, device, 0, usage, format_desc, pool, parent, parent_ops);
if (FAILED(hr)) if (FAILED(hr))
{ {
WARN("Failed to initialize basetexture, returning %#x\n", hr); WARN("Failed to initialize basetexture, returning %#x\n", hr);
...@@ -510,7 +550,7 @@ HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UIN ...@@ -510,7 +550,7 @@ HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UIN
/* Generate all the surfaces. */ /* Generate all the surfaces. */
tmp_w = edge_length; tmp_w = edge_length;
for (i = 0; i < texture->baseTexture.levels; ++i) for (i = 0; i < texture->baseTexture.level_count; ++i)
{ {
/* Create the 6 faces. */ /* Create the 6 faces. */
for (j = 0; j < 6; ++j) for (j = 0; j < 6; ++j)
...@@ -524,20 +564,22 @@ HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UIN ...@@ -524,20 +564,22 @@ HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UIN
GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
}; };
UINT idx = j * texture->baseTexture.level_count + i;
IWineD3DSurface *surface;
hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_w, hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_w,
format, usage, pool, i /* Level */, j, &texture->surfaces[j][i]); format, usage, pool, i /* Level */, j, &surface);
if (FAILED(hr)) if (FAILED(hr))
{ {
FIXME("(%p) Failed to create surface, hr %#x.\n", texture, hr); FIXME("(%p) Failed to create surface, hr %#x.\n", texture, hr);
texture->surfaces[j][i] = NULL;
cubetexture_cleanup(texture); cubetexture_cleanup(texture);
return hr; return hr;
} }
IWineD3DSurface_SetContainer(texture->surfaces[j][i], (IWineD3DBase *)texture); IWineD3DSurface_SetContainer(surface, (IWineD3DBase *)texture);
TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[j][i]); surface_set_texture_target(surface, cube_targets[j]);
surface_set_texture_target(texture->surfaces[j][i], cube_targets[j]); texture->baseTexture.sub_resources[idx] = (IWineD3DResourceImpl *)surface;
TRACE("Created surface level %u @ %p.\n", i, surface);
} }
tmp_w = max(1, tmp_w >> 1); tmp_w = max(1, tmp_w >> 1);
} }
......
...@@ -479,9 +479,8 @@ static void state_alpha(DWORD state, IWineD3DStateBlockImpl *stateblock, struct ...@@ -479,9 +479,8 @@ static void state_alpha(DWORD state, IWineD3DStateBlockImpl *stateblock, struct
if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB) if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB)
{ {
IWineD3DSurfaceImpl *surf; IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)stateblock->textures[0];
IWineD3DSurfaceImpl *surf = (IWineD3DSurfaceImpl *)texture->baseTexture.sub_resources[0];
surf = (IWineD3DSurfaceImpl *) ((IWineD3DTextureImpl *)stateblock->textures[0])->surfaces[0];
if (surf->CKeyFlags & WINEDDSD_CKSRCBLT) if (surf->CKeyFlags & WINEDDSD_CKSRCBLT)
{ {
...@@ -3097,9 +3096,8 @@ void tex_alphaop(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d ...@@ -3097,9 +3096,8 @@ void tex_alphaop(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d
if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB) if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB)
{ {
IWineD3DSurfaceImpl *surf; IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)stateblock->textures[0];
IWineD3DSurfaceImpl *surf = (IWineD3DSurfaceImpl *)texture->baseTexture.sub_resources[0];
surf = (IWineD3DSurfaceImpl *) ((IWineD3DTextureImpl *) stateblock->textures[0])->surfaces[0];
if (surf->CKeyFlags & WINEDDSD_CKSRCBLT && !surf->resource.format_desc->alpha_mask) if (surf->CKeyFlags & WINEDDSD_CKSRCBLT && !surf->resource.format_desc->alpha_mask)
{ {
......
...@@ -69,15 +69,16 @@ static void texture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRG ...@@ -69,15 +69,16 @@ static void texture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRG
if (This->resource.format_desc->format == WINED3DFMT_P8_UINT if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
|| This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM) || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
{ {
for (i = 0; i < This->baseTexture.levels; ++i) for (i = 0; i < This->baseTexture.level_count; ++i)
{ {
if (palette9_changed((IWineD3DSurfaceImpl *)This->surfaces[i])) IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)This->baseTexture.sub_resources[i];
if (palette9_changed(surface))
{ {
TRACE("Reloading surface because the d3d8/9 palette was changed.\n"); TRACE("Reloading surface because the d3d8/9 palette was changed.\n");
/* TODO: This is not necessarily needed with hw palettized texture support. */ /* TODO: This is not necessarily needed with hw palettized texture support. */
IWineD3DSurface_LoadLocation(This->surfaces[i], SFLAG_INSYSMEM, NULL); IWineD3DSurface_LoadLocation((IWineD3DSurface *)surface, SFLAG_INSYSMEM, NULL);
/* Make sure the texture is reloaded because of the palette change, this kills performance though :( */ /* Make sure the texture is reloaded because of the palette change, this kills performance though :( */
IWineD3DSurface_ModifyLocation(This->surfaces[i], SFLAG_INTEXTURE, FALSE); IWineD3DSurface_ModifyLocation((IWineD3DSurface *)surface, SFLAG_INTEXTURE, FALSE);
} }
} }
} }
...@@ -86,9 +87,9 @@ static void texture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRG ...@@ -86,9 +87,9 @@ static void texture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRG
* since the last load then reload the surfaces. */ * since the last load then reload the surfaces. */
if (*dirty) if (*dirty)
{ {
for (i = 0; i < This->baseTexture.levels; ++i) for (i = 0; i < This->baseTexture.level_count; ++i)
{ {
IWineD3DSurface_LoadTexture(This->surfaces[i], srgb_mode); IWineD3DSurface_LoadTexture((IWineD3DSurface *)This->baseTexture.sub_resources[i], srgb_mode);
} }
} }
else else
...@@ -108,17 +109,18 @@ static void texture_cleanup(IWineD3DTextureImpl *This) ...@@ -108,17 +109,18 @@ static void texture_cleanup(IWineD3DTextureImpl *This)
TRACE("(%p) : Cleaning up\n", This); TRACE("(%p) : Cleaning up\n", This);
for (i = 0; i < This->baseTexture.levels; ++i) for (i = 0; i < This->baseTexture.level_count; ++i)
{ {
if (This->surfaces[i]) IWineD3DSurface *surface = (IWineD3DSurface *)This->baseTexture.sub_resources[i];
if (surface)
{ {
/* Clean out the texture name we gave to the surface so that the /* Clean out the texture name we gave to the surface so that the
* surface doesn't try and release it */ * surface doesn't try and release it */
surface_set_texture_name(This->surfaces[i], 0, TRUE); surface_set_texture_name(surface, 0, TRUE);
surface_set_texture_name(This->surfaces[i], 0, FALSE); surface_set_texture_name(surface, 0, FALSE);
surface_set_texture_target(This->surfaces[i], 0); surface_set_texture_target(surface, 0);
IWineD3DSurface_SetContainer(This->surfaces[i], 0); IWineD3DSurface_SetContainer(surface, NULL);
IWineD3DSurface_Release(This->surfaces[i]); IWineD3DSurface_Release(surface);
} }
} }
...@@ -204,10 +206,12 @@ static void WINAPI IWineD3DTextureImpl_UnLoad(IWineD3DTexture *iface) { ...@@ -204,10 +206,12 @@ static void WINAPI IWineD3DTextureImpl_UnLoad(IWineD3DTexture *iface) {
* surface before, this one will be a NOP and vice versa. Unloading an unloaded * surface before, this one will be a NOP and vice versa. Unloading an unloaded
* surface is fine * surface is fine
*/ */
for (i = 0; i < This->baseTexture.levels; i++) { for (i = 0; i < This->baseTexture.level_count; ++i)
IWineD3DSurface_UnLoad(This->surfaces[i]); {
surface_set_texture_name(This->surfaces[i], 0, FALSE); /* Delete rgb name */ IWineD3DSurface *surface = (IWineD3DSurface *)This->baseTexture.sub_resources[i];
surface_set_texture_name(This->surfaces[i], 0, TRUE); /* delete srgb name */ IWineD3DSurface_UnLoad(surface);
surface_set_texture_name(surface, 0, FALSE); /* Delete rgb name */
surface_set_texture_name(surface, 0, TRUE); /* delete srgb name */
} }
basetexture_unload((IWineD3DBaseTexture *)iface); basetexture_unload((IWineD3DBaseTexture *)iface);
...@@ -276,14 +280,20 @@ static HRESULT WINAPI IWineD3DTextureImpl_BindTexture(IWineD3DTexture *iface, BO ...@@ -276,14 +280,20 @@ static HRESULT WINAPI IWineD3DTextureImpl_BindTexture(IWineD3DTexture *iface, BO
gl_tex = &This->baseTexture.texture_rgb; gl_tex = &This->baseTexture.texture_rgb;
} }
for (i = 0; i < This->baseTexture.levels; ++i) { for (i = 0; i < This->baseTexture.level_count; ++i)
surface_set_texture_name(This->surfaces[i], gl_tex->name, This->baseTexture.is_srgb); {
IWineD3DSurface *surface = (IWineD3DSurface *)This->baseTexture.sub_resources[i];
surface_set_texture_name(surface, gl_tex->name, This->baseTexture.is_srgb);
} }
/* Conditinal non power of two textures use a different clamping default. If we're using the GL_WINE_normalized_texrect
* partial driver emulation, we're dealing with a GL_TEXTURE_2D texture which has the address mode set to repeat - something /* Conditinal non power of two textures use a different clamping
* that prevents us from hitting the accelerated codepath. Thus manually set the GL state. The same applies to filtering. * default. If we're using the GL_WINE_normalized_texrect partial
* Even if the texture has only one mip level, the default LINEAR_MIPMAP_LINEAR filter causes a SW fallback on macos. * driver emulation, we're dealing with a GL_TEXTURE_2D texture which
*/ * has the address mode set to repeat - something that prevents us
* from hitting the accelerated codepath. Thus manually set the GL
* state. The same applies to filtering. Even if the texture has only
* one mip level, the default LINEAR_MIPMAP_LINEAR filter causes a SW
* fallback on macos. */
if(IWineD3DBaseTexture_IsCondNP2(iface)) { if(IWineD3DBaseTexture_IsCondNP2(iface)) {
ENTER_GL(); ENTER_GL();
glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(IWineD3DTexture_GetTextureDimensions(iface), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
...@@ -326,11 +336,12 @@ static BOOL WINAPI IWineD3DTextureImpl_IsCondNP2(IWineD3DTexture *iface) { ...@@ -326,11 +336,12 @@ static BOOL WINAPI IWineD3DTextureImpl_IsCondNP2(IWineD3DTexture *iface) {
static HRESULT WINAPI IWineD3DTextureImpl_GetLevelDesc(IWineD3DTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) { static HRESULT WINAPI IWineD3DTextureImpl_GetLevelDesc(IWineD3DTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface; IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
if (Level < This->baseTexture.levels) { if (Level < This->baseTexture.level_count)
{
TRACE("(%p) Level (%d)\n", This, Level); TRACE("(%p) Level (%d)\n", This, Level);
return IWineD3DSurface_GetDesc(This->surfaces[Level], pDesc); return IWineD3DSurface_GetDesc((IWineD3DSurface *)This->baseTexture.sub_resources[Level], pDesc);
} }
WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels); WARN("(%p) level %u >= level_count %u.\n", This, Level, This->baseTexture.level_count);
return WINED3DERR_INVALIDCALL; return WINED3DERR_INVALIDCALL;
} }
...@@ -338,14 +349,15 @@ static HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface ...@@ -338,14 +349,15 @@ static HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface
IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface; IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
HRESULT hr = WINED3DERR_INVALIDCALL; HRESULT hr = WINED3DERR_INVALIDCALL;
if (Level < This->baseTexture.levels) { if (Level < This->baseTexture.level_count)
*ppSurfaceLevel = This->surfaces[Level]; {
IWineD3DSurface_AddRef(This->surfaces[Level]); *ppSurfaceLevel = (IWineD3DSurface *)This->baseTexture.sub_resources[Level];
IWineD3DSurface_AddRef(*ppSurfaceLevel);
hr = WINED3D_OK; hr = WINED3D_OK;
TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level); TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level);
} }
if (WINED3D_OK != hr) { if (WINED3D_OK != hr) {
WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels); WARN("(%p) level %u >= level_count %u.\n", This, Level, This->baseTexture.level_count);
*ppSurfaceLevel = NULL; /* Just to be on the safe side.. */ *ppSurfaceLevel = NULL; /* Just to be on the safe side.. */
} }
return hr; return hr;
...@@ -356,13 +368,15 @@ static HRESULT WINAPI IWineD3DTextureImpl_LockRect(IWineD3DTexture *iface, UINT ...@@ -356,13 +368,15 @@ static HRESULT WINAPI IWineD3DTextureImpl_LockRect(IWineD3DTexture *iface, UINT
IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface; IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
HRESULT hr = WINED3DERR_INVALIDCALL; HRESULT hr = WINED3DERR_INVALIDCALL;
if (Level < This->baseTexture.levels) { if (Level < This->baseTexture.level_count)
hr = IWineD3DSurface_LockRect(This->surfaces[Level], pLockedRect, pRect, Flags); {
IWineD3DSurface *surface = (IWineD3DSurface *)This->baseTexture.sub_resources[Level];
hr = IWineD3DSurface_LockRect(surface, pLockedRect, pRect, Flags);
} }
if (WINED3D_OK == hr) { if (WINED3D_OK == hr) {
TRACE("(%p) Level (%d) success\n", This, Level); TRACE("(%p) Level (%d) success\n", This, Level);
} else { } else {
WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels); WARN("(%p) level %u >= level_count %u.\n", This, Level, This->baseTexture.level_count);
} }
return hr; return hr;
...@@ -372,13 +386,15 @@ static HRESULT WINAPI IWineD3DTextureImpl_UnlockRect(IWineD3DTexture *iface, UIN ...@@ -372,13 +386,15 @@ static HRESULT WINAPI IWineD3DTextureImpl_UnlockRect(IWineD3DTexture *iface, UIN
IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface; IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
HRESULT hr = WINED3DERR_INVALIDCALL; HRESULT hr = WINED3DERR_INVALIDCALL;
if (Level < This->baseTexture.levels) { if (Level < This->baseTexture.level_count)
hr = IWineD3DSurface_UnlockRect(This->surfaces[Level]); {
IWineD3DSurface *surface = (IWineD3DSurface *)This->baseTexture.sub_resources[Level];
hr = IWineD3DSurface_UnlockRect(surface);
} }
if ( WINED3D_OK == hr) { if ( WINED3D_OK == hr) {
TRACE("(%p) Level (%d) success\n", This, Level); TRACE("(%p) Level (%d) success\n", This, Level);
} else { } else {
WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels); WARN("(%p) level %u >= level_count %u.\n", This, Level, This->baseTexture.level_count);
} }
return hr; return hr;
} }
...@@ -388,7 +404,7 @@ static HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, C ...@@ -388,7 +404,7 @@ static HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, C
This->baseTexture.texture_rgb.dirty = TRUE; This->baseTexture.texture_rgb.dirty = TRUE;
This->baseTexture.texture_srgb.dirty = TRUE; This->baseTexture.texture_srgb.dirty = TRUE;
TRACE("(%p) : dirtyfication of surface Level (0)\n", This); TRACE("(%p) : dirtyfication of surface Level (0)\n", This);
surface_add_dirty_rect(This->surfaces[0], pDirtyRect); surface_add_dirty_rect((IWineD3DSurface *)This->baseTexture.sub_resources[0], pDirtyRect);
return WINED3D_OK; return WINED3D_OK;
} }
...@@ -497,8 +513,8 @@ HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT ...@@ -497,8 +513,8 @@ HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT
texture->lpVtbl = &IWineD3DTexture_Vtbl; texture->lpVtbl = &IWineD3DTexture_Vtbl;
hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_TEXTURE, hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, 1, levels,
device, 0, usage, format_desc, pool, parent, parent_ops); WINED3DRTYPE_TEXTURE, device, 0, usage, format_desc, pool, parent, parent_ops);
if (FAILED(hr)) if (FAILED(hr))
{ {
WARN("Failed to initialize basetexture, returning %#x.\n", hr); WARN("Failed to initialize basetexture, returning %#x.\n", hr);
...@@ -565,22 +581,24 @@ HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT ...@@ -565,22 +581,24 @@ HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT
/* Generate all the surfaces. */ /* Generate all the surfaces. */
tmp_w = width; tmp_w = width;
tmp_h = height; tmp_h = height;
for (i = 0; i < texture->baseTexture.levels; ++i) for (i = 0; i < texture->baseTexture.level_count; ++i)
{ {
IWineD3DSurface *surface;
/* Use the callback to create the texture surface. */ /* Use the callback to create the texture surface. */
hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format, hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format,
usage, pool, i, WINED3DCUBEMAP_FACE_POSITIVE_X, &texture->surfaces[i]); usage, pool, i, 0, &surface);
if (FAILED(hr)) if (FAILED(hr))
{ {
FIXME("Failed to create surface %p, hr %#x\n", texture, hr); FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
texture->surfaces[i] = NULL;
texture_cleanup(texture); texture_cleanup(texture);
return hr; return hr;
} }
IWineD3DSurface_SetContainer(texture->surfaces[i], (IWineD3DBase *)texture); IWineD3DSurface_SetContainer(surface, (IWineD3DBase *)texture);
TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[i]); surface_set_texture_target(surface, texture->target);
surface_set_texture_target(texture->surfaces[i], texture->target); texture->baseTexture.sub_resources[i] = (IWineD3DResourceImpl *)surface;
TRACE("Created surface level %u @ %p.\n", i, surface);
/* Calculate the next mipmap level. */ /* Calculate the next mipmap level. */
tmp_w = max(1, tmp_w >> 1); tmp_w = max(1, tmp_w >> 1);
tmp_h = max(1, tmp_h >> 1); tmp_h = max(1, tmp_h >> 1);
......
...@@ -2771,8 +2771,8 @@ void gen_ffp_frag_op(IWineD3DStateBlockImpl *stateblock, struct ffp_frag_setting ...@@ -2771,8 +2771,8 @@ void gen_ffp_frag_op(IWineD3DStateBlockImpl *stateblock, struct ffp_frag_setting
if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB) if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB)
{ {
IWineD3DSurfaceImpl *surf; IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)stateblock->textures[0];
surf = (IWineD3DSurfaceImpl *) ((IWineD3DTextureImpl *) stateblock->textures[0])->surfaces[0]; IWineD3DSurfaceImpl *surf = (IWineD3DSurfaceImpl *)texture->baseTexture.sub_resources[0];
if (surf->CKeyFlags & WINEDDSD_CKSRCBLT && !surf->resource.format_desc->alpha_mask) if (surf->CKeyFlags & WINEDDSD_CKSRCBLT && !surf->resource.format_desc->alpha_mask)
{ {
......
...@@ -51,17 +51,19 @@ static void volumetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINE ...@@ -51,17 +51,19 @@ static void volumetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINE
* since the last load then reload the volumes. */ * since the last load then reload the volumes. */
if (This->baseTexture.texture_rgb.dirty) if (This->baseTexture.texture_rgb.dirty)
{ {
for (i = 0; i < This->baseTexture.levels; ++i) for (i = 0; i < This->baseTexture.level_count; ++i)
{ {
IWineD3DVolume_LoadTexture(This->volumes[i], i, srgb_mode); IWineD3DVolume *volume = (IWineD3DVolume *)This->baseTexture.sub_resources[i];
IWineD3DVolume_LoadTexture(volume, i, srgb_mode);
} }
} }
else if (srgb_was_toggled) else if (srgb_was_toggled)
{ {
for (i = 0; i < This->baseTexture.levels; ++i) for (i = 0; i < This->baseTexture.level_count; ++i)
{ {
volume_add_dirty_box(This->volumes[i], NULL); IWineD3DVolume *volume = (IWineD3DVolume *)This->baseTexture.sub_resources[i];
IWineD3DVolume_LoadTexture(This->volumes[i], i, srgb_mode); volume_add_dirty_box(volume, NULL);
IWineD3DVolume_LoadTexture(volume, i, srgb_mode);
} }
} }
else else
...@@ -81,9 +83,9 @@ static void volumetexture_cleanup(IWineD3DVolumeTextureImpl *This) ...@@ -81,9 +83,9 @@ static void volumetexture_cleanup(IWineD3DVolumeTextureImpl *This)
TRACE("(%p) : Cleaning up.\n", This); TRACE("(%p) : Cleaning up.\n", This);
for (i = 0; i < This->baseTexture.levels; ++i) for (i = 0; i < This->baseTexture.level_count; ++i)
{ {
IWineD3DVolume *volume = This->volumes[i]; IWineD3DVolume *volume = (IWineD3DVolume *)This->baseTexture.sub_resources[i];
if (volume) if (volume)
{ {
...@@ -172,8 +174,9 @@ static void WINAPI IWineD3DVolumeTextureImpl_UnLoad(IWineD3DVolumeTexture *iface ...@@ -172,8 +174,9 @@ static void WINAPI IWineD3DVolumeTextureImpl_UnLoad(IWineD3DVolumeTexture *iface
* surface before, this one will be a NOP and vice versa. Unloading an unloaded * surface before, this one will be a NOP and vice versa. Unloading an unloaded
* surface is fine * surface is fine
*/ */
for (i = 0; i < This->baseTexture.levels; i++) { for (i = 0; i < This->baseTexture.level_count; ++i)
IWineD3DVolume_UnLoad(This->volumes[i]); {
IWineD3DVolume_UnLoad((IWineD3DVolume *)This->baseTexture.sub_resources[i]);
} }
basetexture_unload((IWineD3DBaseTexture *)iface); basetexture_unload((IWineD3DBaseTexture *)iface);
...@@ -250,65 +253,85 @@ static BOOL WINAPI IWineD3DVolumeTextureImpl_IsCondNP2(IWineD3DVolumeTexture *if ...@@ -250,65 +253,85 @@ static BOOL WINAPI IWineD3DVolumeTextureImpl_IsCondNP2(IWineD3DVolumeTexture *if
/* ******************************************* /* *******************************************
IWineD3DVolumeTexture IWineD3DVolumeTexture parts follow IWineD3DVolumeTexture IWineD3DVolumeTexture parts follow
******************************************* */ ******************************************* */
static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetLevelDesc(IWineD3DVolumeTexture *iface, UINT Level,WINED3DVOLUME_DESC *pDesc) { static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetLevelDesc(IWineD3DVolumeTexture *iface,
IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface; UINT level, WINED3DVOLUME_DESC *desc)
if (Level < This->baseTexture.levels) { {
TRACE("(%p) Level (%d)\n", This, Level); IWineD3DVolumeTextureImpl *texture = (IWineD3DVolumeTextureImpl *)iface;
return IWineD3DVolume_GetDesc(This->volumes[Level], pDesc);
} else { TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
WARN("(%p) Level (%d)\n", This, Level);
if (level >= texture->baseTexture.level_count)
{
WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
return WINED3DERR_INVALIDCALL;
} }
return WINED3D_OK;
return IWineD3DVolume_GetDesc((IWineD3DVolume *)texture->baseTexture.sub_resources[level], desc);
} }
static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetVolumeLevel(IWineD3DVolumeTexture *iface, UINT Level, IWineD3DVolume** ppVolumeLevel) {
IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface; static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetVolumeLevel(IWineD3DVolumeTexture *iface,
if (Level < This->baseTexture.levels) { UINT level, IWineD3DVolume **volume)
*ppVolumeLevel = This->volumes[Level]; {
IWineD3DVolume_AddRef(*ppVolumeLevel); IWineD3DVolumeTextureImpl *texture = (IWineD3DVolumeTextureImpl *)iface;
TRACE("(%p) -> level(%d) returning volume@%p\n", This, Level, *ppVolumeLevel);
} else { TRACE("iface %p, level %u, volume %p.\n", iface, level, volume);
WARN("(%p) Level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
return WINED3DERR_INVALIDCALL; if (level >= texture->baseTexture.level_count)
{
WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
return WINED3DERR_INVALIDCALL;
} }
*volume = (IWineD3DVolume *)texture->baseTexture.sub_resources[level];
IWineD3DVolume_AddRef(*volume);
TRACE("Returning volume %p.\n", *volume);
return WINED3D_OK; return WINED3D_OK;
} }
static HRESULT WINAPI IWineD3DVolumeTextureImpl_LockBox(IWineD3DVolumeTexture *iface, UINT Level, WINED3DLOCKED_BOX* pLockedVolume, CONST WINED3DBOX* pBox, DWORD Flags) {
HRESULT hr;
IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
if (Level < This->baseTexture.levels) { static HRESULT WINAPI IWineD3DVolumeTextureImpl_LockBox(IWineD3DVolumeTexture *iface,
hr = IWineD3DVolume_LockBox(This->volumes[Level], pLockedVolume, pBox, Flags); UINT level, WINED3DLOCKED_BOX *locked_box, const WINED3DBOX *box, DWORD flags)
TRACE("(%p) Level (%d) success(%u)\n", This, Level, hr); {
IWineD3DVolumeTextureImpl *texture = (IWineD3DVolumeTextureImpl *)iface;
} else { TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels); iface, level, locked_box, box, flags);
return WINED3DERR_INVALIDCALL;
if (level >= texture->baseTexture.level_count)
{
WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
return WINED3DERR_INVALIDCALL;
} }
return hr;
return IWineD3DVolume_LockBox((IWineD3DVolume *)texture->baseTexture.sub_resources[level], locked_box, box, flags);
} }
static HRESULT WINAPI IWineD3DVolumeTextureImpl_UnlockBox(IWineD3DVolumeTexture *iface, UINT Level) { static HRESULT WINAPI IWineD3DVolumeTextureImpl_UnlockBox(IWineD3DVolumeTexture *iface, UINT level)
HRESULT hr; {
IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface; IWineD3DVolumeTextureImpl *texture = (IWineD3DVolumeTextureImpl *)iface;
if (Level < This->baseTexture.levels) { TRACE("iface %p, level %u.\n", iface, level);
hr = IWineD3DVolume_UnlockBox(This->volumes[Level]);
TRACE("(%p) -> level(%d) success(%u)\n", This, Level, hr);
} else { if (level >= texture->baseTexture.level_count)
FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels); {
return WINED3DERR_INVALIDCALL; WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
return WINED3DERR_INVALIDCALL;
} }
return hr;
return IWineD3DVolume_UnlockBox((IWineD3DVolume *)texture->baseTexture.sub_resources[level]);
} }
static HRESULT WINAPI IWineD3DVolumeTextureImpl_AddDirtyBox(IWineD3DVolumeTexture *iface, CONST WINED3DBOX* pDirtyBox) { static HRESULT WINAPI IWineD3DVolumeTextureImpl_AddDirtyBox(IWineD3DVolumeTexture *iface, const WINED3DBOX *dirty_box)
IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface; {
This->baseTexture.texture_rgb.dirty = TRUE; IWineD3DVolumeTextureImpl *texture = (IWineD3DVolumeTextureImpl *)iface;
This->baseTexture.texture_srgb.dirty = TRUE;
TRACE("(%p) : dirtyfication of volume Level (0)\n", This); TRACE("iface %p, dirty_box %p.\n", iface, dirty_box);
volume_add_dirty_box(This->volumes[0], pDirtyBox);
texture->baseTexture.texture_rgb.dirty = TRUE;
texture->baseTexture.texture_srgb.dirty = TRUE;
volume_add_dirty_box((IWineD3DVolume *)texture->baseTexture.sub_resources[0], dirty_box);
return WINED3D_OK; return WINED3D_OK;
} }
...@@ -399,8 +422,8 @@ HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT ...@@ -399,8 +422,8 @@ HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT
texture->lpVtbl = &IWineD3DVolumeTexture_Vtbl; texture->lpVtbl = &IWineD3DVolumeTexture_Vtbl;
hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_VOLUMETEXTURE, hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, 1, levels,
device, 0, usage, format_desc, pool, parent, parent_ops); WINED3DRTYPE_VOLUMETEXTURE, device, 0, usage, format_desc, pool, parent, parent_ops);
if (FAILED(hr)) if (FAILED(hr))
{ {
WARN("Failed to initialize basetexture, returning %#x.\n", hr); WARN("Failed to initialize basetexture, returning %#x.\n", hr);
...@@ -418,21 +441,23 @@ HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT ...@@ -418,21 +441,23 @@ HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT
tmp_h = height; tmp_h = height;
tmp_d = depth; tmp_d = depth;
for (i = 0; i < texture->baseTexture.levels; ++i) for (i = 0; i < texture->baseTexture.level_count; ++i)
{ {
IWineD3DVolume *volume;
/* Create the volume. */ /* Create the volume. */
hr = IWineD3DDeviceParent_CreateVolume(device->device_parent, parent, hr = IWineD3DDeviceParent_CreateVolume(device->device_parent, parent,
tmp_w, tmp_h, tmp_d, format, pool, usage, &texture->volumes[i]); tmp_w, tmp_h, tmp_d, format, pool, 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);
texture->volumes[i] = NULL;
volumetexture_cleanup(texture); volumetexture_cleanup(texture);
return hr; return hr;
} }
/* Set its container to this texture. */ /* Set its container to this texture. */
IWineD3DVolume_SetContainer(texture->volumes[i], (IWineD3DBase *)texture); IWineD3DVolume_SetContainer(volume, (IWineD3DBase *)texture);
texture->baseTexture.sub_resources[i] = (IWineD3DResourceImpl *)volume;
/* Calculate the next mipmap level. */ /* Calculate the next mipmap level. */
tmp_w = max(1, tmp_w >> 1); tmp_w = max(1, tmp_w >> 1);
......
...@@ -1860,7 +1860,9 @@ struct gl_texture ...@@ -1860,7 +1860,9 @@ struct gl_texture
typedef struct IWineD3DBaseTextureClass typedef struct IWineD3DBaseTextureClass
{ {
struct gl_texture texture_rgb, texture_srgb; struct gl_texture texture_rgb, texture_srgb;
UINT levels; IWineD3DResourceImpl **sub_resources;
UINT layer_count;
UINT level_count;
float pow2Matrix[16]; float pow2Matrix[16];
UINT LOD; UINT LOD;
WINED3DTEXTUREFILTERTYPE filterType; WINED3DTEXTUREFILTERTYPE filterType;
...@@ -1899,9 +1901,10 @@ WINED3DTEXTUREFILTERTYPE basetexture_get_autogen_filter_type(IWineD3DBaseTexture ...@@ -1899,9 +1901,10 @@ WINED3DTEXTUREFILTERTYPE basetexture_get_autogen_filter_type(IWineD3DBaseTexture
BOOL basetexture_get_dirty(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN; BOOL basetexture_get_dirty(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
DWORD basetexture_get_level_count(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN; DWORD basetexture_get_level_count(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
DWORD basetexture_get_lod(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN; DWORD basetexture_get_lod(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT levels, WINED3DRESOURCETYPE resource_type, HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT layer_count, UINT level_count,
IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct wined3d_format_desc *format_desc, WINED3DRESOURCETYPE resource_type, IWineD3DDeviceImpl *device, UINT size, DWORD usage,
WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN; const struct wined3d_format_desc *format_desc, WINED3DPOOL pool, IUnknown *parent,
const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
HRESULT basetexture_set_autogen_filter_type(IWineD3DBaseTexture *iface, HRESULT basetexture_set_autogen_filter_type(IWineD3DBaseTexture *iface,
WINED3DTEXTUREFILTERTYPE filter_type) DECLSPEC_HIDDEN; WINED3DTEXTUREFILTERTYPE filter_type) DECLSPEC_HIDDEN;
BOOL basetexture_set_dirty(IWineD3DBaseTexture *iface, BOOL dirty) DECLSPEC_HIDDEN; BOOL basetexture_set_dirty(IWineD3DBaseTexture *iface, BOOL dirty) DECLSPEC_HIDDEN;
...@@ -1919,7 +1922,6 @@ typedef struct IWineD3DTextureImpl ...@@ -1919,7 +1922,6 @@ typedef struct IWineD3DTextureImpl
IWineD3DBaseTextureClass baseTexture; IWineD3DBaseTextureClass baseTexture;
/* IWineD3DTexture */ /* IWineD3DTexture */
IWineD3DSurface *surfaces[MAX_MIP_LEVELS];
UINT target; UINT target;
BOOL cond_np2; BOOL cond_np2;
...@@ -1938,9 +1940,6 @@ typedef struct IWineD3DCubeTextureImpl ...@@ -1938,9 +1940,6 @@ typedef struct IWineD3DCubeTextureImpl
const IWineD3DCubeTextureVtbl *lpVtbl; const IWineD3DCubeTextureVtbl *lpVtbl;
IWineD3DResourceClass resource; IWineD3DResourceClass resource;
IWineD3DBaseTextureClass baseTexture; IWineD3DBaseTextureClass baseTexture;
/* IWineD3DCubeTexture */
IWineD3DSurface *surfaces[6][MAX_MIP_LEVELS];
} IWineD3DCubeTextureImpl; } IWineD3DCubeTextureImpl;
HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UINT levels, HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UINT levels,
...@@ -1987,9 +1986,6 @@ typedef struct IWineD3DVolumeTextureImpl ...@@ -1987,9 +1986,6 @@ typedef struct IWineD3DVolumeTextureImpl
const IWineD3DVolumeTextureVtbl *lpVtbl; const IWineD3DVolumeTextureVtbl *lpVtbl;
IWineD3DResourceClass resource; IWineD3DResourceClass resource;
IWineD3DBaseTextureClass baseTexture; IWineD3DBaseTextureClass baseTexture;
/* IWineD3DVolumeTexture */
IWineD3DVolume *volumes[MAX_MIP_LEVELS];
} IWineD3DVolumeTextureImpl; } IWineD3DVolumeTextureImpl;
HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT height, HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT height,
......
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