//	Darkstar Engine  (c) UnderWorld Interactive Studio (all coding by Svarog    2007)
//
//      Данный файл является частью Darkstar Engine. Любое использование кода файла
//      без согласия компании, является нарушением закона об авторском праве (в слу-
//      чае если не оговорено обратное).
//
//      Имя файла: sampler_render_state.cpp
//      Краткое описание: Sampler render state
//

#include <Darkstar/Graphic System/Render State/sampler_render_state.hpp>
#include <Darkstar/Graphic System/Render State/render_state_manager.hpp>

using gs::SamplerRenderState;
using gs::RenderStateManager;
using gs::DTEXADDRESS;
using gs::DTEXFILTER;
using gs::SAMPLER_TYPE;

SamplerRenderState::SamplerRenderState()
{
	addressu = addressv = addressw = DTEXADD_WRAP;
	filter = DTEXF_MIN_MAG_MIP_LINEAR;
	mip_lod_bias = 0;
	max_anisotropy = 16;
};

SamplerRenderState::SamplerRenderState(const SamplerRenderState& sm)
{
	addressu = sm.getAddressU();
	addressv = sm.getAddressV();
	addressw = sm.getAddressW();
	filter = sm.getFilter();
	mip_lod_bias = sm.getMipLODBias();
	max_anisotropy = sm.getMaxAnisotropy();
};

SamplerRenderState::~SamplerRenderState()
{

};

bool SamplerRenderState::operator ==(const SamplerRenderState& state) const
{
	return (addressu == state.getAddressU() && addressv == state.getAddressV() && 
		addressw == state.getAddressW() && filter == state.getFilter() && 
		mip_lod_bias == state.getMipLODBias() && max_anisotropy == state.getMaxAnisotropy());
};

void SamplerRenderState::setAddressU(const DTEXADDRESS& new_addressu)
{
	addressu = new_addressu;
};

void SamplerRenderState::setAddressV(const DTEXADDRESS& new_addresv)
{
	addressv = new_addresv;
};

void SamplerRenderState::setAddressW(const DTEXADDRESS& new_addresw)
{
	addressw = new_addresw;
};

void SamplerRenderState::setMaxAnisotropy(const unsigned int new_max_anisotropy)
{
	max_anisotropy = new_max_anisotropy;
};

void SamplerRenderState::setFilter(const DTEXFILTER& new_filter)
{
	filter = new_filter;
};

void SamplerRenderState::setMipLODBias(const float new_mip_lod_bias)
{
	mip_lod_bias = new_mip_lod_bias;
};

const DTEXADDRESS& SamplerRenderState::getAddressU() const
{
	return addressu;
};

const DTEXADDRESS& SamplerRenderState::getAddressV() const
{
	return addressv;
};

const DTEXADDRESS& SamplerRenderState::getAddressW() const
{
	return addressw;
};

const DTEXFILTER& SamplerRenderState::getFilter() const
{
	return filter;
};

unsigned int SamplerRenderState::getMaxAnisotropy() const
{
	return max_anisotropy;
};

float SamplerRenderState::getMipLODBias() const
{
	return mip_lod_bias;
};

void SamplerRenderState::set(const unsigned int sampler_index, const SAMPLER_TYPE& type)
{
	RenderStateManager::ptr()->setSamplerRenderState(*this, sampler_index, type);
};

void SamplerRenderState::setVS(const unsigned int sampler_index)
{
	RenderStateManager::ptr()->setSamplerRenderState(*this, sampler_index, VS_SAMPLER);
};

void SamplerRenderState::setPS(const unsigned int sampler_index)
{
	RenderStateManager::ptr()->setSamplerRenderState(*this, sampler_index, PS_SAMPLER);
};

void SamplerRenderState::setGS(const unsigned int sampler_index)
{
	RenderStateManager::ptr()->setSamplerRenderState(*this, sampler_index, GS_SAMPLER);
};