#include "Scene.h"

void Scene::addMaterial(PosMaterial* material)
{
	materials.push_back(dynamic_cast<Material*>(material));
}

void Scene::addGeometry(PosGeometry* geometry)
{
	geometries.push_back(dynamic_cast<Geometry*>(geometry));
}

void Scene::addSceneEntity(PosSceneEntity* sceneEntity)
{
	entities.push_back(dynamic_cast<SceneEntity*>(sceneEntity));
}

void Scene::addModel(PosModel* model)
{
	models.push_back(dynamic_cast<Model*>(model));
}

PosModel* Scene::getNewModel()
{
	return new Model();
}

PosMaterial* Scene::getNewMaterial()
{
	return new Material();
}

PosGeometry* Scene::getNewGeometry()
{
	return new Geometry();
}

PosSceneEntity* Scene::getNewSceneEntity()
{
	return new SceneEntity();
}

void Scene::render(Effect* effect, ID3D10EffectPass* pass)
{
	for (vector<SceneEntity*>::iterator it = entities.begin(); it!=entities.end(); ++it)
	{
			(*it)->render(effect,pass);
	}
}

void Scene::createVBOs(ID3D10Effect* effect)
{
	for (vector<SceneEntity*>::iterator it = entities.begin(); it!=entities.end(); ++it)
			(*it)->createVBOs(effect);
}

void Scene::loadTextures()
{
	for(unsigned int i=0;i<materials.size();i++)
		materials[i]->loadTextures();
}

Scene::~Scene()
{
	for(unsigned int i=0;i<materials.size();i++)
		delete materials[i];
	
	materials.clear();

	for(unsigned int i=0;i<geometries.size();i++)
		delete geometries[i];

	geometries.clear();

	for(unsigned int i=0;i<entities.size();i++)
		delete entities[i];

	entities.clear();

	for(unsigned int i=0;i<models.size();i++)
		delete models[i];

	models.clear();
}