wined3d: Introduce volumetexture_init() to handle most of the volume texture initialization.
This commit is contained in:
parent
9e69b86a03
commit
97f320a77b
|
@ -1121,47 +1121,11 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVolumeTexture(IWineD3DDevice *ifa
|
||||||
WINED3DPOOL Pool, IWineD3DVolumeTexture **ppVolumeTexture, IUnknown *parent)
|
WINED3DPOOL Pool, IWineD3DVolumeTexture **ppVolumeTexture, IUnknown *parent)
|
||||||
{
|
{
|
||||||
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
|
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
|
||||||
const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(Format, &This->adapter->gl_info);
|
|
||||||
IWineD3DVolumeTextureImpl *object;
|
IWineD3DVolumeTextureImpl *object;
|
||||||
unsigned int i;
|
|
||||||
UINT tmpW;
|
|
||||||
UINT tmpH;
|
|
||||||
UINT tmpD;
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
/* TODO: It should only be possible to create textures for formats
|
TRACE("(%p) : W(%u) H(%u) D(%u), Lvl(%u) Usage(%#x), Fmt(%u,%s), Pool(%s)\n", This, Width, Height,
|
||||||
that are reported as supported */
|
Depth, Levels, Usage, Format, debug_d3dformat(Format), debug_d3dpool(Pool));
|
||||||
if (WINED3DFMT_UNKNOWN >= Format) {
|
|
||||||
WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN\n", This);
|
|
||||||
return WINED3DERR_INVALIDCALL;
|
|
||||||
}
|
|
||||||
if(!GL_SUPPORT(EXT_TEXTURE3D)) {
|
|
||||||
WARN("(%p) : Texture cannot be created - no volume texture support\n", This);
|
|
||||||
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 = %d\n", Levels);
|
|
||||||
}
|
|
||||||
|
|
||||||
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
||||||
if (!object)
|
if (!object)
|
||||||
|
@ -1172,66 +1136,18 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVolumeTexture(IWineD3DDevice *ifa
|
||||||
}
|
}
|
||||||
|
|
||||||
object->lpVtbl = &IWineD3DVolumeTexture_Vtbl;
|
object->lpVtbl = &IWineD3DVolumeTexture_Vtbl;
|
||||||
hr = basetexture_init((IWineD3DBaseTextureImpl *)object, Levels,
|
hr = volumetexture_init(object, Width, Height, Depth, Levels, This, Usage, Format, Pool, parent);
|
||||||
WINED3DRTYPE_VOLUMETEXTURE, This, 0, Usage, format_desc, Pool, parent);
|
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
WARN("Failed to initialize basetexture, returning %#x\n", hr);
|
WARN("Failed to initialize volumetexture, returning %#x\n", hr);
|
||||||
HeapFree(GetProcessHeap(), 0, object);
|
HeapFree(GetProcessHeap(), 0, object);
|
||||||
*ppVolumeTexture = NULL;
|
*ppVolumeTexture = NULL;
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE("(%p) : Created basetexture %p\n", This, object);
|
TRACE("(%p) : Created volume texture %p.\n", This, object);
|
||||||
|
*ppVolumeTexture = (IWineD3DVolumeTexture *)object;
|
||||||
|
|
||||||
TRACE("(%p) : W(%d) H(%d) D(%d), Lvl(%d) Usage(%d), Fmt(%u,%s), Pool(%s)\n", This, Width, Height,
|
|
||||||
Depth, Levels, Usage, Format, debug_d3dformat(Format), debug_d3dpool(Pool));
|
|
||||||
|
|
||||||
/* Is NP2 support for volumes needed? */
|
|
||||||
object->baseTexture.pow2Matrix[ 0] = 1.0;
|
|
||||||
object->baseTexture.pow2Matrix[ 5] = 1.0;
|
|
||||||
object->baseTexture.pow2Matrix[10] = 1.0;
|
|
||||||
object->baseTexture.pow2Matrix[15] = 1.0;
|
|
||||||
|
|
||||||
if (object->resource.format_desc->Flags & WINED3DFMT_FLAG_FILTERING)
|
|
||||||
{
|
|
||||||
object->baseTexture.minMipLookup = minMipLookup;
|
|
||||||
object->baseTexture.magLookup = magLookup;
|
|
||||||
} else {
|
|
||||||
object->baseTexture.minMipLookup = minMipLookup_noFilter;
|
|
||||||
object->baseTexture.magLookup = magLookup_noFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Generate all the surfaces */
|
|
||||||
tmpW = Width;
|
|
||||||
tmpH = Height;
|
|
||||||
tmpD = Depth;
|
|
||||||
|
|
||||||
for (i = 0; i < object->baseTexture.levels; i++)
|
|
||||||
{
|
|
||||||
HRESULT hr;
|
|
||||||
/* Create the volume */
|
|
||||||
hr = IWineD3DDeviceParent_CreateVolume(This->device_parent, parent,
|
|
||||||
tmpW, tmpH, tmpD, Format, Pool, Usage, &object->volumes[i]);
|
|
||||||
if(FAILED(hr)) {
|
|
||||||
ERR("Creating a volume for the volume texture failed(%08x)\n", hr);
|
|
||||||
IWineD3DVolumeTexture_Release((IWineD3DVolumeTexture *) object);
|
|
||||||
*ppVolumeTexture = NULL;
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set its container to this object */
|
|
||||||
IWineD3DVolume_SetContainer(object->volumes[i], (IWineD3DBase *)object);
|
|
||||||
|
|
||||||
/* calculate the next mipmap level */
|
|
||||||
tmpW = max(1, tmpW >> 1);
|
|
||||||
tmpH = max(1, tmpH >> 1);
|
|
||||||
tmpD = max(1, tmpD >> 1);
|
|
||||||
}
|
|
||||||
object->baseTexture.internal_preload = volumetexture_internal_preload;
|
|
||||||
|
|
||||||
*ppVolumeTexture = (IWineD3DVolumeTexture *) object;
|
|
||||||
TRACE("(%p) : Created volume texture %p\n", This, object);
|
|
||||||
return WINED3D_OK;
|
return WINED3D_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,57 @@
|
||||||
#include "wined3d_private.h"
|
#include "wined3d_private.h"
|
||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
|
||||||
#define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
|
|
||||||
|
#define GLINFO_LOCATION (*gl_info)
|
||||||
|
|
||||||
|
static void volumetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb)
|
||||||
|
{
|
||||||
|
/* Override the IWineD3DResource Preload method. */
|
||||||
|
IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
||||||
|
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
||||||
|
const WineD3D_GL_Info *gl_info = &device->adapter->gl_info;
|
||||||
|
BOOL srgb_mode = This->baseTexture.is_srgb;
|
||||||
|
BOOL srgb_was_toggled = FALSE;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
TRACE("(%p) : About to load texture.\n", This);
|
||||||
|
|
||||||
|
if (!device->isInDraw)
|
||||||
|
{
|
||||||
|
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
|
||||||
|
}
|
||||||
|
else if (GL_SUPPORT(EXT_TEXTURE_SRGB) && This->baseTexture.bindCount > 0)
|
||||||
|
{
|
||||||
|
srgb_mode = device->stateBlock->samplerState[This->baseTexture.sampler][WINED3DSAMP_SRGBTEXTURE];
|
||||||
|
srgb_was_toggled = This->baseTexture.is_srgb != srgb_mode;
|
||||||
|
This->baseTexture.is_srgb = srgb_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the texture is marked dirty or the srgb sampler setting has changed
|
||||||
|
* since the last load then reload the volumes. */
|
||||||
|
if (This->baseTexture.dirty)
|
||||||
|
{
|
||||||
|
for (i = 0; i < This->baseTexture.levels; ++i)
|
||||||
|
{
|
||||||
|
IWineD3DVolume_LoadTexture(This->volumes[i], i, srgb_mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (srgb_was_toggled)
|
||||||
|
{
|
||||||
|
for (i = 0; i < This->baseTexture.levels; ++i)
|
||||||
|
{
|
||||||
|
volume_add_dirty_box(This->volumes[i], NULL);
|
||||||
|
IWineD3DVolume_LoadTexture(This->volumes[i], i, srgb_mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TRACE("(%p) Texture not dirty, nothing to do.\n", iface);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* No longer dirty */
|
||||||
|
This->baseTexture.dirty = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static void volumetexture_cleanup(IWineD3DVolumeTextureImpl *This, D3DCB_DESTROYVOLUMEFN volume_destroy_cb)
|
static void volumetexture_cleanup(IWineD3DVolumeTextureImpl *This, D3DCB_DESTROYVOLUMEFN volume_destroy_cb)
|
||||||
{
|
{
|
||||||
|
@ -46,9 +96,116 @@ static void volumetexture_cleanup(IWineD3DVolumeTextureImpl *This, D3DCB_DESTROY
|
||||||
basetexture_cleanup((IWineD3DBaseTexture *)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 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (texture->resource.format_desc->Flags & WINED3DFMT_FLAG_FILTERING)
|
||||||
|
{
|
||||||
|
texture->baseTexture.minMipLookup = minMipLookup;
|
||||||
|
texture->baseTexture.magLookup = magLookup;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
texture->baseTexture.minMipLookup = minMipLookup_noFilter;
|
||||||
|
texture->baseTexture.magLookup = magLookup_noFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Is NP2 support for volumes needed? */
|
||||||
|
texture->baseTexture.pow2Matrix[0] = 1.0;
|
||||||
|
texture->baseTexture.pow2Matrix[5] = 1.0;
|
||||||
|
texture->baseTexture.pow2Matrix[10] = 1.0;
|
||||||
|
texture->baseTexture.pow2Matrix[15] = 1.0;
|
||||||
|
|
||||||
|
/* 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, D3DCB_DefaultDestroyVolume);
|
||||||
|
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
|
||||||
|
|
||||||
/* *******************************************
|
/* *******************************************
|
||||||
IWineD3DTexture IUnknown parts follow
|
IWineD3DTexture IUnknown parts follow
|
||||||
******************************************* */
|
******************************************* */
|
||||||
|
|
||||||
|
#define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
|
||||||
|
|
||||||
static HRESULT WINAPI IWineD3DVolumeTextureImpl_QueryInterface(IWineD3DVolumeTexture *iface, REFIID riid, LPVOID *ppobj)
|
static HRESULT WINAPI IWineD3DVolumeTextureImpl_QueryInterface(IWineD3DVolumeTexture *iface, REFIID riid, LPVOID *ppobj)
|
||||||
{
|
{
|
||||||
IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
||||||
|
@ -110,43 +267,6 @@ static DWORD WINAPI IWineD3DVolumeTextureImpl_GetPriority(IWineD3DVolumeTexture
|
||||||
return resource_get_priority((IWineD3DResource *)iface);
|
return resource_get_priority((IWineD3DResource *)iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
void volumetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb) {
|
|
||||||
/* Overrider the IWineD3DResource Preload method */
|
|
||||||
unsigned int i;
|
|
||||||
IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
|
||||||
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
|
||||||
BOOL srgb_mode = This->baseTexture.is_srgb;
|
|
||||||
BOOL srgb_was_toggled = FALSE;
|
|
||||||
|
|
||||||
TRACE("(%p) : About to load texture\n", This);
|
|
||||||
|
|
||||||
if(!device->isInDraw) {
|
|
||||||
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
|
|
||||||
} else if (GL_SUPPORT(EXT_TEXTURE_SRGB) && This->baseTexture.bindCount > 0) {
|
|
||||||
srgb_mode = device->stateBlock->samplerState[This->baseTexture.sampler][WINED3DSAMP_SRGBTEXTURE];
|
|
||||||
srgb_was_toggled = This->baseTexture.is_srgb != srgb_mode;
|
|
||||||
This->baseTexture.is_srgb = srgb_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the texture is marked dirty or the srgb sampler setting has changed since the last load then reload the surfaces */
|
|
||||||
if (This->baseTexture.dirty) {
|
|
||||||
for (i = 0; i < This->baseTexture.levels; i++)
|
|
||||||
IWineD3DVolume_LoadTexture(This->volumes[i], i, srgb_mode);
|
|
||||||
} else if (srgb_was_toggled) {
|
|
||||||
for (i = 0; i < This->baseTexture.levels; i++) {
|
|
||||||
volume_add_dirty_box(This->volumes[i], NULL);
|
|
||||||
IWineD3DVolume_LoadTexture(This->volumes[i], i, srgb_mode);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
TRACE("(%p) Texture not dirty, nothing to do\n" , iface);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* No longer dirty */
|
|
||||||
This->baseTexture.dirty = FALSE;
|
|
||||||
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void WINAPI IWineD3DVolumeTextureImpl_PreLoad(IWineD3DVolumeTexture *iface) {
|
static void WINAPI IWineD3DVolumeTextureImpl_PreLoad(IWineD3DVolumeTexture *iface) {
|
||||||
volumetexture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY);
|
volumetexture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1712,7 +1712,6 @@ typedef struct IWineD3DBaseTextureClass
|
||||||
void (*internal_preload)(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb);
|
void (*internal_preload)(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb);
|
||||||
} IWineD3DBaseTextureClass;
|
} IWineD3DBaseTextureClass;
|
||||||
|
|
||||||
void volumetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb);
|
|
||||||
void surface_internal_preload(IWineD3DSurface *iface, enum WINED3DSRGB srgb);
|
void surface_internal_preload(IWineD3DSurface *iface, enum WINED3DSRGB srgb);
|
||||||
|
|
||||||
typedef struct IWineD3DBaseTextureImpl
|
typedef struct IWineD3DBaseTextureImpl
|
||||||
|
@ -1833,6 +1832,9 @@ typedef struct IWineD3DVolumeTextureImpl
|
||||||
|
|
||||||
extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
|
extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
|
||||||
|
|
||||||
|
HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT height, UINT depth, UINT levels,
|
||||||
|
IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent);
|
||||||
|
|
||||||
typedef struct _WINED3DSURFACET_DESC
|
typedef struct _WINED3DSURFACET_DESC
|
||||||
{
|
{
|
||||||
WINED3DMULTISAMPLE_TYPE MultiSampleType;
|
WINED3DMULTISAMPLE_TYPE MultiSampleType;
|
||||||
|
|
Loading…
Reference in New Issue