#include"../../Maid/FrameWork/Windows/CSingleWindowAppWindows.h"

#include"../../Maid/Graphic/CGraphic.h"

#include"../../Maid/Graphic/CPixelShader.h"
#include"../../Maid/Graphic/CVertexShader.h"
#include"../../Maid/Graphic/CVertexMemory.h"

#include"../../Maid/Graphic/CCustomVertexTemplate.h"

using namespace Maid;


class CApp : public IGameThread
{
protected:
	void OnLocalSetup( APPCONFIG& conf )
	{

	}

	void OnLocalEnd()
	{

	}

	void OnLocalBegin( const BEGINPARAM& param )
	{
		{
			CGraphic::SCREENMODE m;

			m.Mode = CGraphic::SCREENMODE::TYPE_WINDOW;
			m.Size = SIZE2DI(800,600);
			m.RefreshRate = 0;
			m.IsSoftTnL = false;
			m.IsWaitVSync = true;
			m.IsAspectLock = false;

			m_Graphic.Initialize( m, param.pFontDriver, param.pInfo );
		}
		{
			vs.Create( VERTEXSHADERNAME::RHWCOLOR );
			ps.Create( PIXELSHADERNAME::VERTEXCOLOR_ADD );

			{
				CUSTOMVERTEX_COLOR v[] =
				{
					CUSTOMVERTEX_COLOR(POINT3DF(100,100,0), 1.0f, COLOR_A08R08G08B08I(0xFF,0xFF,0x00,0x00) ),
					CUSTOMVERTEX_COLOR(POINT3DF(100,200,0), 1.0f, COLOR_A08R08G08B08I(0xFF,0xFF,0x00,0x00) ),
					CUSTOMVERTEX_COLOR(POINT3DF(200,100,0), 1.0f, COLOR_A08R08G08B08I(0xFF,0xFF,0x00,0x00) ),
				};

				vertex.Create( v[0].GetVertexFormat(), v, NUMELEMENTS(v) );
			}
		}
	}

	void OnLocalLoop()
	{
		//	ここで描画命令を出す
		m_Graphic.ClearRenderTargetColor( COLOR_A08R08G08B08I(0xFF,0x00,0x00,0x80) );

		//	2Dな描画(矩形塗りつぶし)
		m_Graphic.Fill( RECT2DI(150,100,100,100), COLOR_A08R08G08B08I(0xFF,0x00,0xFF,0x00) );

		//	自分でいろいろ設定して描画
		{

			m_Graphic.SetVertexShader( vs );
			m_Graphic.SetPixelShader( ps );
			m_Graphic.SetVertex( vertex );
			m_Graphic.DrawPrimitive( CGraphic::PRIMITIVE_TRIANGLESTRIP, 0, 1 );
		}


		//	次のフレームへ
		OnNextFrame(m_Graphic);
		::Sleep(100);
	}


private:
	CGraphic		m_Graphic;
	CVertexShaderDefault vs;	//	頂点変換済みの頂点＆頂点色をそのままながすシェーダー
	CPixelShaderDefault ps;	//	加算するピクセルシェーダー
	CVertexMemory vertex;
};


int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
	CSingleWindowAppWindows capp( SPGAMETHREAD( new CApp ) );
	return capp.Run( hInstance, hPrevInstance, lpCmdLine, nCmdShow );
}