d3dx9: Get rid of the ID3DXSpriteImpl typedef.
This commit is contained in:
parent
0a993f14b4
commit
0f965d16f0
|
@ -41,7 +41,7 @@ typedef struct _SPRITE {
|
|||
D3DXMATRIX transform;
|
||||
} SPRITE;
|
||||
|
||||
typedef struct ID3DXSpriteImpl
|
||||
struct d3dx9_sprite
|
||||
{
|
||||
ID3DXSprite ID3DXSprite_iface;
|
||||
LONG ref;
|
||||
|
@ -62,14 +62,14 @@ typedef struct ID3DXSpriteImpl
|
|||
SPRITE *sprites;
|
||||
int sprite_count; /* number of sprites to be drawn */
|
||||
int allocated_sprites; /* number of (pre-)allocated sprites */
|
||||
} ID3DXSpriteImpl;
|
||||
};
|
||||
|
||||
static inline ID3DXSpriteImpl *impl_from_ID3DXSprite(ID3DXSprite *iface)
|
||||
static inline struct d3dx9_sprite *impl_from_ID3DXSprite(ID3DXSprite *iface)
|
||||
{
|
||||
return CONTAINING_RECORD(iface, ID3DXSpriteImpl, ID3DXSprite_iface);
|
||||
return CONTAINING_RECORD(iface, struct d3dx9_sprite, ID3DXSprite_iface);
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ID3DXSpriteImpl_QueryInterface(ID3DXSprite *iface, REFIID riid, void **out)
|
||||
static HRESULT WINAPI d3dx9_sprite_QueryInterface(ID3DXSprite *iface, REFIID riid, void **out)
|
||||
{
|
||||
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
|
||||
|
||||
|
@ -87,76 +87,91 @@ static HRESULT WINAPI ID3DXSpriteImpl_QueryInterface(ID3DXSprite *iface, REFIID
|
|||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
static ULONG WINAPI ID3DXSpriteImpl_AddRef(ID3DXSprite *iface)
|
||||
static ULONG WINAPI d3dx9_sprite_AddRef(ID3DXSprite *iface)
|
||||
{
|
||||
ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
|
||||
ULONG ref=InterlockedIncrement(&This->ref);
|
||||
TRACE("(%p)->(): AddRef from %d\n", This, ref-1);
|
||||
return ref;
|
||||
struct d3dx9_sprite *sprite = impl_from_ID3DXSprite(iface);
|
||||
ULONG refcount = InterlockedIncrement(&sprite->ref);
|
||||
|
||||
TRACE("%p increasing refcount to %u.\n", sprite, refcount);
|
||||
|
||||
return refcount;
|
||||
}
|
||||
|
||||
static ULONG WINAPI ID3DXSpriteImpl_Release(ID3DXSprite *iface)
|
||||
static ULONG WINAPI d3dx9_sprite_Release(ID3DXSprite *iface)
|
||||
{
|
||||
ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
|
||||
ULONG ref=InterlockedDecrement(&This->ref);
|
||||
struct d3dx9_sprite *sprite = impl_from_ID3DXSprite(iface);
|
||||
ULONG refcount = InterlockedDecrement(&sprite->ref);
|
||||
|
||||
TRACE("(%p)->(): ReleaseRef to %d\n", This, ref);
|
||||
TRACE("%p decreasing refcount to %u.\n", sprite, refcount);
|
||||
|
||||
if(ref==0) {
|
||||
if(This->sprites) {
|
||||
if (!refcount)
|
||||
{
|
||||
if (sprite->sprites)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<This->sprite_count;i++)
|
||||
if(This->sprites[i].texture)
|
||||
IDirect3DTexture9_Release(This->sprites[i].texture);
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, This->sprites);
|
||||
for (i = 0; i < sprite->sprite_count; ++i)
|
||||
{
|
||||
if (sprite->sprites[i].texture)
|
||||
IDirect3DTexture9_Release(sprite->sprites[i].texture);
|
||||
}
|
||||
if(This->stateblock) IDirect3DStateBlock9_Release(This->stateblock);
|
||||
if(This->vdecl) IDirect3DVertexDeclaration9_Release(This->vdecl);
|
||||
if(This->device) IDirect3DDevice9_Release(This->device);
|
||||
HeapFree(GetProcessHeap(), 0, This);
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, sprite->sprites);
|
||||
}
|
||||
return ref;
|
||||
|
||||
if (sprite->stateblock)
|
||||
IDirect3DStateBlock9_Release(sprite->stateblock);
|
||||
if (sprite->vdecl)
|
||||
IDirect3DVertexDeclaration9_Release(sprite->vdecl);
|
||||
if (sprite->device)
|
||||
IDirect3DDevice9_Release(sprite->device);
|
||||
HeapFree(GetProcessHeap(), 0, sprite);
|
||||
}
|
||||
|
||||
return refcount;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ID3DXSpriteImpl_GetDevice(struct ID3DXSprite *iface, struct IDirect3DDevice9 **device)
|
||||
static HRESULT WINAPI d3dx9_sprite_GetDevice(struct ID3DXSprite *iface, struct IDirect3DDevice9 **device)
|
||||
{
|
||||
ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
|
||||
struct d3dx9_sprite *sprite = impl_from_ID3DXSprite(iface);
|
||||
|
||||
TRACE("(%p)->(%p)\n", This, device);
|
||||
TRACE("iface %p, device %p.\n", iface, device);
|
||||
|
||||
if(device==NULL) return D3DERR_INVALIDCALL;
|
||||
*device=This->device;
|
||||
IDirect3DDevice9_AddRef(This->device);
|
||||
if (!device)
|
||||
return D3DERR_INVALIDCALL;
|
||||
*device = sprite->device;
|
||||
IDirect3DDevice9_AddRef(sprite->device);
|
||||
|
||||
return D3D_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ID3DXSpriteImpl_GetTransform(ID3DXSprite *iface, D3DXMATRIX *transform)
|
||||
static HRESULT WINAPI d3dx9_sprite_GetTransform(ID3DXSprite *iface, D3DXMATRIX *transform)
|
||||
{
|
||||
ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
|
||||
|
||||
TRACE("(%p)->(%p)\n", This, transform);
|
||||
|
||||
if(transform==NULL) return D3DERR_INVALIDCALL;
|
||||
*transform=This->transform;
|
||||
|
||||
return D3D_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ID3DXSpriteImpl_SetTransform(ID3DXSprite *iface, const D3DXMATRIX *transform)
|
||||
{
|
||||
ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
|
||||
struct d3dx9_sprite *sprite = impl_from_ID3DXSprite(iface);
|
||||
|
||||
TRACE("iface %p, transform %p.\n", iface, transform);
|
||||
|
||||
if(transform==NULL) return D3DERR_INVALIDCALL;
|
||||
This->transform=*transform;
|
||||
if (!transform)
|
||||
return D3DERR_INVALIDCALL;
|
||||
*transform = sprite->transform;
|
||||
|
||||
return D3D_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ID3DXSpriteImpl_SetWorldViewRH(ID3DXSprite *iface,
|
||||
static HRESULT WINAPI d3dx9_sprite_SetTransform(ID3DXSprite *iface, const D3DXMATRIX *transform)
|
||||
{
|
||||
struct d3dx9_sprite *sprite = impl_from_ID3DXSprite(iface);
|
||||
|
||||
TRACE("iface %p, transform %p.\n", iface, transform);
|
||||
|
||||
if (!transform)
|
||||
return D3DERR_INVALIDCALL;
|
||||
sprite->transform = *transform;
|
||||
|
||||
return D3D_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI d3dx9_sprite_SetWorldViewRH(ID3DXSprite *iface,
|
||||
const D3DXMATRIX *world, const D3DXMATRIX *view)
|
||||
{
|
||||
FIXME("iface %p, world %p, view %p stub!\n", iface, world, view);
|
||||
|
@ -164,7 +179,7 @@ static HRESULT WINAPI ID3DXSpriteImpl_SetWorldViewRH(ID3DXSprite *iface,
|
|||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ID3DXSpriteImpl_SetWorldViewLH(ID3DXSprite *iface,
|
||||
static HRESULT WINAPI d3dx9_sprite_SetWorldViewLH(ID3DXSprite *iface,
|
||||
const D3DXMATRIX *world, const D3DXMATRIX *view)
|
||||
{
|
||||
FIXME("iface %p, world %p, view %p stub!\n", iface, world, view);
|
||||
|
@ -173,7 +188,7 @@ static HRESULT WINAPI ID3DXSpriteImpl_SetWorldViewLH(ID3DXSprite *iface,
|
|||
}
|
||||
|
||||
/* Helper function */
|
||||
static void set_states(ID3DXSpriteImpl *object)
|
||||
static void set_states(struct d3dx9_sprite *object)
|
||||
{
|
||||
D3DXMATRIX mat;
|
||||
D3DVIEWPORT9 vp;
|
||||
|
@ -254,12 +269,12 @@ static void set_states(ID3DXSpriteImpl *object)
|
|||
IDirect3DDevice9_SetTransform(object->device, D3DTS_PROJECTION, &mat);
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ID3DXSpriteImpl_Begin(ID3DXSprite *iface, DWORD flags)
|
||||
static HRESULT WINAPI d3dx9_sprite_Begin(ID3DXSprite *iface, DWORD flags)
|
||||
{
|
||||
ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
|
||||
struct d3dx9_sprite *This = impl_from_ID3DXSprite(iface);
|
||||
HRESULT hr;
|
||||
|
||||
TRACE("(%p)->(%#x)\n", This, flags);
|
||||
TRACE("iface %p, flags %#x.\n", iface, flags);
|
||||
|
||||
if(flags>D3DXSPRITE_FLAGLIMIT || This->ready) return D3DERR_INVALIDCALL;
|
||||
|
||||
|
@ -318,10 +333,10 @@ D3DXSPRITE_SORT_TEXTURE: sort by texture (so that it doesn't change too often)
|
|||
return D3D_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ID3DXSpriteImpl_Draw(ID3DXSprite *iface, IDirect3DTexture9 *texture,
|
||||
static HRESULT WINAPI d3dx9_sprite_Draw(ID3DXSprite *iface, IDirect3DTexture9 *texture,
|
||||
const RECT *rect, const D3DXVECTOR3 *center, const D3DXVECTOR3 *position, D3DCOLOR color)
|
||||
{
|
||||
ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
|
||||
struct d3dx9_sprite *This = impl_from_ID3DXSprite(iface);
|
||||
D3DSURFACE_DESC texdesc;
|
||||
|
||||
TRACE("iface %p, texture %p, rect %s, center %p, position %p, color 0x%08x.\n",
|
||||
|
@ -380,13 +395,13 @@ static HRESULT WINAPI ID3DXSpriteImpl_Draw(ID3DXSprite *iface, IDirect3DTexture9
|
|||
return D3D_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ID3DXSpriteImpl_Flush(ID3DXSprite *iface)
|
||||
static HRESULT WINAPI d3dx9_sprite_Flush(ID3DXSprite *iface)
|
||||
{
|
||||
ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
|
||||
struct d3dx9_sprite *This = impl_from_ID3DXSprite(iface);
|
||||
SPRITEVERTEX *vertices;
|
||||
int i, count=0, start;
|
||||
|
||||
TRACE("(%p)->()\n", This);
|
||||
TRACE("iface %p.\n", iface);
|
||||
|
||||
if(!This->ready) return D3DERR_INVALIDCALL;
|
||||
if(!This->sprite_count) return D3D_OK;
|
||||
|
@ -454,34 +469,37 @@ static HRESULT WINAPI ID3DXSpriteImpl_Flush(ID3DXSprite *iface)
|
|||
return D3D_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ID3DXSpriteImpl_End(ID3DXSprite *iface)
|
||||
static HRESULT WINAPI d3dx9_sprite_End(ID3DXSprite *iface)
|
||||
{
|
||||
ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
|
||||
struct d3dx9_sprite *sprite = impl_from_ID3DXSprite(iface);
|
||||
|
||||
TRACE("(%p)->()\n", This);
|
||||
TRACE("iface %p.\n", iface);
|
||||
|
||||
if(!This->ready) return D3DERR_INVALIDCALL;
|
||||
if (!sprite->ready)
|
||||
return D3DERR_INVALIDCALL;
|
||||
|
||||
ID3DXSprite_Flush(iface);
|
||||
|
||||
if(!(This->flags & D3DXSPRITE_DONOTSAVESTATE))
|
||||
if(This->stateblock) IDirect3DStateBlock9_Apply(This->stateblock); /* Restore old state */
|
||||
if (sprite->stateblock && !(sprite->flags & D3DXSPRITE_DONOTSAVESTATE))
|
||||
IDirect3DStateBlock9_Apply(sprite->stateblock); /* Restore old state */
|
||||
|
||||
This->ready=FALSE;
|
||||
sprite->ready = FALSE;
|
||||
|
||||
return D3D_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ID3DXSpriteImpl_OnLostDevice(ID3DXSprite *iface)
|
||||
static HRESULT WINAPI d3dx9_sprite_OnLostDevice(ID3DXSprite *iface)
|
||||
{
|
||||
ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
|
||||
struct d3dx9_sprite *sprite = impl_from_ID3DXSprite(iface);
|
||||
|
||||
TRACE("(%p)->()\n", This);
|
||||
TRACE("iface %p.\n", iface);
|
||||
|
||||
if(This->stateblock) IDirect3DStateBlock9_Release(This->stateblock);
|
||||
if(This->vdecl) IDirect3DVertexDeclaration9_Release(This->vdecl);
|
||||
This->vdecl=NULL;
|
||||
This->stateblock=NULL;
|
||||
if (sprite->stateblock)
|
||||
IDirect3DStateBlock9_Release(sprite->stateblock);
|
||||
if (sprite->vdecl)
|
||||
IDirect3DVertexDeclaration9_Release(sprite->vdecl);
|
||||
sprite->vdecl = NULL;
|
||||
sprite->stateblock = NULL;
|
||||
|
||||
/* Reset some variables */
|
||||
ID3DXSprite_OnResetDevice(iface);
|
||||
|
@ -489,21 +507,22 @@ static HRESULT WINAPI ID3DXSpriteImpl_OnLostDevice(ID3DXSprite *iface)
|
|||
return D3D_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ID3DXSpriteImpl_OnResetDevice(ID3DXSprite *iface)
|
||||
static HRESULT WINAPI d3dx9_sprite_OnResetDevice(ID3DXSprite *iface)
|
||||
{
|
||||
ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
|
||||
struct d3dx9_sprite *sprite = impl_from_ID3DXSprite(iface);
|
||||
int i;
|
||||
|
||||
TRACE("(%p)->()\n", This);
|
||||
TRACE("iface %p.\n", iface);
|
||||
|
||||
for(i=0;i<This->sprite_count;i++)
|
||||
if(This->sprites[i].texture)
|
||||
IDirect3DTexture9_Release(This->sprites[i].texture);
|
||||
for (i = 0; i < sprite->sprite_count; ++i)
|
||||
{
|
||||
if (sprite->sprites[i].texture)
|
||||
IDirect3DTexture9_Release(sprite->sprites[i].texture);
|
||||
}
|
||||
|
||||
This->sprite_count=0;
|
||||
|
||||
This->flags=0;
|
||||
This->ready=FALSE;
|
||||
sprite->sprite_count = 0;
|
||||
sprite->flags = 0;
|
||||
sprite->ready = FALSE;
|
||||
|
||||
/* keep matrices */
|
||||
/* device objects get restored on Begin */
|
||||
|
@ -511,41 +530,39 @@ static HRESULT WINAPI ID3DXSpriteImpl_OnResetDevice(ID3DXSprite *iface)
|
|||
return D3D_OK;
|
||||
}
|
||||
|
||||
static const ID3DXSpriteVtbl D3DXSprite_Vtbl =
|
||||
static const ID3DXSpriteVtbl d3dx9_sprite_vtbl =
|
||||
{
|
||||
/*** IUnknown methods ***/
|
||||
ID3DXSpriteImpl_QueryInterface,
|
||||
ID3DXSpriteImpl_AddRef,
|
||||
ID3DXSpriteImpl_Release,
|
||||
/*** ID3DXSprite methods ***/
|
||||
ID3DXSpriteImpl_GetDevice,
|
||||
ID3DXSpriteImpl_GetTransform,
|
||||
ID3DXSpriteImpl_SetTransform,
|
||||
ID3DXSpriteImpl_SetWorldViewRH,
|
||||
ID3DXSpriteImpl_SetWorldViewLH,
|
||||
ID3DXSpriteImpl_Begin,
|
||||
ID3DXSpriteImpl_Draw,
|
||||
ID3DXSpriteImpl_Flush,
|
||||
ID3DXSpriteImpl_End,
|
||||
ID3DXSpriteImpl_OnLostDevice,
|
||||
ID3DXSpriteImpl_OnResetDevice
|
||||
d3dx9_sprite_QueryInterface,
|
||||
d3dx9_sprite_AddRef,
|
||||
d3dx9_sprite_Release,
|
||||
d3dx9_sprite_GetDevice,
|
||||
d3dx9_sprite_GetTransform,
|
||||
d3dx9_sprite_SetTransform,
|
||||
d3dx9_sprite_SetWorldViewRH,
|
||||
d3dx9_sprite_SetWorldViewLH,
|
||||
d3dx9_sprite_Begin,
|
||||
d3dx9_sprite_Draw,
|
||||
d3dx9_sprite_Flush,
|
||||
d3dx9_sprite_End,
|
||||
d3dx9_sprite_OnLostDevice,
|
||||
d3dx9_sprite_OnResetDevice,
|
||||
};
|
||||
|
||||
HRESULT WINAPI D3DXCreateSprite(struct IDirect3DDevice9 *device, struct ID3DXSprite **sprite)
|
||||
{
|
||||
ID3DXSpriteImpl *object;
|
||||
struct d3dx9_sprite *object;
|
||||
D3DCAPS9 caps;
|
||||
|
||||
TRACE("(%p, %p)\n", device, sprite);
|
||||
TRACE("device %p, sprite %p.\n", device, sprite);
|
||||
|
||||
if(device==NULL || sprite==NULL) return D3DERR_INVALIDCALL;
|
||||
|
||||
object=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXSpriteImpl));
|
||||
if(object==NULL) {
|
||||
*sprite=NULL;
|
||||
if (!(object=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
|
||||
{
|
||||
*sprite = NULL;
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
object->ID3DXSprite_iface.lpVtbl = &D3DXSprite_Vtbl;
|
||||
object->ID3DXSprite_iface.lpVtbl = &d3dx9_sprite_vtbl;
|
||||
object->ref=1;
|
||||
object->device=device;
|
||||
IUnknown_AddRef(device);
|
||||
|
|
Loading…
Reference in New Issue