wined3d: Move vtable initialization to the texture init functions.
This commit is contained in:
parent
b1ede91bfc
commit
83b3d4f27a
|
@ -5,6 +5,7 @@
|
|||
* Copyright 2002-2005 Raphael Junqueira
|
||||
* Copyright 2005 Oliver Stieber
|
||||
* Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
||||
* Copyright 2009 Henri Verbeet for CodeWeavers
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -137,121 +138,6 @@ static void cubetexture_cleanup(IWineD3DCubeTextureImpl *This)
|
|||
basetexture_cleanup((IWineD3DBaseTexture *)This);
|
||||
}
|
||||
|
||||
HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UINT levels,
|
||||
IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent)
|
||||
{
|
||||
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
||||
const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
|
||||
UINT pow2_edge_length;
|
||||
unsigned int i, j;
|
||||
UINT tmp_w;
|
||||
HRESULT hr;
|
||||
|
||||
/* TODO: It should only be possible to create textures for formats
|
||||
* that are reported as supported. */
|
||||
if (WINED3DFMT_UNKNOWN >= format)
|
||||
{
|
||||
WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
if (!GL_SUPPORT(ARB_TEXTURE_CUBE_MAP) && pool != WINED3DPOOL_SCRATCH)
|
||||
{
|
||||
WARN("(%p) : Tried to create not supported cube texture.\n", texture);
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
/* Calculate levels for mip mapping */
|
||||
if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
|
||||
{
|
||||
if (!GL_SUPPORT(SGIS_GENERATE_MIPMAP))
|
||||
{
|
||||
WARN("No mipmap generation support, returning D3DERR_INVALIDCALL.\n");
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
if (levels > 1)
|
||||
{
|
||||
WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL.\n");
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
levels = 1;
|
||||
}
|
||||
else if (!levels)
|
||||
{
|
||||
levels = wined3d_log2i(edge_length) + 1;
|
||||
TRACE("Calculated levels = %u.\n", levels);
|
||||
}
|
||||
|
||||
hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels,
|
||||
WINED3DRTYPE_CUBETEXTURE, device, 0, usage, format_desc, pool, parent);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
WARN("Failed to initialize basetexture, returning %#x\n", hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
/* Find the nearest pow2 match. */
|
||||
pow2_edge_length = 1;
|
||||
while (pow2_edge_length < edge_length) pow2_edge_length <<= 1;
|
||||
|
||||
if (GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO) || (edge_length == pow2_edge_length))
|
||||
{
|
||||
/* Precalculated scaling for 'faked' non power of two texture coords. */
|
||||
texture->baseTexture.pow2Matrix[0] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[5] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[10] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[15] = 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Precalculated scaling for 'faked' non power of two texture coords. */
|
||||
texture->baseTexture.pow2Matrix[0] = ((float)edge_length) / ((float)pow2_edge_length);
|
||||
texture->baseTexture.pow2Matrix[5] = ((float)edge_length) / ((float)pow2_edge_length);
|
||||
texture->baseTexture.pow2Matrix[10] = ((float)edge_length) / ((float)pow2_edge_length);
|
||||
texture->baseTexture.pow2Matrix[15] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix_identity = FALSE;
|
||||
}
|
||||
|
||||
/* Generate all the surfaces. */
|
||||
tmp_w = edge_length;
|
||||
for (i = 0; i < texture->baseTexture.levels; ++i)
|
||||
{
|
||||
/* Create the 6 faces. */
|
||||
for (j = 0; j < 6; ++j)
|
||||
{
|
||||
static const GLenum cube_targets[6] =
|
||||
{
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
|
||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
|
||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
|
||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
|
||||
};
|
||||
|
||||
hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_w,
|
||||
format, usage, pool, i /* Level */, j, &texture->surfaces[j][i]);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
FIXME("(%p) Failed to create surface, hr %#x.\n", texture, hr);
|
||||
texture->surfaces[j][i] = NULL;
|
||||
cubetexture_cleanup(texture);
|
||||
return hr;
|
||||
}
|
||||
|
||||
IWineD3DSurface_SetContainer(texture->surfaces[j][i], (IWineD3DBase *)texture);
|
||||
TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[j][i]);
|
||||
surface_set_texture_target(texture->surfaces[j][i], cube_targets[j]);
|
||||
}
|
||||
tmp_w = max(1, tmp_w >> 1);
|
||||
}
|
||||
texture->baseTexture.internal_preload = cubetexture_internal_preload;
|
||||
|
||||
return WINED3D_OK;
|
||||
}
|
||||
|
||||
#undef GLINFO_LOCATION
|
||||
|
||||
/* *******************************************
|
||||
|
@ -519,8 +405,7 @@ static HRESULT WINAPI IWineD3DCubeTextureImpl_AddDirtyRect(IWineD3DCubeTexture
|
|||
return hr;
|
||||
}
|
||||
|
||||
|
||||
const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl =
|
||||
static const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl =
|
||||
{
|
||||
/* IUnknown */
|
||||
IWineD3DCubeTextureImpl_QueryInterface,
|
||||
|
@ -557,3 +442,120 @@ const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl =
|
|||
IWineD3DCubeTextureImpl_UnlockRect,
|
||||
IWineD3DCubeTextureImpl_AddDirtyRect
|
||||
};
|
||||
|
||||
HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UINT levels,
|
||||
IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent)
|
||||
{
|
||||
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
||||
const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
|
||||
UINT pow2_edge_length;
|
||||
unsigned int i, j;
|
||||
UINT tmp_w;
|
||||
HRESULT hr;
|
||||
|
||||
/* TODO: It should only be possible to create textures for formats
|
||||
* that are reported as supported. */
|
||||
if (WINED3DFMT_UNKNOWN >= format)
|
||||
{
|
||||
WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
if (!gl_info->supported[ARB_TEXTURE_CUBE_MAP] && pool != WINED3DPOOL_SCRATCH)
|
||||
{
|
||||
WARN("(%p) : Tried to create not supported cube texture.\n", texture);
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
/* Calculate levels for mip mapping */
|
||||
if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
|
||||
{
|
||||
if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
|
||||
{
|
||||
WARN("No mipmap generation support, returning D3DERR_INVALIDCALL.\n");
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
if (levels > 1)
|
||||
{
|
||||
WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL.\n");
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
levels = 1;
|
||||
}
|
||||
else if (!levels)
|
||||
{
|
||||
levels = wined3d_log2i(edge_length) + 1;
|
||||
TRACE("Calculated levels = %u.\n", levels);
|
||||
}
|
||||
|
||||
texture->lpVtbl = &IWineD3DCubeTexture_Vtbl;
|
||||
|
||||
hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels,
|
||||
WINED3DRTYPE_CUBETEXTURE, device, 0, usage, format_desc, pool, parent);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
WARN("Failed to initialize basetexture, returning %#x\n", hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
/* Find the nearest pow2 match. */
|
||||
pow2_edge_length = 1;
|
||||
while (pow2_edge_length < edge_length) pow2_edge_length <<= 1;
|
||||
|
||||
if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] || (edge_length == pow2_edge_length))
|
||||
{
|
||||
/* Precalculated scaling for 'faked' non power of two texture coords. */
|
||||
texture->baseTexture.pow2Matrix[0] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[5] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[10] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[15] = 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Precalculated scaling for 'faked' non power of two texture coords. */
|
||||
texture->baseTexture.pow2Matrix[0] = ((float)edge_length) / ((float)pow2_edge_length);
|
||||
texture->baseTexture.pow2Matrix[5] = ((float)edge_length) / ((float)pow2_edge_length);
|
||||
texture->baseTexture.pow2Matrix[10] = ((float)edge_length) / ((float)pow2_edge_length);
|
||||
texture->baseTexture.pow2Matrix[15] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix_identity = FALSE;
|
||||
}
|
||||
|
||||
/* Generate all the surfaces. */
|
||||
tmp_w = edge_length;
|
||||
for (i = 0; i < texture->baseTexture.levels; ++i)
|
||||
{
|
||||
/* Create the 6 faces. */
|
||||
for (j = 0; j < 6; ++j)
|
||||
{
|
||||
static const GLenum cube_targets[6] =
|
||||
{
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
|
||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
|
||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
|
||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
|
||||
};
|
||||
|
||||
hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_w,
|
||||
format, usage, pool, i /* Level */, j, &texture->surfaces[j][i]);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
FIXME("(%p) Failed to create surface, hr %#x.\n", texture, hr);
|
||||
texture->surfaces[j][i] = NULL;
|
||||
cubetexture_cleanup(texture);
|
||||
return hr;
|
||||
}
|
||||
|
||||
IWineD3DSurface_SetContainer(texture->surfaces[j][i], (IWineD3DBase *)texture);
|
||||
TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[j][i]);
|
||||
surface_set_texture_target(texture->surfaces[j][i], cube_targets[j]);
|
||||
}
|
||||
tmp_w = max(1, tmp_w >> 1);
|
||||
}
|
||||
texture->baseTexture.internal_preload = cubetexture_internal_preload;
|
||||
|
||||
return WINED3D_OK;
|
||||
}
|
||||
|
|
|
@ -983,8 +983,6 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateTexture(IWineD3DDevice *iface,
|
|||
return WINED3DERR_OUTOFVIDEOMEMORY;
|
||||
}
|
||||
|
||||
object->lpVtbl = &IWineD3DTexture_Vtbl;
|
||||
|
||||
hr = texture_init(object, Width, Height, Levels, This, Usage, Format, Pool, parent);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
|
@ -1020,7 +1018,6 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVolumeTexture(IWineD3DDevice *ifa
|
|||
return WINED3DERR_OUTOFVIDEOMEMORY;
|
||||
}
|
||||
|
||||
object->lpVtbl = &IWineD3DVolumeTexture_Vtbl;
|
||||
hr = volumetexture_init(object, Width, Height, Depth, Levels, This, Usage, Format, Pool, parent);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
|
@ -1085,7 +1082,6 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateCubeTexture(IWineD3DDevice *iface
|
|||
return WINED3DERR_OUTOFVIDEOMEMORY;
|
||||
}
|
||||
|
||||
object->lpVtbl = &IWineD3DCubeTexture_Vtbl;
|
||||
hr = cubetexture_init(object, EdgeLength, Levels, This, Usage, Format, Pool, parent);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* Copyright 2002-2005 Raphael Junqueira
|
||||
* Copyright 2005 Oliver Stieber
|
||||
* Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
||||
* Copyright 2009 Henri Verbeet for CodeWeavers
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -124,164 +125,6 @@ static void texture_cleanup(IWineD3DTextureImpl *This)
|
|||
basetexture_cleanup((IWineD3DBaseTexture *)This);
|
||||
}
|
||||
|
||||
HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
|
||||
IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent)
|
||||
{
|
||||
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
||||
const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
|
||||
UINT pow2_width, pow2_height;
|
||||
UINT tmp_w, tmp_h;
|
||||
unsigned int i;
|
||||
HRESULT hr;
|
||||
|
||||
/* TODO: It should only be possible to create textures for formats
|
||||
* that are reported as supported. */
|
||||
if (WINED3DFMT_UNKNOWN >= format)
|
||||
{
|
||||
WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
/* Non-power2 support. */
|
||||
if (GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO))
|
||||
{
|
||||
pow2_width = width;
|
||||
pow2_height = height;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Find the nearest pow2 match. */
|
||||
pow2_width = pow2_height = 1;
|
||||
while (pow2_width < width) pow2_width <<= 1;
|
||||
while (pow2_height < height) pow2_height <<= 1;
|
||||
|
||||
if (pow2_width != width || pow2_height != height)
|
||||
{
|
||||
if (levels > 1)
|
||||
{
|
||||
WARN("Attempted to create a mipmapped np2 texture without unconditional np2 support.\n");
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
levels = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculate levels for mip mapping. */
|
||||
if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
|
||||
{
|
||||
if (!GL_SUPPORT(SGIS_GENERATE_MIPMAP))
|
||||
{
|
||||
WARN("No mipmap generation support, returning WINED3DERR_INVALIDCALL.\n");
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
if (levels > 1)
|
||||
{
|
||||
WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning WINED3DERR_INVALIDCALL.\n");
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
levels = 1;
|
||||
}
|
||||
else if (!levels)
|
||||
{
|
||||
levels = wined3d_log2i(max(width, height)) + 1;
|
||||
TRACE("Calculated levels = %u.\n", levels);
|
||||
}
|
||||
|
||||
hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels,
|
||||
WINED3DRTYPE_TEXTURE, device, 0, usage, format_desc, pool, parent);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
WARN("Failed to initialize basetexture, returning %#x.\n", hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
/* Precalculated scaling for 'faked' non power of two texture coords.
|
||||
* Second also don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
|
||||
* is used in combination with texture uploads (RTL_READTEX). The reason is that EXT_PALETTED_TEXTURE
|
||||
* doesn't work in combination with ARB_TEXTURE_RECTANGLE. */
|
||||
if (GL_SUPPORT(WINE_NORMALIZED_TEXRECT) && (width != pow2_width || height != pow2_height))
|
||||
{
|
||||
texture->baseTexture.pow2Matrix[0] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[5] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[10] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[15] = 1.0f;
|
||||
texture->target = GL_TEXTURE_2D;
|
||||
texture->cond_np2 = TRUE;
|
||||
texture->baseTexture.minMipLookup = minMipLookup_noFilter;
|
||||
}
|
||||
else if (GL_SUPPORT(ARB_TEXTURE_RECTANGLE) && (width != pow2_width || height != pow2_height)
|
||||
&& !((format_desc->format == WINED3DFMT_P8) && GL_SUPPORT(EXT_PALETTED_TEXTURE)
|
||||
&& (wined3d_settings.rendertargetlock_mode == RTL_READTEX)))
|
||||
{
|
||||
if ((width != 1) || (height != 1)) texture->baseTexture.pow2Matrix_identity = FALSE;
|
||||
|
||||
texture->baseTexture.pow2Matrix[0] = (float)width;
|
||||
texture->baseTexture.pow2Matrix[5] = (float)height;
|
||||
texture->baseTexture.pow2Matrix[10] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[15] = 1.0f;
|
||||
texture->target = GL_TEXTURE_RECTANGLE_ARB;
|
||||
texture->cond_np2 = TRUE;
|
||||
|
||||
if(texture->resource.format_desc->Flags & WINED3DFMT_FLAG_FILTERING)
|
||||
{
|
||||
texture->baseTexture.minMipLookup = minMipLookup_noMip;
|
||||
}
|
||||
else
|
||||
{
|
||||
texture->baseTexture.minMipLookup = minMipLookup_noFilter;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((width != pow2_width) || (height != pow2_height))
|
||||
{
|
||||
texture->baseTexture.pow2Matrix_identity = FALSE;
|
||||
texture->baseTexture.pow2Matrix[0] = (((float)width) / ((float)pow2_width));
|
||||
texture->baseTexture.pow2Matrix[5] = (((float)height) / ((float)pow2_height));
|
||||
}
|
||||
else
|
||||
{
|
||||
texture->baseTexture.pow2Matrix[0] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[5] = 1.0f;
|
||||
}
|
||||
|
||||
texture->baseTexture.pow2Matrix[10] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[15] = 1.0f;
|
||||
texture->target = GL_TEXTURE_2D;
|
||||
texture->cond_np2 = FALSE;
|
||||
}
|
||||
TRACE("xf(%f) yf(%f)\n", texture->baseTexture.pow2Matrix[0], texture->baseTexture.pow2Matrix[5]);
|
||||
|
||||
/* Generate all the surfaces. */
|
||||
tmp_w = width;
|
||||
tmp_h = height;
|
||||
for (i = 0; i < texture->baseTexture.levels; ++i)
|
||||
{
|
||||
/* Use the callback to create the texture surface. */
|
||||
hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format,
|
||||
usage, pool, i, WINED3DCUBEMAP_FACE_POSITIVE_X, &texture->surfaces[i]);
|
||||
if (FAILED(hr) || ((IWineD3DSurfaceImpl *)texture->surfaces[i])->Flags & SFLAG_OVERSIZE)
|
||||
{
|
||||
FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
|
||||
texture->surfaces[i] = NULL;
|
||||
texture_cleanup(texture);
|
||||
return hr;
|
||||
}
|
||||
|
||||
IWineD3DSurface_SetContainer(texture->surfaces[i], (IWineD3DBase *)texture);
|
||||
TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[i]);
|
||||
surface_set_texture_target(texture->surfaces[i], texture->target);
|
||||
/* Calculate the next mipmap level. */
|
||||
tmp_w = max(1, tmp_w >> 1);
|
||||
tmp_h = max(1, tmp_h >> 1);
|
||||
}
|
||||
texture->baseTexture.internal_preload = texture_internal_preload;
|
||||
|
||||
return WINED3D_OK;
|
||||
}
|
||||
|
||||
#undef GLINFO_LOCATION
|
||||
|
||||
/* *******************************************
|
||||
|
@ -559,7 +402,7 @@ static HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, C
|
|||
return WINED3D_OK;
|
||||
}
|
||||
|
||||
const IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
|
||||
static const IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
|
||||
{
|
||||
/* IUnknown */
|
||||
IWineD3DTextureImpl_QueryInterface,
|
||||
|
@ -596,3 +439,163 @@ const IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
|
|||
IWineD3DTextureImpl_UnlockRect,
|
||||
IWineD3DTextureImpl_AddDirtyRect
|
||||
};
|
||||
|
||||
HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
|
||||
IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent)
|
||||
{
|
||||
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
||||
const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
|
||||
UINT pow2_width, pow2_height;
|
||||
UINT tmp_w, tmp_h;
|
||||
unsigned int i;
|
||||
HRESULT hr;
|
||||
|
||||
/* TODO: It should only be possible to create textures for formats
|
||||
* that are reported as supported. */
|
||||
if (WINED3DFMT_UNKNOWN >= format)
|
||||
{
|
||||
WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
/* Non-power2 support. */
|
||||
if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
|
||||
{
|
||||
pow2_width = width;
|
||||
pow2_height = height;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Find the nearest pow2 match. */
|
||||
pow2_width = pow2_height = 1;
|
||||
while (pow2_width < width) pow2_width <<= 1;
|
||||
while (pow2_height < height) pow2_height <<= 1;
|
||||
|
||||
if (pow2_width != width || pow2_height != height)
|
||||
{
|
||||
if (levels > 1)
|
||||
{
|
||||
WARN("Attempted to create a mipmapped np2 texture without unconditional np2 support.\n");
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
levels = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculate levels for mip mapping. */
|
||||
if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
|
||||
{
|
||||
if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
|
||||
{
|
||||
WARN("No mipmap generation support, returning WINED3DERR_INVALIDCALL.\n");
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
if (levels > 1)
|
||||
{
|
||||
WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning WINED3DERR_INVALIDCALL.\n");
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
levels = 1;
|
||||
}
|
||||
else if (!levels)
|
||||
{
|
||||
levels = wined3d_log2i(max(width, height)) + 1;
|
||||
TRACE("Calculated levels = %u.\n", levels);
|
||||
}
|
||||
|
||||
texture->lpVtbl = &IWineD3DTexture_Vtbl;
|
||||
|
||||
hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels,
|
||||
WINED3DRTYPE_TEXTURE, device, 0, usage, format_desc, pool, parent);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
WARN("Failed to initialize basetexture, returning %#x.\n", hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
/* Precalculated scaling for 'faked' non power of two texture coords.
|
||||
* Second also don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
|
||||
* is used in combination with texture uploads (RTL_READTEX). The reason is that EXT_PALETTED_TEXTURE
|
||||
* doesn't work in combination with ARB_TEXTURE_RECTANGLE. */
|
||||
if (gl_info->supported[WINE_NORMALIZED_TEXRECT] && (width != pow2_width || height != pow2_height))
|
||||
{
|
||||
texture->baseTexture.pow2Matrix[0] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[5] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[10] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[15] = 1.0f;
|
||||
texture->target = GL_TEXTURE_2D;
|
||||
texture->cond_np2 = TRUE;
|
||||
texture->baseTexture.minMipLookup = minMipLookup_noFilter;
|
||||
}
|
||||
else if (gl_info->supported[ARB_TEXTURE_RECTANGLE] && (width != pow2_width || height != pow2_height)
|
||||
&& !((format_desc->format == WINED3DFMT_P8) && gl_info->supported[EXT_PALETTED_TEXTURE]
|
||||
&& (wined3d_settings.rendertargetlock_mode == RTL_READTEX)))
|
||||
{
|
||||
if ((width != 1) || (height != 1)) texture->baseTexture.pow2Matrix_identity = FALSE;
|
||||
|
||||
texture->baseTexture.pow2Matrix[0] = (float)width;
|
||||
texture->baseTexture.pow2Matrix[5] = (float)height;
|
||||
texture->baseTexture.pow2Matrix[10] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[15] = 1.0f;
|
||||
texture->target = GL_TEXTURE_RECTANGLE_ARB;
|
||||
texture->cond_np2 = TRUE;
|
||||
|
||||
if(texture->resource.format_desc->Flags & WINED3DFMT_FLAG_FILTERING)
|
||||
{
|
||||
texture->baseTexture.minMipLookup = minMipLookup_noMip;
|
||||
}
|
||||
else
|
||||
{
|
||||
texture->baseTexture.minMipLookup = minMipLookup_noFilter;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((width != pow2_width) || (height != pow2_height))
|
||||
{
|
||||
texture->baseTexture.pow2Matrix_identity = FALSE;
|
||||
texture->baseTexture.pow2Matrix[0] = (((float)width) / ((float)pow2_width));
|
||||
texture->baseTexture.pow2Matrix[5] = (((float)height) / ((float)pow2_height));
|
||||
}
|
||||
else
|
||||
{
|
||||
texture->baseTexture.pow2Matrix[0] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[5] = 1.0f;
|
||||
}
|
||||
|
||||
texture->baseTexture.pow2Matrix[10] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[15] = 1.0f;
|
||||
texture->target = GL_TEXTURE_2D;
|
||||
texture->cond_np2 = FALSE;
|
||||
}
|
||||
TRACE("xf(%f) yf(%f)\n", texture->baseTexture.pow2Matrix[0], texture->baseTexture.pow2Matrix[5]);
|
||||
|
||||
/* Generate all the surfaces. */
|
||||
tmp_w = width;
|
||||
tmp_h = height;
|
||||
for (i = 0; i < texture->baseTexture.levels; ++i)
|
||||
{
|
||||
/* Use the callback to create the texture surface. */
|
||||
hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format,
|
||||
usage, pool, i, WINED3DCUBEMAP_FACE_POSITIVE_X, &texture->surfaces[i]);
|
||||
if (FAILED(hr) || ((IWineD3DSurfaceImpl *)texture->surfaces[i])->Flags & SFLAG_OVERSIZE)
|
||||
{
|
||||
FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
|
||||
texture->surfaces[i] = NULL;
|
||||
texture_cleanup(texture);
|
||||
return hr;
|
||||
}
|
||||
|
||||
IWineD3DSurface_SetContainer(texture->surfaces[i], (IWineD3DBase *)texture);
|
||||
TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[i]);
|
||||
surface_set_texture_target(texture->surfaces[i], texture->target);
|
||||
/* Calculate the next mipmap level. */
|
||||
tmp_w = max(1, tmp_w >> 1);
|
||||
tmp_h = max(1, tmp_h >> 1);
|
||||
}
|
||||
texture->baseTexture.internal_preload = texture_internal_preload;
|
||||
|
||||
return WINED3D_OK;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* Copyright 2002-2005 Jason Edmeades
|
||||
* Copyright 2002-2005 Raphael Junqueira
|
||||
* Copyright 2005 Oliver Stieber
|
||||
* Copyright 2009 Henri Verbeet for CodeWeavers
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -96,97 +97,6 @@ static void volumetexture_cleanup(IWineD3DVolumeTextureImpl *This)
|
|||
basetexture_cleanup((IWineD3DBaseTexture *)This);
|
||||
}
|
||||
|
||||
HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT height, UINT depth, UINT levels,
|
||||
IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent)
|
||||
{
|
||||
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
||||
const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
|
||||
UINT tmp_w, tmp_h, tmp_d;
|
||||
unsigned int i;
|
||||
HRESULT hr;
|
||||
|
||||
/* TODO: It should only be possible to create textures for formats
|
||||
* that are reported as supported. */
|
||||
if (WINED3DFMT_UNKNOWN >= format)
|
||||
{
|
||||
WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
if (!GL_SUPPORT(EXT_TEXTURE3D))
|
||||
{
|
||||
WARN("(%p) : Texture cannot be created - no volume texture support.\n", texture);
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
/* Calculate levels for mip mapping. */
|
||||
if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
|
||||
{
|
||||
if (!GL_SUPPORT(SGIS_GENERATE_MIPMAP))
|
||||
{
|
||||
WARN("No mipmap generation support, returning D3DERR_INVALIDCALL.\n");
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
if (levels > 1)
|
||||
{
|
||||
WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL.\n");
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
levels = 1;
|
||||
}
|
||||
else if (!levels)
|
||||
{
|
||||
levels = wined3d_log2i(max(max(width, height), depth)) + 1;
|
||||
TRACE("Calculated levels = %u.\n", levels);
|
||||
}
|
||||
|
||||
hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels,
|
||||
WINED3DRTYPE_VOLUMETEXTURE, device, 0, usage, format_desc, pool, parent);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
WARN("Failed to initialize basetexture, returning %#x.\n", hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
/* Is NP2 support for volumes needed? */
|
||||
texture->baseTexture.pow2Matrix[0] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[5] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[10] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[15] = 1.0f;
|
||||
|
||||
/* Generate all the surfaces. */
|
||||
tmp_w = width;
|
||||
tmp_h = height;
|
||||
tmp_d = depth;
|
||||
|
||||
for (i = 0; i < texture->baseTexture.levels; ++i)
|
||||
{
|
||||
/* Create the volume. */
|
||||
hr = IWineD3DDeviceParent_CreateVolume(device->device_parent, parent,
|
||||
tmp_w, tmp_h, tmp_d, format, pool, usage, &texture->volumes[i]);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
ERR("Creating a volume for the volume texture failed, hr %#x.\n", hr);
|
||||
texture->volumes[i] = NULL;
|
||||
volumetexture_cleanup(texture);
|
||||
return hr;
|
||||
}
|
||||
|
||||
/* Set its container to this texture. */
|
||||
IWineD3DVolume_SetContainer(texture->volumes[i], (IWineD3DBase *)texture);
|
||||
|
||||
/* Calculate the next mipmap level. */
|
||||
tmp_w = max(1, tmp_w >> 1);
|
||||
tmp_h = max(1, tmp_h >> 1);
|
||||
tmp_d = max(1, tmp_d >> 1);
|
||||
}
|
||||
texture->baseTexture.internal_preload = volumetexture_internal_preload;
|
||||
|
||||
return WINED3D_OK;
|
||||
}
|
||||
|
||||
#undef GLINFO_LOCATION
|
||||
|
||||
/* *******************************************
|
||||
|
@ -415,7 +325,7 @@ static HRESULT WINAPI IWineD3DVolumeTextureImpl_AddDirtyBox(IWineD3DVolumeTextur
|
|||
return WINED3D_OK;
|
||||
}
|
||||
|
||||
const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl =
|
||||
static const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl =
|
||||
{
|
||||
/* IUnknown */
|
||||
IWineD3DVolumeTextureImpl_QueryInterface,
|
||||
|
@ -453,3 +363,96 @@ const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl =
|
|||
IWineD3DVolumeTextureImpl_UnlockBox,
|
||||
IWineD3DVolumeTextureImpl_AddDirtyBox
|
||||
};
|
||||
|
||||
HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT height, UINT depth, UINT levels,
|
||||
IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent)
|
||||
{
|
||||
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
||||
const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
|
||||
UINT tmp_w, tmp_h, tmp_d;
|
||||
unsigned int i;
|
||||
HRESULT hr;
|
||||
|
||||
/* TODO: It should only be possible to create textures for formats
|
||||
* that are reported as supported. */
|
||||
if (WINED3DFMT_UNKNOWN >= format)
|
||||
{
|
||||
WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
if (!gl_info->supported[EXT_TEXTURE3D])
|
||||
{
|
||||
WARN("(%p) : Texture cannot be created - no volume texture support.\n", texture);
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
/* Calculate levels for mip mapping. */
|
||||
if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
|
||||
{
|
||||
if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
|
||||
{
|
||||
WARN("No mipmap generation support, returning D3DERR_INVALIDCALL.\n");
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
if (levels > 1)
|
||||
{
|
||||
WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL.\n");
|
||||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
levels = 1;
|
||||
}
|
||||
else if (!levels)
|
||||
{
|
||||
levels = wined3d_log2i(max(max(width, height), depth)) + 1;
|
||||
TRACE("Calculated levels = %u.\n", levels);
|
||||
}
|
||||
|
||||
texture->lpVtbl = &IWineD3DVolumeTexture_Vtbl;
|
||||
|
||||
hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels,
|
||||
WINED3DRTYPE_VOLUMETEXTURE, device, 0, usage, format_desc, pool, parent);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
WARN("Failed to initialize basetexture, returning %#x.\n", hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
/* Is NP2 support for volumes needed? */
|
||||
texture->baseTexture.pow2Matrix[0] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[5] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[10] = 1.0f;
|
||||
texture->baseTexture.pow2Matrix[15] = 1.0f;
|
||||
|
||||
/* Generate all the surfaces. */
|
||||
tmp_w = width;
|
||||
tmp_h = height;
|
||||
tmp_d = depth;
|
||||
|
||||
for (i = 0; i < texture->baseTexture.levels; ++i)
|
||||
{
|
||||
/* Create the volume. */
|
||||
hr = IWineD3DDeviceParent_CreateVolume(device->device_parent, parent,
|
||||
tmp_w, tmp_h, tmp_d, format, pool, usage, &texture->volumes[i]);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
ERR("Creating a volume for the volume texture failed, hr %#x.\n", hr);
|
||||
texture->volumes[i] = NULL;
|
||||
volumetexture_cleanup(texture);
|
||||
return hr;
|
||||
}
|
||||
|
||||
/* Set its container to this texture. */
|
||||
IWineD3DVolume_SetContainer(texture->volumes[i], (IWineD3DBase *)texture);
|
||||
|
||||
/* Calculate the next mipmap level. */
|
||||
tmp_w = max(1, tmp_w >> 1);
|
||||
tmp_h = max(1, tmp_h >> 1);
|
||||
tmp_d = max(1, tmp_d >> 1);
|
||||
}
|
||||
texture->baseTexture.internal_preload = volumetexture_internal_preload;
|
||||
|
||||
return WINED3D_OK;
|
||||
}
|
||||
|
|
|
@ -1825,8 +1825,6 @@ typedef struct IWineD3DTextureImpl
|
|||
|
||||
} IWineD3DTextureImpl;
|
||||
|
||||
extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl DECLSPEC_HIDDEN;
|
||||
|
||||
HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels, IWineD3DDeviceImpl *device,
|
||||
DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent) DECLSPEC_HIDDEN;
|
||||
|
||||
|
@ -1844,8 +1842,6 @@ typedef struct IWineD3DCubeTextureImpl
|
|||
IWineD3DSurface *surfaces[6][MAX_MIP_LEVELS];
|
||||
} IWineD3DCubeTextureImpl;
|
||||
|
||||
extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl DECLSPEC_HIDDEN;
|
||||
|
||||
HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UINT levels, IWineD3DDeviceImpl *device,
|
||||
DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent) DECLSPEC_HIDDEN;
|
||||
|
||||
|
@ -1895,8 +1891,6 @@ typedef struct IWineD3DVolumeTextureImpl
|
|||
IWineD3DVolume *volumes[MAX_MIP_LEVELS];
|
||||
} IWineD3DVolumeTextureImpl;
|
||||
|
||||
extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl DECLSPEC_HIDDEN;
|
||||
|
||||
HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT height,
|
||||
UINT depth, UINT levels, IWineD3DDeviceImpl *device, DWORD usage,
|
||||
WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent) DECLSPEC_HIDDEN;
|
||||
|
|
Loading…
Reference in New Issue