Search in sources :

Example 6 with VkApplicationInfo

use of org.lwjgl.vulkan.VkApplicationInfo in project lwjgl3-demos by LWJGL.

the class InstancedSpheresDemo method createInstance.

/**
 * Create a Vulkan instance using LWJGL 3.
 *
 * @return the VkInstance handle
 */
private static VkInstance createInstance(PointerBuffer requiredExtensions) {
    VkApplicationInfo appInfo = VkApplicationInfo.calloc().sType(VK_STRUCTURE_TYPE_APPLICATION_INFO).pApplicationName(memUTF8("GLFW Vulkan Demo")).pEngineName(memUTF8("")).apiVersion(VK_MAKE_VERSION(1, 0, 2));
    PointerBuffer ppEnabledExtensionNames = memAllocPointer(requiredExtensions.remaining() + 1);
    ppEnabledExtensionNames.put(requiredExtensions);
    ByteBuffer VK_EXT_DEBUG_REPORT_EXTENSION = memUTF8(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
    ppEnabledExtensionNames.put(VK_EXT_DEBUG_REPORT_EXTENSION);
    ppEnabledExtensionNames.flip();
    PointerBuffer ppEnabledLayerNames = memAllocPointer(layers.length);
    for (int i = 0; validation && i < layers.length; i++) ppEnabledLayerNames.put(layers[i]);
    ppEnabledLayerNames.flip();
    VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc().sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO).pNext(NULL).pApplicationInfo(appInfo).ppEnabledExtensionNames(ppEnabledExtensionNames).ppEnabledLayerNames(ppEnabledLayerNames);
    PointerBuffer pInstance = memAllocPointer(1);
    int err = vkCreateInstance(pCreateInfo, null, pInstance);
    long instance = pInstance.get(0);
    memFree(pInstance);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    VkInstance ret = new VkInstance(instance, pCreateInfo);
    pCreateInfo.free();
    memFree(ppEnabledLayerNames);
    memFree(VK_EXT_DEBUG_REPORT_EXTENSION);
    memFree(ppEnabledExtensionNames);
    memFree(appInfo.pApplicationName());
    memFree(appInfo.pEngineName());
    appInfo.free();
    return ret;
}
Also used : VkApplicationInfo(org.lwjgl.vulkan.VkApplicationInfo) PointerBuffer(org.lwjgl.PointerBuffer) ByteBuffer(java.nio.ByteBuffer) VkInstance(org.lwjgl.vulkan.VkInstance) VkInstanceCreateInfo(org.lwjgl.vulkan.VkInstanceCreateInfo)

Example 7 with VkApplicationInfo

use of org.lwjgl.vulkan.VkApplicationInfo in project lwjgl3-demos by LWJGL.

the class ColoredTriangleDemo method createInstance.

/**
 * Create a Vulkan instance using LWJGL 3.
 *
 * @return the VkInstance handle
 */
private static VkInstance createInstance(PointerBuffer requiredExtensions) {
    VkApplicationInfo appInfo = VkApplicationInfo.calloc().sType(VK_STRUCTURE_TYPE_APPLICATION_INFO).pApplicationName(memUTF8("GLFW Vulkan Demo")).pEngineName(memUTF8("")).apiVersion(VK_MAKE_VERSION(1, 0, 2));
    PointerBuffer ppEnabledExtensionNames = memAllocPointer(requiredExtensions.remaining() + 1);
    ppEnabledExtensionNames.put(requiredExtensions);
    ByteBuffer VK_EXT_DEBUG_REPORT_EXTENSION = memUTF8(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
    ppEnabledExtensionNames.put(VK_EXT_DEBUG_REPORT_EXTENSION);
    ppEnabledExtensionNames.flip();
    PointerBuffer ppEnabledLayerNames = memAllocPointer(layers.length);
    for (int i = 0; validation && i < layers.length; i++) ppEnabledLayerNames.put(layers[i]);
    ppEnabledLayerNames.flip();
    VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc().sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO).pNext(NULL).pApplicationInfo(appInfo).ppEnabledExtensionNames(ppEnabledExtensionNames).ppEnabledLayerNames(ppEnabledLayerNames);
    PointerBuffer pInstance = memAllocPointer(1);
    int err = vkCreateInstance(pCreateInfo, null, pInstance);
    long instance = pInstance.get(0);
    memFree(pInstance);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    VkInstance ret = new VkInstance(instance, pCreateInfo);
    pCreateInfo.free();
    memFree(ppEnabledLayerNames);
    memFree(VK_EXT_DEBUG_REPORT_EXTENSION);
    memFree(ppEnabledExtensionNames);
    memFree(appInfo.pApplicationName());
    memFree(appInfo.pEngineName());
    appInfo.free();
    return ret;
}
Also used : VkApplicationInfo(org.lwjgl.vulkan.VkApplicationInfo) PointerBuffer(org.lwjgl.PointerBuffer) ByteBuffer(java.nio.ByteBuffer) VkInstance(org.lwjgl.vulkan.VkInstance) VkInstanceCreateInfo(org.lwjgl.vulkan.VkInstanceCreateInfo)

Aggregations

ByteBuffer (java.nio.ByteBuffer)7 PointerBuffer (org.lwjgl.PointerBuffer)7 VkApplicationInfo (org.lwjgl.vulkan.VkApplicationInfo)7 VkInstance (org.lwjgl.vulkan.VkInstance)7 VkInstanceCreateInfo (org.lwjgl.vulkan.VkInstanceCreateInfo)7