package com.simibubi.create.content.contraptions.render;

import org.lwjgl.opengl.GL20;

import com.jozufozu.flywheel.core.shader.WorldProgram;
import com.mojang.math.Matrix4f;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.phys.AABB;

public class ContraptionProgram extends WorldProgram {
	protected final int uLightBoxSize;
	protected final int uLightBoxMin;
	protected final int uModel;

	protected int uLightVolume;

	public ContraptionProgram(ResourceLocation name, int handle) {
		super(name, handle);
		uLightBoxSize = getUniformLocation("uLightBoxSize");
		uLightBoxMin = getUniformLocation("uLightBoxMin");
		uModel = getUniformLocation("uModel");
	}

	@Override
	protected void registerSamplers() {
		super.registerSamplers();
		uLightVolume = setSamplerBinding("uLightVolume", 4);
	}

    public void bind(Matrix4f model, AABB lightVolume) {
        double sizeX = lightVolume.maxX - lightVolume.minX;
        double sizeY = lightVolume.maxY - lightVolume.minY;
        double sizeZ = lightVolume.maxZ - lightVolume.minZ;
        GL20.glUniform3f(uLightBoxSize, (float) sizeX, (float) sizeY, (float) sizeZ);
        GL20.glUniform3f(uLightBoxMin, (float) lightVolume.minX, (float) lightVolume.minY, (float) lightVolume.minZ);
        uploadMatrixUniform(uModel, model);
    }
}
