/*----------------------------------------------------------------------------
	SoH Nijna Layer
----------------------------------------------------------------------------*/

#include "soh.h"

static NJS_POLYGON_VTX vbuf0[SX_MAX_VERTEX];	/* バーテックスバッファ		*/
static NJS_TEXTURE_VTX vbuf1[SX_MAX_VERTEX];	/* バーテックスバッファ		*/
/*--------------------------------------------------------------------------*/
SXERR sxSetBrendMode(ULONG flag)
{
	switch (flag) {
	case SX_BREND_ON:							/* ブレンドを有効にする		*/
		if (!SDX->isAlpha) {
			njColorBlendingMode( NJD_SOURCE_COLOR     , NJD_COLOR_BLENDING_ONE);
			njColorBlendingMode( NJD_DESTINATION_COLOR, NJD_COLOR_BLENDING_ONE);
		}
		SDX->isBrend=TRUE;
		break;
	case SX_BREND_OFF:							/* ブレンドを無効にする		*/
		njColorBlendingMode( NJD_SOURCE_COLOR     , NJD_COLOR_BLENDING_SRCALPHA);
		njColorBlendingMode( NJD_DESTINATION_COLOR, NJD_COLOR_BLENDING_INVSRCALPHA);
		SDX->isBrend=FALSE;
		break;
	case SX_BREND_ALPHA:						/* αブレンドモードにする	*/
		njColorBlendingMode( NJD_SOURCE_COLOR     , NJD_COLOR_BLENDING_SRCALPHA);
		njColorBlendingMode( NJD_DESTINATION_COLOR, NJD_COLOR_BLENDING_INVSRCALPHA);
		SDX->isAlpha=TRUE;
		break;
	case SX_BREND_ADD:							/* 加算モードにする			*/
		njColorBlendingMode( NJD_SOURCE_COLOR     , NJD_COLOR_BLENDING_ONE);
		njColorBlendingMode( NJD_DESTINATION_COLOR, NJD_COLOR_BLENDING_ONE);
		SDX->isAlpha=FALSE;
		break;
	}
	return SX_OK;
}
/*--------------------------------------------------------------------------*/
SXERR sxSetFilterMode(ULONG flag)
{
	switch (flag) {
	case SX_FILTER_OFF:							/* フィルター無効にする		*/
		njTextureFilterMode( NJD_TEXTUREFILTER_POINT_SAMPLE );
		break;
	case SX_FILTER_BILINEAR:					/* バイリニアを有効にする	*/
		njTextureFilterMode( NJD_TEXTUREFILTER_BILINEAR );
		break;
	case SX_FILTER_TRILINEAR:					/* トライリニアを有効にする	*/
		njTextureFilterMode( NJD_TEXTUREFILTER_TRILINEAR );
		break;
	}
	return SX_OK;
}
/*--------------------------------------------------------------------------*/
SXERR sxDraw3D(ULONG prim, SX_VERTEX *vtx, SLONG num, ULONG flag)
{
	return SX_OK;
}
/*--------------------------------------------------------------------------*/
SXERR sxDraw2D(ULONG prim, SX_VERTEX *vtx, SLONG num, ULONG flag)
{
	SLONG i;
	float z;
	SX_VERTEX *srcV = vtx;
	NJS_TEXTURE_VTX *dstV0 = vbuf1;
	NJS_POLYGON_VTX *dstV1 = vbuf0;
/*	
	if (num<0||num>SX_MAX_VERTEX) {
		return SX_ERR;
	}
*/	
	z=1.f/srcV->z;
	
	if (SDX->isGI>=0) {
		for(i=0; i<num; i++) {
			dstV0->x   = srcV->x;
			dstV0->y   = srcV->y;
			dstV0->z   = z;
			dstV0->u   = srcV->u;
			dstV0->v   = srcV->v;
			dstV0->col = srcV->c.color;
			
			srcV++;
			dstV0++;
		}
		njDrawTexture( vbuf1, num, SDX->isGI, !flag);
	} else {
		for(i=0; i<num; i++) {
			dstV1->x   = srcV->x;
			dstV1->y   = srcV->y;
			dstV1->z   = z;
			dstV1->col = srcV->c.color;
			
			srcV++;
			dstV1++;
		}
		njDrawPolygon( vbuf0, num, !flag);
	}
	return SX_OK;
}
/*--------------------------------------------------------------------------*/
SXERR sxSetBackColor(FLOAT R,FLOAT G,FLOAT B)
{
	SX_COLOR C;
	
	C.argb.r = R*255.f;
	C.argb.g = G*255.f;
	C.argb.b = B*255.f;
	
	njSetBackColor(C.color,C.color,C.color);
	return SX_OK;
}
/*--------------------------------------------------------------------------*/
