#include "colorlayer.h"
#include "openglstate.h"
#include "m3derror.h"
namespace M3D {

ColorLayer::ColorLayer()
 : MaterialLayer()
{
}


ColorLayer::~ColorLayer()
{
}

void ColorLayer::set_layer(OpenGLState *state)
{
	int programID = state->get_current_program();
	GLint location = glGetUniformLocation ( programID, (_layer_name_ + "Color").c_str() );
	if(location==-1)/*THROW("Unable to find " + (_layer_name_ + "Color") + " in shader program")*/;
	else glUniform4fv ( location, 4, _color_ );
}

void ColorLayer::load( const std::string & base_dir, M3DML_BLOCK_TYPE block_type, const M3DML_Layer * layer, EngineInterface * engine )
{
	_layer_type_ = block_type;
	_color_[0] = layer->color_block->r;
	_color_[1] = layer->color_block->g;
	_color_[2] = layer->color_block->b;
	_color_[3] = layer->color_block->a;
	set_layer_type();
}

}

