package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.PostProcessing;

import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
import org.lwjgl.system.MemoryUtil;
import org.lwjgl.vulkan.VkSpecializationInfo;
import org.lwjgl.vulkan.VkSpecializationMapEntry;

import java.nio.ByteBuffer;

public class SpecializationConstants {

    private final ByteBuffer data;
    private final VkSpecializationMapEntry.Buffer SpecializationEntryMap;
    private final VkSpecializationInfo SpecializationInfo;

    public SpecializationConstants(){
        var EngineCfg = EngineConfig.getInstance();
        data = MemoryUtil.memAlloc(VulkanUtils.INT_SIZE);
        data.putInt(EngineCfg.RenderAA());
        data.flip();

        SpecializationEntryMap = VkSpecializationMapEntry.calloc(1);
        SpecializationEntryMap.get(0)
                .constantID(0)
                .size(VulkanUtils.INT_SIZE)
                .offset(0);

        SpecializationInfo = VkSpecializationInfo.calloc();
        SpecializationInfo.pData(data).pMapEntries(SpecializationEntryMap);
    }

    public void CleanUp(){
        MemoryUtil.memFree(SpecializationEntryMap);
        SpecializationInfo.free();
        MemoryUtil.memFree(data);
    }
    public VkSpecializationInfo GetSpecializationInfo(){return SpecializationInfo;}
}
