#include "ColorProgram.hpp"

#include "../Renderer.hpp"

using namespace pass;

ColorProgram::ColorProgram(): Program() {

    std::vector<std::string> flags;
    std::vector<Shader*> shaders;
    shaders.push_back(loadShader(GL_VERTEX_SHADER, flags));
    shaders.push_back(loadShader(GL_FRAGMENT_SHADER, flags));
    load(shaders);

    MVPMatrixID = glGetUniformLocation(ProgramID, "MVP");
    ColID = glGetUniformLocation(ProgramID, "Col");
}

ColorProgram::~ColorProgram() { }

std::string ColorProgram::getName() const {
    return "Color";
}
void ColorProgram::setup(render::gl::Renderer *renderer, glm::mat4 modelMatrix, glm::vec4 color) {
    const auto mvp = renderer->getProjectionMatrix() * renderer->getViewMatrix() * modelMatrix;
    setMVP(&mvp[0][0]);
    setCol(&color[0]);
}

void ColorProgram::setMVP(const GLfloat *matrix) {
    glUniformMatrix4fv(MVPMatrixID, 1, GL_FALSE, matrix);
}
void ColorProgram::setCol(const GLfloat *color) {
    glUniform4fv(ColID, 1, color);
}
