package speiger.src.coreengine.rendering.utils.states;

import speiger.src.coreengine.rendering.utils.GLFunctions;

public class PixelState implements IGLState {
	final int id;
	final int defaultValue;
	int value;
	
	public PixelState(int id, int defaultValue) {
		this.id = id;
		this.defaultValue = defaultValue;
		this.value = defaultValue;
	}
	
	public PixelState set(int value) {
		if(this.value != value) {
			this.value = value;
			setValue(value);
		}
		return this;
	}
	
	protected void setValue(int value) {
		GLFunctions.pixelStoreI(id, value);
	}
	
	public int get() {
		return value;
	}
	
	@Override
	public void setDefault() {
		set(defaultValue);
	}
	
	@Override
	public void reapply() {
		setValue(value);
	}
}
