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

import org.lwjgl.opengl.GL45;

import speiger.src.collections.objects.maps.impl.hash.Object2IntOpenHashMap;
import speiger.src.collections.objects.maps.interfaces.Object2IntMap;
import speiger.src.coreengine.assets.api.ID;

public class FrameBufferCache {
	Object2IntMap<ID> fboCache = new Object2IntOpenHashMap<>();
	
	public int getOrCreateFBO(ID id) {
		return fboCache.supplyIntIfAbsent(id, GL45::glCreateFramebuffers);
	}
	
	public void deleteFBO(ID id) {
		int fbo = fboCache.rem(id);
		if(fbo == -1) return;
		GL45.glDeleteFramebuffers(fbo);
	}
	
	public void clear() {
		GL45.glDeleteFramebuffers(fboCache.values().toIntArray());
		fboCache.clear();
	}
}
