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

#include <Darkstar/Graphic System/Render State/colorwrite_render_state.hpp>
#include <Darkstar/Graphic System/Render State/render_state_manager.hpp>
#include <Darkstar/Kernel/logh.hpp>

using gs::ColorWriteRenderState;
using gs::RenderStateManager;
using ker::Log;
using gs::DCWM_ALL;

ColorWriteRenderState::ColorWriteRenderState()
{
	for(unsigned int i = 0; i < render_target_num; ++i)
		flags[i] = DCWM_ALL;
};

ColorWriteRenderState::ColorWriteRenderState(const ColorWriteRenderState& cw)
{
	for(unsigned int i = 0; i < render_target_num; ++i)
		flags[i] = cw.getColorWriteFlag(i);
};

ColorWriteRenderState::ColorWriteRenderState(const unsigned int render_target_index, const unsigned char flag)
{
	setColorWriteFlag(render_target_index, flag);
};

ColorWriteRenderState::~ColorWriteRenderState()
{

};

bool ColorWriteRenderState::operator ==(const ColorWriteRenderState& state) const
{
	for(unsigned int i = 0; i < render_target_num; ++i)
		if(flags[i] != state.getColorWriteFlag(i))
			return false;
	return true;
};

void ColorWriteRenderState::setColorWriteFlag(const unsigned int render_target_index, const unsigned char flag)
{
#ifdef _NOTFINAL
	if(render_target_index >= render_target_num)
	{
		lwar << "Try to set color write flag with render target index greater or equal than render_target_num";
		return;
	};
#endif
	flags[render_target_index] = flag;
};

unsigned char ColorWriteRenderState::getColorWriteFlag(const unsigned int render_target_index) const
{
#ifdef _NOTFINAL
	if(render_target_index >= render_target_num)
	{
		lwar << "Try to get color write flag with render target index greater or equal than render_target_num";
		return 0;
	};
#endif
	return flags[render_target_index];
};

void ColorWriteRenderState::set()
{
	RenderStateManager::ptr()->setColorWriteRenderState(*this);
};