/*		Direct3DTexture implementation
 *
 * Copyright 2001 TransGaming Technologies Inc.
 */

#include "config.h"
#include "winerror.h"

#include <assert.h>
#include <stdlib.h>

#include "wine/debug.h"
#include "ddraw_private.h"
#include "d3d_private.h"
#include "d3ddevice/main.h"
#include "dsurface/main.h"
#include "dsurface/texture.h"

WINE_DEFAULT_DEBUG_CHANNEL(ddraw);

#define CONVERT(pd3dt) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,	\
					  IDirect3DTexture2,		\
					  IDirectDrawSurface7,		\
					  (pd3dt))

static HRESULT WINAPI
Direct3DTexture2_QueryInterface(LPDIRECT3DTEXTURE2 iface, REFIID riid,
				LPVOID *ppObj)
{
    return IDirectDrawSurface7_QueryInterface(CONVERT(iface), riid, ppObj);
}

static ULONG WINAPI
Direct3DTexture2_AddRef(LPDIRECT3DTEXTURE2 iface)
{
    return IDirectDrawSurface7_AddRef(CONVERT(iface));
}

static ULONG WINAPI
Direct3DTexture2_Release(LPDIRECT3DTEXTURE2 iface)
{
    return IDirectDrawSurface7_Release(CONVERT(iface));
}

static HRESULT WINAPI
Direct3DTexture2_GetHandle(LPDIRECT3DTEXTURE2 iface,
			   LPDIRECT3DDEVICE2 lpDirect3DDevice2,
			   LPD3DTEXTUREHANDLE lpHandle)
{
    ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirect3DTexture2, iface);
    TRACE("(%p)->(%p,%p)\n", iface, lpDirect3DDevice2, lpHandle);

    *lpHandle = (D3DTEXTUREHANDLE)This;

    return D3D_OK;
}

static HRESULT WINAPI
Direct3DTexture2_PaletteChanged(LPDIRECT3DTEXTURE2 iface,
				DWORD dwStart, DWORD dwCount)
{
    /* ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirect3DTexture2, iface); */
    TRACE("(%p)->(%ld,%ld)\n", iface, dwStart, dwCount);

    return D3D_OK;
}

static HRESULT WINAPI
Direct3DTexture2_Load(LPDIRECT3DTEXTURE2 iface,
		      LPDIRECT3DTEXTURE2 lpD3DTexture2)
{
    ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirect3DTexture2, iface);
    TRACE("(%p)->(%p)\n", iface, lpD3DTexture2);
    if (iface == lpD3DTexture2) return D3D_OK;
    Main_Direct3DDevice_req_load_texture(This,
					 ICOM_OBJECT(IDirectDrawSurfaceImpl,
						     IDirect3DTexture2,
						     lpD3DTexture2));
    return D3D_OK;
}

#undef CONVERT

ICOM_VTABLE(IDirect3DTexture2) DDRAW_ID3DT2_VTable =
{
    Direct3DTexture2_QueryInterface,
    Direct3DTexture2_AddRef,
    Direct3DTexture2_Release,
    Direct3DTexture2_GetHandle,
    Direct3DTexture2_PaletteChanged,
    Direct3DTexture2_Load
};

#define CONVERT(pd3dt) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,	\
					  IDirect3DTexture,		\
					  IDirectDrawSurface7,		\
					  (pd3dt))
#define CONVERT2(pd3dt) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,	\
					   IDirect3DTexture,		\
					   IDirect3DTexture2,		\
					   (pd3dt))

static HRESULT WINAPI
Direct3DTexture_QueryInterface(LPDIRECT3DTEXTURE iface, REFIID riid,
				    LPVOID *ppObj)
{
    return IDirectDrawSurface7_QueryInterface(CONVERT(iface), riid, ppObj);
}

static ULONG WINAPI
Direct3DTexture_AddRef(LPDIRECT3DTEXTURE iface)
{
    return IDirectDrawSurface7_AddRef(CONVERT(iface));
}

static ULONG WINAPI
Direct3DTexture_Release(LPDIRECT3DTEXTURE iface)
{
    return IDirectDrawSurface7_Release(CONVERT(iface));
}

static HRESULT WINAPI
Direct3DTexture_Initialize(LPDIRECT3DTEXTURE iface,
			   LPDIRECT3DDEVICE lpDirect3DDevice,
			   LPDIRECTDRAWSURFACE lpSurface)
{
    TRACE("(%p)->(%p,%p)\n", iface, lpDirect3DDevice, lpSurface);

    return DDERR_ALREADYINITIALIZED;
}

static HRESULT WINAPI
Direct3DTexture_GetHandle(LPDIRECT3DTEXTURE iface,
			  LPDIRECT3DDEVICE lpDirect3DDevice,
			  LPD3DTEXTUREHANDLE lpHandle)
{
    return IDirect3DTexture2_GetHandle(CONVERT2(iface),
				       COM_INTERFACE_CAST(IDirect3DDeviceImpl,
							  IDirect3DDevice,
							  IDirect3DDevice2,
							  lpDirect3DDevice),
				       lpHandle);
}

static HRESULT WINAPI
Direct3DTexture_PaletteChanged(LPDIRECT3DTEXTURE iface,
			       DWORD dwStart, DWORD dwCount)
{
    return IDirect3DTexture2_PaletteChanged(CONVERT2(iface),
					    dwStart, dwCount);
}

static HRESULT WINAPI
Direct3DTexture_Load(LPDIRECT3DTEXTURE iface,
		     LPDIRECT3DTEXTURE lpD3DTexture)
{
    return IDirect3DTexture2_Load(CONVERT2(iface),
				  CONVERT2(lpD3DTexture));
}

static HRESULT WINAPI
Direct3DTexture_Unload(LPDIRECT3DTEXTURE iface)
{
    TRACE("(%p)\n", iface);

    return D3D_OK;
}

#undef CONVERT7
#undef CONVERT

ICOM_VTABLE(IDirect3DTexture) DDRAW_ID3DT_VTable =
{
    Direct3DTexture_QueryInterface,
    Direct3DTexture_AddRef,
    Direct3DTexture_Release,
    Direct3DTexture_Initialize,
    Direct3DTexture_GetHandle,
    Direct3DTexture_PaletteChanged,
    Direct3DTexture_Load,
    Direct3DTexture_Unload
};
