package speiger.src.coreengine.platform.graphics.opengl.shader;

import java.util.Map;

import speiger.src.collections.ints.maps.impl.hash.Int2ObjectOpenHashMap;
import speiger.src.collections.ints.maps.interfaces.Int2ObjectMap;
import speiger.src.collections.objects.maps.impl.hash.Object2ObjectOpenHashMap;

public record ShaderInstance(int programId, ShaderStorage<BufferObject> uniforms, ShaderStorage<BufferObject> storages, ShaderStorage<TextureObject> samplers, ShaderStorage<TextureObject> buffers) {
	public record BufferObject(int slot) {}
	public record TextureObject(int unit) {}
	
	public static class ShaderStorage<T> {
		Map<String, T> byName = new Object2ObjectOpenHashMap<>();
		Int2ObjectMap<T> byIndex = new Int2ObjectOpenHashMap<>();
		
		public void add(String name, int index, T value) {
			byName.put(name, value);
			byIndex.put(index, value);
		}
		
		public T byName(String name) {
			return byName.get(name);
		}
		
		public T byIndex(int index) {
			return byIndex.get(index);
		}
	}
}
