wined3d: Add a separate function for volume initialization.

This commit is contained in:
Henri Verbeet 2009-09-16 08:37:16 +02:00 committed by Alexandre Julliard
parent a5214c306f
commit 2b2d3de025
3 changed files with 47 additions and 32 deletions

View File

@ -1040,15 +1040,12 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVolume(IWineD3DDevice *iface,
UINT Width, UINT Height, UINT Depth, DWORD Usage, WINED3DFORMAT Format,
WINED3DPOOL Pool, IWineD3DVolume **ppVolume, IUnknown *parent)
{
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
IWineD3DVolumeImpl *object; /** NOTE: impl ref allowed since this is a create function **/
const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(Format, &GLINFO_LOCATION);
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
IWineD3DVolumeImpl *object;
HRESULT hr;
if(!GL_SUPPORT(EXT_TEXTURE3D)) {
WARN("(%p) : Volume cannot be created - no volume texture support\n", This);
return WINED3DERR_INVALIDCALL;
}
TRACE("(%p) : W(%d) H(%d) D(%d), Usage(%d), Fmt(%u,%s), Pool(%s)\n", This, Width, Height,
Depth, Usage, Format, debug_d3dformat(Format), debug_d3dpool(Pool));
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if (!object)
@ -1058,36 +1055,17 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVolume(IWineD3DDevice *iface,
return WINED3DERR_OUTOFVIDEOMEMORY;
}
object->lpVtbl = &IWineD3DVolume_Vtbl;
hr = resource_init((IWineD3DResource *)object, WINED3DRTYPE_VOLUME, This,
Width * Height * Depth * format_desc->byte_count, Usage, format_desc, Pool, parent);
hr = volume_init(object, This, Width, Height, Depth, Usage, Format, Pool, parent);
if (FAILED(hr))
{
WARN("Failed to initialize resource, returning %#x\n", hr);
WARN("Failed to initialize volume, returning %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
*ppVolume = NULL;
return hr;
}
TRACE("(%p) : Created resource %p\n", This, object);
TRACE("(%p) : Created volume %p.\n", This, object);
*ppVolume = (IWineD3DVolume *)object;
TRACE("(%p) : W(%d) H(%d) D(%d), Usage(%d), Fmt(%u,%s), Pool(%s)\n", This, Width, Height,
Depth, Usage, Format, debug_d3dformat(Format), debug_d3dpool(Pool));
object->currentDesc.Width = Width;
object->currentDesc.Height = Height;
object->currentDesc.Depth = Depth;
/** Note: Volume textures cannot be dxtn, hence no need to check here **/
object->lockable = TRUE;
object->locked = FALSE;
memset(&object->lockedBox, 0, sizeof(WINED3DBOX));
object->dirty = TRUE;
volume_add_dirty_box((IWineD3DVolume *)object, NULL);
return WINED3D_OK;
}

View File

@ -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
@ -346,7 +347,7 @@ static HRESULT WINAPI IWineD3DVolumeImpl_LoadTexture(IWineD3DVolume *iface, int
}
const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl =
static const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl =
{
/* IUnknown */
IWineD3DVolumeImpl_QueryInterface,
@ -372,3 +373,39 @@ const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl =
IWineD3DVolumeImpl_LoadTexture,
IWineD3DVolumeImpl_SetContainer
};
HRESULT volume_init(IWineD3DVolumeImpl *volume, IWineD3DDeviceImpl *device, UINT width, UINT height,
UINT depth, 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);
HRESULT hr;
if (!gl_info->supported[EXT_TEXTURE3D])
{
WARN("Volume cannot be created - no volume texture support.\n");
return WINED3DERR_INVALIDCALL;
}
volume->lpVtbl = &IWineD3DVolume_Vtbl;
hr = resource_init((IWineD3DResource *)volume, WINED3DRTYPE_VOLUME, device,
width * height * depth * format_desc->byte_count, usage, format_desc, pool, parent);
if (FAILED(hr))
{
WARN("Failed to initialize resource, returning %#x.\n", hr);
return hr;
}
volume->currentDesc.Width = width;
volume->currentDesc.Height = height;
volume->currentDesc.Depth = depth;
volume->lockable = TRUE;
volume->locked = FALSE;
memset(&volume->lockedBox, 0, sizeof(volume->lockedBox));
volume->dirty = TRUE;
volume_add_dirty_box((IWineD3DVolume *)volume, NULL);
return WINED3D_OK;
}

View File

@ -1875,9 +1875,9 @@ typedef struct IWineD3DVolumeImpl
BOOL dirty;
} IWineD3DVolumeImpl;
extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl DECLSPEC_HIDDEN;
void volume_add_dirty_box(IWineD3DVolume *iface, const WINED3DBOX *dirty_box) DECLSPEC_HIDDEN;
HRESULT volume_init(IWineD3DVolumeImpl *volume, IWineD3DDeviceImpl *device, UINT width, UINT height,
UINT depth, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent) DECLSPEC_HIDDEN;
/*****************************************************************************
* IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)