Search in sources :

Example 1 with VkInstanceCreateInfo

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

the class ClearScreenDemo method createInstance.

/**
 * Create a Vulkan {@link VkInstance} using LWJGL 3.
 * <p>
 * The {@link VkInstance} represents a handle to the Vulkan API and we need that instance for about everything we do.
 *
 * @return the VkInstance handle
 */
private static VkInstance createInstance(PointerBuffer requiredExtensions) {
    // Here we say what the name of our application is and which Vulkan version we are targetting (having this is optional)
    VkApplicationInfo appInfo = VkApplicationInfo.calloc().sType(VK_STRUCTURE_TYPE_APPLICATION_INFO).pApplicationName(memUTF8("GLFW Vulkan Demo")).pEngineName(memUTF8("")).apiVersion(VK_MAKE_VERSION(1, 0, 2));
    // We also need to tell Vulkan which extensions we would like to use.
    // Those include the platform-dependent required extensions we are being told by GLFW to use.
    // This includes stuff like the Window System Interface extensions to actually render something on a window.
    // 
    // We also add the debug extension so that validation layers and other things can send log messages to us.
    ByteBuffer VK_EXT_DEBUG_REPORT_EXTENSION = memUTF8(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
    PointerBuffer ppEnabledExtensionNames = memAllocPointer(requiredExtensions.remaining() + 1);
    // <- platform-dependent required extensions
    ppEnabledExtensionNames.put(requiredExtensions).put(// <- the debug extensions
    VK_EXT_DEBUG_REPORT_EXTENSION).flip();
    // Now comes the validation layers. These layers sit between our application (the Vulkan client) and the
    // Vulkan driver. Those layers will check whether we make any mistakes in using the Vulkan API and yell
    // at us via the debug extension.
    PointerBuffer ppEnabledLayerNames = memAllocPointer(layers.length);
    for (int i = 0; validation && i < layers.length; i++) ppEnabledLayerNames.put(layers[i]);
    ppEnabledLayerNames.flip();
    // Vulkan uses many struct/record types when creating something. This ensures that every information is available
    // at the callsite of the creation and allows for easier validation and also for immutability of the created object.
    // 
    // The following struct defines everything that is needed to create a VkInstance
    VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc().sType(// <- identifies what kind of struct this is (this is useful for extending the struct type later)
    VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO).pNext(// <- must always be NULL until any next Vulkan version tells otherwise
    NULL).pApplicationInfo(// <- the application info we created above
    appInfo).ppEnabledExtensionNames(// <- and the extension names themselves
    ppEnabledExtensionNames).ppEnabledLayerNames(// <- and the layer names themselves
    ppEnabledLayerNames);
    // <- create a PointerBuffer which will hold the handle to the created VkInstance
    PointerBuffer pInstance = memAllocPointer(1);
    // <- actually create the VkInstance now!
    int err = vkCreateInstance(pCreateInfo, null, pInstance);
    // <- get the VkInstance handle
    long instance = pInstance.get(0);
    // <- free the PointerBuffer
    memFree(pInstance);
    // Check whether we succeeded in creating the VkInstance
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    // Create an object-oriented wrapper around the simple VkInstance long handle
    // This is needed by LWJGL to later "dispatch" (i.e. direct calls to) the right Vukan functions.
    VkInstance ret = new VkInstance(instance, pCreateInfo);
    // Now we can free/deallocate everything
    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 2 with VkInstanceCreateInfo

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

the class ColoredRotatingQuadDemo 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 3 with VkInstanceCreateInfo

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

the class TriangleDemo 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 4 with VkInstanceCreateInfo

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

the class TwoRotatingTrianglesDemo 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 5 with VkInstanceCreateInfo

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

the class TwoRotatingTrianglesInvDepthDemo 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