#include "shaderprogramm.h"
#include <fstream>
#include <iostream>
#include <string>
#include <errno.h>
#include "m3derror.h"
#include "m3ds.h"

namespace M3D
{

ShaderProgram::ShaderProgram()
{}


ShaderProgram::~ShaderProgram()
{}

void ShaderProgram::load( const std::string & fname )
{
	M3DS shader;
	shader.load( fname );
	_vertex_shader_.load( shader.get_data()->vertex_shader);
	_fragment_shader_.load( shader.get_data()->fragment_shader);
	
	_shader_id_ = glCreateProgram();
	glAttachShader(_shader_id_, _vertex_shader_.get_shader_id());
	glAttachShader(_shader_id_, _fragment_shader_.get_shader_id());
	glLinkProgram(_shader_id_);
	GLint status;
	glGetProgramiv(_shader_id_, GL_LINK_STATUS, &status);
	if (!status) {
		char error_buf[2048];
		int size = 2048;
		glGetProgramInfoLog(_shader_id_, 2048, &size, error_buf);
		THROW(error_buf);
	}
	std::cerr<<"Program linked"<<std::endl;
}

}
