#include "kamui.h"
#include "kamuix.h"
#include "kmgeo.h"

void kmgInitVertexContext(PKMVERTEXCONTEXT pVertexContext)
{
	memset(pVertexContext, 0, sizeof(KMVERTEXCONTEXT));	/* Crear Context */

	/* 頂点CONTEXTの生成 */
	pVertexContext->RenderState	= KM_DEPTHMODE			| KM_CULLINGMODE
								| KM_SCREENCOORDINATION	| KM_SHADINGMODE
								| KM_MODIFIER			| KM_ZWRITEDISABLE
								| KM_SRCBLENDINGMODE	| KM_DSTBLENDINGMODE
								| KM_SRCSELECT			| KM_DSTSELECT
								| KM_FOGMODE			| KM_USESPECULAR
								| KM_USEALPHA			| KM_IGNORETEXTUREALPHA
								| KM_FLIPUV				| KM_CLAMPUV
								| KM_FILTERMODE			| KM_SUPERSAMPLE
								| KM_MIPMAPDADJUST		| KM_TEXTURESHADINGMODE
								| KM_PARAMTYPE			| KM_LISTTYPE
								| KM_COLORTYPE			| KM_USESPECULAR
								| KM_UVFORMAT			| KM_DCALCEXACT;

	/* for ParameterControlWord */
	pVertexContext->ParamType			= KM_POLYGON;
	pVertexContext->ListType			= KM_OPAQUE_POLYGON;
	pVertexContext->ColorType			= KM_PACKEDCOLOR;
	pVertexContext->bUseSpecular		= FALSE;
	pVertexContext->UVFormat			= KM_32BITUV;

	/* for ISP/TSP InstructionWord */
	pVertexContext->DepthMode			= KM_GREATER;
	pVertexContext->CullingMode			= KM_NOCULLING;
	pVertexContext->ScreenCoordination	= KM_SCREEN;
	pVertexContext->ShadingMode			= KM_NOTEXTUREGOURAUD;
	pVertexContext->SelectModifier		= KM_NOMODIFIER;
	pVertexContext->bZWriteDisable		= FALSE;			/* ARC1にはない */

	/* for TSP ControlWord */
	pVertexContext->SRCBlendingMode		= KM_ONE;
	pVertexContext->DSTBlendingMode		= KM_ZERO;
	pVertexContext->bSRCSel				= FALSE;			/* ARC1にはない */
	pVertexContext->bDSTSel				= FALSE;			/* ARC1にはない */
	pVertexContext->FogMode				= KM_NOFOG;			/* 11はリザーブ */
	pVertexContext->bUseSpecular		= FALSE;
	pVertexContext->bUseAlpha			= FALSE;
	pVertexContext->FlipUV				= KM_NOFLIP;
	pVertexContext->ClampUV				= KM_NOCLAMP;
	pVertexContext->FilterMode			= KM_BILINEAR;
	pVertexContext->bSuperSample		= FALSE;
	pVertexContext->MipMapAdjust		= 0x00000004;		/* D=1.00 */
	pVertexContext->TextureShadingMode	= KM_MODULATE;

	/* for Texture ControlBit */

	/* No effect on ARC1 */
	pVertexContext->bDCalcExact		= FALSE;
	pVertexContext->bColorClamp		= FALSE;
	pVertexContext->PaletteBank		= 0;

	/* for GlobalColorData */
	pVertexContext->fFaceColorAlpha		= 1.0f;		/* Face Color Alpha */
	pVertexContext->fFaceColorRed		= 1.0f;		/* Face Color Red */
	pVertexContext->fFaceColorGreen		= 1.0f;		/* Face Color Green */
	pVertexContext->fFaceColorBlue		= 1.0f;		/* Face Color Blue */
	pVertexContext->fOffsetColorAlpha	= 1.0f;		/* Specular Color Alpha */
	pVertexContext->fOffsetColorRed		= 1.0f;		/* Specular Color Red */
	pVertexContext->fOffsetColorGreen	= 1.0f;		/* Specular Color Green */
	pVertexContext->fOffsetColorBlue	= 1.0f;		/* Specular Color Blue */
	kmProcessVertexRenderState(pVertexContext);
}

void kmgDefaultGouraudOpaqueSetting(PKMVERTEXCONTEXT pVertexContext)
{
	kmgInitVertexContext(pVertexContext);
}

void kmgDefaultGouraudTransSetting(PKMVERTEXCONTEXT pVertexContext)
{
	kmgInitVertexContext(pVertexContext);

	pVertexContext->RenderState			=	KM_SRCBLENDINGMODE	|	KM_DSTBLENDINGMODE		|
											KM_LISTTYPE			|	KM_TEXTURESHADINGMODE	|
											KM_USEALPHA			|	KM_SHADINGMODE;
	pVertexContext->SRCBlendingMode		= KM_SRCALPHA;
	pVertexContext->DSTBlendingMode		= KM_INVSRCALPHA;
	pVertexContext->ListType			= KM_TRANS_POLYGON;
	pVertexContext->TextureShadingMode	= KM_MODULATE_ALPHA;
	pVertexContext->bUseAlpha			= TRUE;
	pVertexContext->ShadingMode			= KM_TEXTUREGOURAUD;
	kmProcessVertexRenderState(pVertexContext);
}

void kmgSetTexture(PKMVERTEXCONTEXT pVertexContext, PKMSURFACEDESC pTextureSurfaceDesc)
{
	pVertexContext->RenderState		= KM_SHADINGMODE;
	pVertexContext->ShadingMode		= KM_TEXTUREGOURAUD;
	pVertexContext->pTextureSurfaceDesc	= pTextureSurfaceDesc;
	kmProcessVertexRenderState(pVertexContext);
}

