package speiger.src.coreengine.rendering.textures.base;

import org.lwjgl.opengl.GL11;

import speiger.src.coreengine.rendering.utils.GLStateTracker;
import speiger.src.coreengine.rendering.utils.values.textures.GLTextureFormat;

public abstract class BaseTexture implements ITexture {
	protected int id;
	
	protected BaseTexture() {
		this(GL11.glGenTextures());
	}
	
	protected BaseTexture(int id) {
		this.id = id;
		track();
	}
	
	protected int textureType() {
		return -1;
	}
	
	protected void track() {
		GLStateTracker.TEXTURE_TRACKER.registerTexture(this);
	}
	
	@Override
	public int id() {
		return id;
	}
	
	@Override
	public void bind(int unit) {
		GLStateTracker.TEXTURES.bind(unit, id);
	}
	
	@Override
	public void delete() {
		GL11.glDeleteTextures(id);
		GLStateTracker.TEXTURE_TRACKER.deleteTexture(this);
	}
}
