#pragma once

#include "Mix/Scene/IParticleProcessor.h"
#include "Mix/Geometry/AABB.h"
#include "Mix/Private/Container.h"
#include "Mix/Private/Scene/Common/WidgetTypes.h"
#include "Mix/Scene/IParticleSystem.h"

namespace Mix{ namespace Scene{ namespace Common{

	class InternalParticle
	{
	protected:
		Mix::Scene::IMaterial* m_pMaterial;
		UInt32 m_VertexDataSize;
		UInt32 m_VertexTWOffset;

		Mix::DynamicContainerT<Mix::Scene::Common::WIDGET_QUAD, Mix::Memory::SECTION_SCENE> m_QuadPool; //派生先のクラスで初期化する

#ifdef _DEBUG
		Mix::StringW m_DebugName;
		UInt32 m_DebVertexStride;
#endif //_DEBUG
		
	protected:
		////////////////////////////////////////////////////////////////////////////////////////////////////
		// 共通
		////////////////////////////////////////////////////////////////////////////////////////////////////

		InternalParticle( const wchar_t* pDebugName );
		virtual ~InternalParticle( void );

		void GetMaterial( Mix::Scene::IMaterial** ppMaterial );
		Boolean SetMaterial( Mix::Scene::IMaterial* pMaterial );

		void FlashQuads( void ); // クワッドに必要な情報を設定
		void ExtendQuadsPool( UInt32 addCount ); // クワッドプールの拡張

	public:
		//設定できるマテリアルのチェック
		static Boolean CheckMaterial( Mix::Scene::IMaterial* pMaterial, const wchar_t* pLabel, const wchar_t* pDebugName );
		//サブセットにビルボード行列を適用する
		static void FixedBillboardSubset( const Mix::Matrix4x4& mat, Mix::Scene::Common::WIDGET_QUAD** quads, UInt32 quadNum );

	protected:
		////////////////////////////////////////////////////////////////////////////////////////////////////
		// リービング
		//   subset の quadCount ppQuads bounds.min bounds.max を更新( ComputePoints は行っていません )
		////////////////////////////////////////////////////////////////////////////////////////////////////

		void RefreshDefaultSubset(	Boolean bIndividual,
									const Mix::Matrix4x4& worldMat,
									const Mix::Scene::IParticleProcessor::FACE* faces,
									UInt32 faceNum,
									UInt32 quadOffset,
									Mix::Scene::Common::WIDGET_AABB_SUBSET& subset );

		void RefreshBillboardSubset(	Boolean bIndividual,
										const Mix::Matrix4x4& worldMat,
										const Mix::Scene::IParticleProcessor::FACE* faces,
										UInt32 faceNum,
										UInt32 quadOffset,
										Mix::Scene::Common::WIDGET_AABB_SUBSET& subset );

		////////////////////////////////////////////////////////////////////////////////////////////////////
		// スキャッター
		//   subset の quadCount ppQuads bounds.center bounds.radius を更新
		////////////////////////////////////////////////////////////////////////////////////////////////////

		void RefreshDefaultSubset(	const Mix::Matrix4x4& worldMat,
									const Mix::Scene::IParticleProcessor::FACE* faces,
									UInt32 faceNum,
									UInt32 quadOffset,
									Mix::Scene::Common::WIDGET_SPHERE_SUBSET& subset );

		void RefreshBillboardSubset(	const Mix::Scene::IParticleProcessor::FACE* faces,
										UInt32 faceNum,
										UInt32 quadOffset,
										Mix::Scene::Common::WIDGET_SPHERE_SUBSET& subset );

	protected:
		static const UInt32 ES_POS_COL;
		static const UInt32 ES_TANGENTSPACE;
		static const UInt32 ES_NORMAL;
		static const UInt32 ES_MASK0;
		static const UInt32 ES_MASK1;

		static const wchar_t* STR_ONLY_DEFMATERIAL;
		static const wchar_t* STR_ILLEGAL_IS;
		static const wchar_t* STR_NS_BUMP;
	};

}}}
