package de.frajul.endlessroll.rendering.shader;

import android.content.Context;
import android.opengl.GLES20;

import de.frajul.endlessroll.data.Color;
import de.frajul.endlessroll.entities.Entity;
import de.frajul.endlessroll.main.game.Camera;
import de.frajul.endlessroll.rendering.MatrixCreator;

/**
 * Created by Julian on 10.08.2016.
 */
public class ParticleShader extends ShaderProgram {

    private int location_mvpMatrix;
    private int location_transformationMatrix;
    private int location_color;
    private int location_alpha;

    public ParticleShader(Context context) throws Exception {
        super(context, "shader/entityVertexShader.glsl", "shader/particleFragmentShader.glsl");
    }

    @Override
    protected void loadUniformLocations() {
        location_mvpMatrix = super.getUniformLocation("mvpMatrix");
        location_transformationMatrix = super.getUniformLocation("transformationMatrix");
        location_color = super.getUniformLocation("color");
        location_alpha = super.getUniformLocation("alpha");
    }

    public void loadMVPMatrix(MatrixCreator matrixCreator, Camera camera) {
        float[] mvpMatrix = matrixCreator.createModelViewProjectionMatrix(camera);
        GLES20.glUniformMatrix4fv(location_mvpMatrix, 1, false, mvpMatrix, 0);
    }

    public void loadTransformationMatrix(MatrixCreator matrixCreator, Entity entity) {
        float[] transformationMatrix = matrixCreator.createTransformationMatrix(entity);
        GLES20.glUniformMatrix4fv(location_transformationMatrix, 1, false, transformationMatrix, 0);
    }

    public void loadAlpha(float alpha){
        GLES20.glUniform1f(location_alpha, alpha);
    }

    public void loadColor(Color color) {
        GLES20.glUniform3f(location_color, color.getR(), color.getG(), color.getB());
    }

}
