/*****************************************************************************
  Name : KMTexture.c
  Date : August 1998
  Platform : ANSI compatible
 
  * Description : 
  This file is part of the KAMUI TOOLS library (KMTools.lib) used
  with the SDK demos for PowerVR series 2.

  Set of functions used in texturing.
  

  Copyright : 1998 by VideoLogic Limited. All rights reserved.
******************************************************************************/

#include "KMTools.h"

/*----------------------------------------------------------------------*/
/*  Function Name   : KMTextureLoad                                       */
/*  Inputs          : pTextureSurfaceDesc, pSourceTex, SizeX, SizeY,    */  
/*                    nTextureType,                                     */
/*  Outputs         : None                                              */
/*  Returns         : ErrorCode                                         */
/*  Globals Used    : None                                              */
/*  Description     : This function loads in video memory a square      */
/*                    texture already set in a memory buffer.           */       
/*----------------------------------------------------------------------*/
KMDWORD KMTextureLoad(KMSURFACEDESC *pTexSurfaceDesc, unsigned long *pSourceTex, KMINT32 Size, KMTEXTURETYPE nTextureType)
{
KMDWORD ErrorCode;

	/* Create texture surface */
	ErrorCode = kmCreateTextureSurface(
		pTexSurfaceDesc,		/* OUT	PKMSURFACEDESC	pSurfaceDesc */
		Size,					/*	IN	KMINT32			nWidth */
		Size,					/*	IN	KMINT32			nHeight */
		nTextureType			/*	IN	KMTEXTURETYPE	nTextureType */
	);

	if (ErrorCode != KMSTATUS_SUCCESS) return ErrorCode;


	/* Load and set texture */
	ErrorCode = kmLoadTexture( 
		pTexSurfaceDesc,						/* PKMSURFACEDESC pSurfaceDesc */
		pSourceTex + (16 / sizeof(KMDWORD)),	/* PKMDWORD pTexture */
		FALSE,									/* KMBOOLEAN bAutoMipMap */
		FALSE									/* KMBOOLEAN bDither */
	);

	if (ErrorCode != KMSTATUS_SUCCESS) return ErrorCode;

	/* Everything's OK */
	return KMSTATUS_SUCCESS;
}