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

import java.nio.ByteBuffer;

import org.lwjgl.system.MemoryUtil;

import speiger.src.coreengine.assets.AssetLocation;
import speiger.src.coreengine.assets.base.IAssetProvider;
import speiger.src.coreengine.rendering.textures.simple.DirectTexture;
import speiger.src.coreengine.rendering.textures.simple.SimpleTexture;
import speiger.src.coreengine.rendering.textures.simple.WrappedTexture;

public interface ITexture {
	public int id();
	public default void bind() { bind(0); }
	public void bind(int unit);
	public void load(IAssetProvider provider);
	public default void reset() { delete(false); }
	public default void delete() { delete(true); }
	public void delete(boolean untrack);
	
	public int width();
	public int height();
	
	public default float minU() { return 0F; }
	public default float minV() { return 0F; }
	public default float maxU() { return 1F; }
	public default float maxV() { return 1F; }
	
	public static ITexture direct(int width, int height, ByteBuffer buffer, TextureMetadata metadata) {
		return direct(width, height, MemoryUtil.memAddress(buffer), metadata);
	}
	
	public static ITexture direct(int width, int height, long data, TextureMetadata metadata) {
		return new DirectTexture(width, height, data, metadata);
	}
	
	public static ITexture simple(AssetLocation location, TextureMetadata metadata) {
		return new SimpleTexture(location, metadata);
	}
	
	public static ITexture wrap(ITexture texture) {
		return texture instanceof WrappedTexture ? texture : wrap(texture.id());
	}
	
	public static ITexture wrap(int id) {
		return new WrappedTexture(id);
	}
}
