/***************************************************************/
//
//
//		DirectX	[ texturedx9interface.cpp ]
//
//											Author	kazuki tanaka
//											Date	2017 5/17
/*---------------------------------------------------------------
■Update : 2017/5/17
			texturedx9interface.cppの作成

/*---------------------------------------------------------------
	Include File
---------------------------------------------------------------*/

#include "texturedx9_interface.h"
#include "texture_manager.h"

#include "rendererdx9.h"
#include "videorenderer.h"

#include "game_manager.h"
#include "window.h"

/*---------------------------------------------------------------
	Macro Difinition
---------------------------------------------------------------*/


/*---------------------------------------------------------------
	Const Number Difinition
---------------------------------------------------------------*/

/*----------------------------------------------------------------
	static member variable Initialize 
----------------------------------------------------------------*/





// TextureDX9Interface Constructor
TextureDX9Interface::TextureDX9Interface( )
	: data( nullptr )
{

	// Menber Clear Process

}

// TextureDX9Interface Destructor
TextureDX9Interface::~TextureDX9Interface( )
{

	// Do Nothing!!

}

// TextureDX9Interface Create Instance 
TextureDX9Interface* TextureDX9Interface::Create( void )
{

	// Create Class Instance
	TextureDX9Interface* pObject;
	pObject = new TextureDX9Interface;

	return pObject;

}

// TextureDX9Interface Initialize
void TextureDX9Interface::Release( void )
{

	// Release Process
	SAFE_RELEASE( data )


}

// TextureDX9Interface SetTexture
void TextureDX9Interface::SetTexture( void )
{

	// TextureDX9Interface SetTexture
	GetDevice( )->SetTexture( 0, data );

}

// TextureDX9Interface Load
bool TextureDX9Interface::Load( const char* FILE_NAME )
{

	// texture format
	const int TEXTURE_FORMAT_MAX = 5;
	const char* TEXTURE_FORMAT[ ] = {
		".jpg",
		".png",
		".tga",
		".bmp",
		".dds"
	};
	
	// video format
	const int VIDEO_FORMAT_MAX = 1;
	const char* VIDEO_FORMAT[ ] = {
		".avi",
	};
	
	// Divide File Name
	char filename [256] = { };		// ファイルネーム
	char extension[256] = { };		// 拡張子
	char loadFile [256] = { };		// ロードファイルネーム

	// Split Path
	_splitpath( FILE_NAME, NULL, NULL, filename, extension );
	
	// Synthesis String < Load File Name >
	sprintf( loadFile, "%s%s", filename , extension );
	
	// Create Texture Interface Process
	for( int index = 0; index < TEXTURE_FORMAT_MAX; index++ ){

		if( strcmp( extension, TEXTURE_FORMAT[index] ) == 0 ){
			
			if( FAILED( D3DXCreateTextureFromFile( GetDevice( ), FILE_NAME, &data )))
			{
				#ifdef _DEBUG
				MessageBox( NULL, loadFile , "Create Texture File ERROR!! : texturedx9_interface.cpp", MB_OK | MB_ICONWARNING );
				#endif	// _DEBUG
				return false;
			}else{
				return true;	
			}
		}
	}
	
	for( int index = 0; index < VIDEO_FORMAT_MAX; index++ ){
	
		if( strcmp( extension, VIDEO_FORMAT[index] ) == 0 ){
			
			if( FAILED( CVideoRenderer::CreateRealtimeRenderTexture( FILE_NAME, &data )))
			{
				#ifdef _DEBUG
				MessageBox( NULL, loadFile , "Create Texture File ERROR!! : texturedx9_interface.cpp", MB_OK | MB_ICONWARNING );
				#endif	// _DEBUG
				return false;
			}else{
				return true;	
			}
		}	
	}
	
	return false;

}

// TextureDX9Interface Load From Manager
TextureInterface* TextureDX9Interface::LoadFromManager( const char* FILE_NAME )
{

	if( TextureManager::Load( FILE_NAME ) ){
	
		return TextureManager::Bind( FILE_NAME );
	}

	return nullptr;

}


