#include<stdafx.h>
#include"Layer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

void TextureLayer::Import(const char *tname)
{
	LoadTexture(tname);

}

void TextureLayer::Import(Image &img)
{
	Img=img;
Loaded=true;
}

void HeightFieldLayer::Import(const char *tname)
{
	CString tstr(tname);
	tstr+=".TGA";
	Img.Load((char *)(LPCTSTR)tstr);
Loaded=true;
}

void HeightFieldLayer::Import(Image &img)
{
	Img=img;
Loaded=true;
}

void TextureLayer::LoadTexture(const char *tname)
{
	Name=tname;
	Texture = MLRTexturePool::Instance->Add(tname);
	CString tstr(tname);
	tstr+=".TGA";
	Img.Load((char *)(LPCTSTR)tstr);
	SetState();
	MLRTexturePool::Instance->LoadImages();
Loaded=true;
}

Layer &Layer::operator=(Layer &lay)
{
	
	Img=lay.Img;
	Name=lay.Name;
	Texture=lay.Texture;
	State=lay.State;
	Loaded=lay.Loaded;	
	return *this;
}

void Layer::SetState()
{
	State.SetTextureHandle(Texture->GetTextureHandle());
	State.SetRenderDeltaMask(MLRState::TextureMask);
	State.SetZBufferCompareOn();
	State.SetZBufferWriteOn();
	State.SetFilterMode(MLRState::TriLinearFilterMode);
	State.SetPriority(MLRState::DefaultPriority);

}
