package com.github.hydos.ginger.engine.vulkan.shaders;

import static org.lwjgl.system.MemoryStack.stackPush;
import static org.lwjgl.vulkan.VK10.*;

import java.nio.*;

import org.lwjgl.system.MemoryStack;
import org.lwjgl.vulkan.VkShaderModuleCreateInfo;

import com.github.hydos.ginger.VulkanExample;

/** will be used in the future to manage multiple shaders
 * 
 * @author hydos */
public class VKShaderManager
{
	public static long createShaderModule(ByteBuffer spirvCode)
	{
		try (MemoryStack stack = stackPush())
		{
			VkShaderModuleCreateInfo createInfo = VkShaderModuleCreateInfo.callocStack(stack);
			createInfo.sType(VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO);
			createInfo.pCode(spirvCode);
			LongBuffer pShaderModule = stack.mallocLong(1);
			if (vkCreateShaderModule(VulkanExample.VulkanDemoGinger2.device, createInfo, null, pShaderModule) != VK_SUCCESS)
			{ throw new RuntimeException("Failed to create shader module"); }
			return pShaderModule.get(0);
		}
	}
}
