//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	FeatureGrid::BLENDFUNCTION (
		FeatureInstance *featureInstance, 
		unsigned char *pix_buf, 
		int start_span, 
		int end_span,
		int downScale
	)
{
#ifdef TEXTURE_HORIZONTAL_FLIP
#else
#endif
	unsigned char *mask0data = featureInstance->currentMask0Ptr;

#ifdef SHOW_MATERIAL
	DWORD mat_color = downScale & 0xffffff;
	downScale >>= 24;
#else
	int texture_width = (featureInstance->feature->featureTexture->width) >> downScale;
	int count_down = featureInstance->countDownToBorder;
	WORD *data_ptr_word = (WORD *)featureInstance->currentTexturePtr;
#endif

#ifdef MASK0_HORIZONTAL_FLIP
	int i, j;
	for(i=0,j=0;i<end_span-start_span;i++,j--)
#else
	for(int i=0;i<end_span-start_span;i++)
#endif
	{
#ifdef MASK0_HORIZONTAL_FLIP
		int alpha = mask0data[j];

	#ifdef SHOW_MATERIAL
		if(alpha>0x80)
		{
			*(DWORD *)pix_buf = mat_color;
		}
	#else	//	SHOW_MATERIAL
		if(alpha>0)
		{
			int col = *pix_buf*(0xff-alpha) + ((data_ptr_word[j] & 0x1f)<<3)*alpha;
			*pix_buf = static_cast<unsigned char>(col>>8);

			col = *(pix_buf+1)*(0xff-alpha) + ((data_ptr_word[j] & 0x3e0)>>2)*alpha;
			*(pix_buf+1) = static_cast<unsigned char>(col>>8);

			col = *(pix_buf+2)*(0xff-alpha) + ((data_ptr_word[j] & 0x7c00)>>7)*alpha;
			*(pix_buf+2) = static_cast<unsigned char>(col>>8);
		}

		if(--count_down <= 0)
		{
			data_ptr_word += texture_width;
			count_down = texture_width;
		}
	#endif	//	SHOW_MATERIAL
#else
		int alpha = mask0data[i];

	#ifdef SHOW_MATERIAL
		if(alpha>0x80)
		{
			*(DWORD *)pix_buf = mat_color;
		}
	#else	//	SHOW_MATERIAL
		if(alpha>0)
		{
			int col = *pix_buf*(0xff-alpha) + ((data_ptr_word[i] & 0x1f)<<3)*alpha;
			*pix_buf = static_cast<unsigned char>(col>>8);

			col = *(pix_buf+1)*(0xff-alpha) + ((data_ptr_word[i] & 0x3e0)>>2)*alpha;
			*(pix_buf+1) = static_cast<unsigned char>(col>>8);

			col = *(pix_buf+2)*(0xff-alpha) + ((data_ptr_word[i] & 0x7c00)>>7)*alpha;
			*(pix_buf+2) = static_cast<unsigned char>(col>>8);
		}

		if(--count_down <= 0)
		{
			data_ptr_word -= texture_width;
			count_down = texture_width;
		}
	#endif	//	SHOW_MATERIAL
#endif

		pix_buf += colorDepth;
	}

}