//------------------------------------------------------------------------------
// Lamp : Open source game middleware
// Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//------------------------------------------------------------------------------

/** @file
 * メッシュマネージャ実装
 * @author Junpee
 */

#include "LampBasic.h"
#include "Graphics/Mesh/MeshManager.h"

namespace Lamp{

//------------------------------------------------------------------------------
// コンストラクタ
MeshManager::MeshManager(Scene* scene) :
	SceneObjectManagerTemplate<Mesh>(scene){
}
//------------------------------------------------------------------------------
// 剛体メッシュの作成
RigidMesh* MeshManager::createRigidMesh(const String& meshName){
	if(!checkName(meshName)){ return NULL; }
	RigidMesh* mesh = new RigidMesh(meshName, getScene());
	addDatabase(meshName, mesh);
	return mesh;
}
//------------------------------------------------------------------------------
// キャラクタメッシュの作成
CharacterMesh* MeshManager::createCharacterMesh(const String& meshName){
	if(!checkName(meshName)){ return NULL; }
	CharacterMesh* mesh = new CharacterMesh(meshName, getScene());
	addDatabase(meshName, mesh);
	return mesh;
}
//------------------------------------------------------------------------------
// デバイスオブジェクトの初期化
bool MeshManager::initializeGraphicsDeviceObjects(){
	int meshCount = getCount();
	for(int i = 0; i < meshCount; i++){
		if(!get(i)->initializeGraphicsDeviceObjects()){ return false; }
	}
	return true;
}
//------------------------------------------------------------------------------
// デバイスオブジェクトの削除
void MeshManager::deleteGraphicsDeviceObjects(){
	int meshCount = getCount();
	for(int i = 0; i < meshCount; i++){
		get(i)->deleteGraphicsDeviceObjects();
	}
}
//------------------------------------------------------------------------------
// デバイスオブジェクトのリストア
bool MeshManager::restoreGraphicsDeviceObjects(){
	int meshCount = getCount();
	for(int i = 0; i < meshCount; i++){
		if(!get(i)->restoreGraphicsDeviceObjects()){ return false; }
	}
	return true;
}
//------------------------------------------------------------------------------
// デバイスオブジェクトの無効化
void MeshManager::invalidateGraphicsDeviceObjects(){
	int meshCount = getCount();
	for(int i = 0; i < meshCount; i++){
		get(i)->invalidateGraphicsDeviceObjects();
	}
}
//------------------------------------------------------------------------------
} // End of namespace Lamp
//------------------------------------------------------------------------------
