org.lwjgl.vulkan.VkApplicationInfo Java Examples

The following examples show how to use org.lwjgl.vulkan.VkApplicationInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleDemo.java    From lwjgl3-awt with MIT License 5 votes vote down vote up
/**
 * Create a Vulkan instance using LWJGL 3.
 * 
 * @return the VkInstance handle
 */
private static VkInstance createInstance() {
    VkApplicationInfo appInfo = VkApplicationInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
            .pApplicationName(memUTF8("AWT Vulkan Demo"))
            .pEngineName(memUTF8(""))
            .apiVersion(VK_MAKE_VERSION(1, 0, 2));
    ByteBuffer VK_KHR_SURFACE_EXTENSION = memUTF8(VK_KHR_SURFACE_EXTENSION_NAME);
    ByteBuffer VK_KHR_OS_SURFACE_EXTENSION;
    if (Platform.get() == Platform.WINDOWS)
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
    else
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
    PointerBuffer ppEnabledExtensionNames = memAllocPointer(2);
    ppEnabledExtensionNames.put(VK_KHR_SURFACE_EXTENSION);
    ppEnabledExtensionNames.put(VK_KHR_OS_SURFACE_EXTENSION);
    ppEnabledExtensionNames.flip();
    VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
            .pNext(0L)
            .pApplicationInfo(appInfo);
    if (ppEnabledExtensionNames.remaining() > 0) {
        pCreateInfo.ppEnabledExtensionNames(ppEnabledExtensionNames);
    }
    PointerBuffer pInstance = MemoryUtil.memAllocPointer(1);
    int err = vkCreateInstance(pCreateInfo, null, pInstance);
    if (err != VK_SUCCESS) {
        throw new RuntimeException("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    long instance = pInstance.get(0);
    memFree(pInstance);
    VkInstance ret = new VkInstance(instance, pCreateInfo);
    memFree(ppEnabledExtensionNames);
    memFree(VK_KHR_OS_SURFACE_EXTENSION);
    memFree(VK_KHR_SURFACE_EXTENSION);
    appInfo.free();
    return ret;
}
 
Example #2
Source File: SimpleDemo.java    From lwjgl3-swt with MIT License 5 votes vote down vote up
/**
 * Create a Vulkan instance using LWJGL 3.
 * 
 * @return the VkInstance handle
 */
private static VkInstance createInstance() {
    VkApplicationInfo appInfo = VkApplicationInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
            .pApplicationName(memUTF8("SWT Vulkan Demo"))
            .pEngineName(memUTF8(""))
            .apiVersion(VK_MAKE_VERSION(1, 0, 2));
    ByteBuffer VK_KHR_SURFACE_EXTENSION = memUTF8(VK_KHR_SURFACE_EXTENSION_NAME);
    ByteBuffer VK_KHR_OS_SURFACE_EXTENSION;
    if (Platform.get() == Platform.WINDOWS)
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
    else
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
    PointerBuffer ppEnabledExtensionNames = memAllocPointer(2);
    ppEnabledExtensionNames.put(VK_KHR_SURFACE_EXTENSION);
    ppEnabledExtensionNames.put(VK_KHR_OS_SURFACE_EXTENSION);
    ppEnabledExtensionNames.flip();
    VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
            .pNext(0L)
            .pApplicationInfo(appInfo);
    if (ppEnabledExtensionNames.remaining() > 0) {
        pCreateInfo.ppEnabledExtensionNames(ppEnabledExtensionNames);
    }
    PointerBuffer pInstance = MemoryUtil.memAllocPointer(1);
    int err = vkCreateInstance(pCreateInfo, null, pInstance);
    if (err != VK_SUCCESS) {
        throw new RuntimeException("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    long instance = pInstance.get(0);
    memFree(pInstance);
    VkInstance ret = new VkInstance(instance, pCreateInfo);
    memFree(ppEnabledExtensionNames);
    memFree(VK_KHR_OS_SURFACE_EXTENSION);
    memFree(VK_KHR_SURFACE_EXTENSION);
    appInfo.free();
    return ret;
}
 
Example #3
Source File: ClearScreenDemo.java    From lwjgl3-swt with MIT License 4 votes vote down vote up
/**
 * 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() {
    VkApplicationInfo appInfo = VkApplicationInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
            .pApplicationName(memUTF8("SWT Vulkan Demo"))
            .pEngineName(memUTF8(""))
            .apiVersion(VK_MAKE_VERSION(1, 0, 2));
    ByteBuffer VK_KHR_SURFACE_EXTENSION = memUTF8(VK_KHR_SURFACE_EXTENSION_NAME);
    ByteBuffer VK_EXT_DEBUG_REPORT_EXTENSION = memUTF8(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
    ByteBuffer VK_KHR_OS_SURFACE_EXTENSION;
    if (Platform.get() == Platform.WINDOWS)
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
    else
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
    PointerBuffer ppEnabledExtensionNames = memAllocPointer(3)
      .put(VK_KHR_SURFACE_EXTENSION)
      .put(VK_KHR_OS_SURFACE_EXTENSION)
      .put(VK_EXT_DEBUG_REPORT_EXTENSION)
      .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(ppEnabledExtensionNames);
    memFree(VK_KHR_OS_SURFACE_EXTENSION);
    memFree(VK_EXT_DEBUG_REPORT_EXTENSION);
    memFree(VK_KHR_SURFACE_EXTENSION);
    appInfo.free();
    return ret;
}
 
Example #4
Source File: VulkanInstance.java    From oreon-engine with GNU General Public License v3.0 4 votes vote down vote up
public VulkanInstance(PointerBuffer ppEnabledLayerNames) {

PointerBuffer requiredExtensions = glfwGetRequiredInstanceExtensions();
      if (requiredExtensions == null) {
          throw new AssertionError("Failed to find list of required Vulkan extensions");
      }

      ByteBuffer VK_EXT_DEBUG_REPORT_EXTENSION = memUTF8(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
      
      // +1 due to VK_EXT_DEBUG_REPORT_EXTENSION
      PointerBuffer ppEnabledExtensionNames = memAllocPointer(requiredExtensions.remaining() + 1);
      ppEnabledExtensionNames.put(requiredExtensions);
      ppEnabledExtensionNames.put(VK_EXT_DEBUG_REPORT_EXTENSION);
      ppEnabledExtensionNames.flip();
      
      VkApplicationInfo appInfo = VkApplicationInfo.calloc()
              .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
              .pApplicationName(memUTF8("Vulkan Demo"))
              .pEngineName(memUTF8("OREON ENGINE"))
              .apiVersion(VK_MAKE_VERSION(1, 1, 77));
      
      VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc()
              .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
              .pNext(0)
              .pApplicationInfo(appInfo)
              .ppEnabledExtensionNames(ppEnabledExtensionNames)
              .ppEnabledLayerNames(ppEnabledLayerNames);
      PointerBuffer pInstance = memAllocPointer(1);
      int err = vkCreateInstance(pCreateInfo, null, pInstance);
  
      if (err != VK_SUCCESS) {
          throw new AssertionError("Failed to create VkInstance: " + VkUtil.translateVulkanResult(err));
      }
      
      handle = new VkInstance(pInstance.get(0), pCreateInfo);
      
      pCreateInfo.free();
      memFree(pInstance);
      memFree(VK_EXT_DEBUG_REPORT_EXTENSION);
      memFree(ppEnabledExtensionNames);
      memFree(appInfo.pApplicationName());
      memFree(appInfo.pEngineName());
      appInfo.free();
      
      VkDebugReportCallbackEXT debugCallback = new VkDebugReportCallbackEXT() {
          public int invoke(int flags, int objectType, long object, long location, int messageCode, long pLayerPrefix, long pMessage, long pUserData) {
              System.err.println("ERROR OCCURED: " + VkDebugReportCallbackEXT.getString(pMessage));
              return 0;
          }
      };
      
      debugCallbackHandle = setupDebugging(handle, VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT, debugCallback);
  }