package speiger.src.coreengine.rendering.shaderOld.uniforms;

import org.lwjgl.opengl.GL30;
import org.lwjgl.opengl.GL31;

import speiger.src.coreengine.rendering.models.buffers.UniformBuffer;
import speiger.src.coreengine.rendering.shaderOld.ShaderProgram;
import speiger.src.coreengine.utils.io.GameLog;

public class UniformBufferBlock extends Uniform {
	ShaderProgram prog;
	int slot;

	public UniformBufferBlock(String id, int slot) {
		super(id);
		this.slot = slot;
	}

	@Override
	public void loadUniform(ShaderProgram prog) {
		this.prog = prog;
		position = GL31.glGetUniformBlockIndex(prog.getShaderID(), name);
		if (position == -1) {
			GameLog.error("Couldn't find Shader Uniform Block: " + name + ", Shader ID: " + prog.getShaderID());
		}
	}

	public void bindBuffer(UniformBuffer buffer) {
		GL30.glBindBufferBase(GL31.GL_UNIFORM_BUFFER, slot, buffer.id());
		GL31.glUniformBlockBinding(prog.getShaderID(), position, slot);
	}
}
