package speiger.src.coreengine.rendering.utils.values.textures;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL30;

import speiger.src.coreengine.rendering.utils.values.IGLValue.ITextureFormatType;

public enum GLTextureFormat implements ITextureFormatType {
	R(GL11.GL_RED, true),
	RG(GL30.GL_RG, true),
	RGB(GL11.GL_RGB, true),
	RGBA(GL11.GL_RGBA, true),
	DEPTH(GL11.GL_DEPTH_COMPONENT, true),
	DEPTH_STENCIL(GL30.GL_DEPTH_STENCIL, true),
	LUMINANCE(GL11.GL_LUMINANCE, false),
	LUMINANCE_ALPHA(GL11.GL_LUMINANCE_ALPHA, false);
	
	int glMode;
	boolean internal;
	
	private GLTextureFormat(int glMode, boolean internal) {
		this.glMode = glMode;
		this.internal = internal;
	}
	
	@Override
	public int glValue() { return glMode; }
	@Override
	public boolean internal() { return internal; }
	
	public static int toComponents(int glValue) {
		return switch(glValue) {
			case GL11.GL_LUMINANCE -> 1;
			case GL11.GL_LUMINANCE_ALPHA -> 2;
			case GL11.GL_RGB -> 3;
			case GL11.GL_RGBA -> 4;			
			default -> 0;
		};
	}
	
	public static GLTextureFormat bySTB(int components) {
		return switch(components) {
			case 1 -> LUMINANCE;
			case 2 -> LUMINANCE_ALPHA;
			case 3 -> RGB;
			case 4 -> RGBA;
			default -> throw new IllegalArgumentException("Only 1-4 Components are supported");
		};
	}
}
