package de.frajul.endlessroll.rendering.shader;

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

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 TerrainShader extends ShaderProgram {

    private int location_mvpMatrix;
    private int location_transformationMatrix;
    private int location_gridColumnCount;
    private int location_isEndlessTileList;

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

    @Override
    protected void loadUniformLocations() {
        location_mvpMatrix = super.getUniformLocation("mvpMatrix");
        location_transformationMatrix = super.getUniformLocation("transformationMatrix");
        location_gridColumnCount = super.getUniformLocation("gridColumnCount");
        location_isEndlessTileList = super.getUniformLocation("isEndlessTileList");
    }

    public void loadGridColumnCount(int gridColumnCount) {
        GLES20.glUniform1f(location_gridColumnCount, gridColumnCount);
    }

    public void loadIsEndlessTileList(boolean endless) {
        GLES20.glUniform1f(location_isEndlessTileList, endless ? 1f : 0f);
    }

    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);
    }

}
