package org.lwjgl.vulkan.awt;

import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.vulkan.EXTMetalSurface.VK_EXT_METAL_SURFACE_EXTENSION_NAME;
import static org.lwjgl.vulkan.KHRSurface.*;
import static org.lwjgl.vulkan.KHRWin32Surface.*;
import static org.lwjgl.vulkan.KHRXlibSurface.*;
import static org.lwjgl.vulkan.VK10.*;
import static org.lwjgl.vulkan.awt.VKUtil.*;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.nio.ByteBuffer;

import javax.swing.JFrame;

import org.lwjgl.PointerBuffer;
import org.lwjgl.system.MemoryUtil;
import org.lwjgl.system.Platform;
import org.lwjgl.vulkan.VkApplicationInfo;
import org.lwjgl.vulkan.VkInstance;
import org.lwjgl.vulkan.VkInstanceCreateInfo;

/**
 * Shows how to create a simple Vulkan instance and a {@link AWTVKCanvas}.
 * 
 * @author Kai Burjack
 */
public class SimpleDemo {

	/**
     * 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 if (Platform.get() == Platform.LINUX)
            VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
        else
            VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_EXT_METAL_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;
    }

    public static void main(String[] args) {
        // Create the Vulkan instance
        VkInstance instance = createInstance();
        VKData data = new VKData();
        data.instance = instance; // <- set Vulkan instance
        JFrame frame = new JFrame("AWT test");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setLayout(new BorderLayout());
        frame.setPreferredSize(new Dimension(600, 600));
        frame.add(new AWTVKCanvas(data) {
            private static final long serialVersionUID = 1L;
            public void initVK() {
                @SuppressWarnings("unused")
                long surface = this.surface;

                // Do something with surface...
            }
            public void paintVK() {
            }
        }, BorderLayout.CENTER);
        frame.pack();
        frame.setVisible(true);
    }

}

@@ -1296,24 +1296,25 @@
 0, 2));%0A
+%0A
         
 ByteBuff
@@ -1309,112 +1309,330 @@
     
-ByteBuffer VK_KHR_SURFACE_EXTENSION = memUTF8(VK_KHR_SURFACE_EXTENSION_NAME);%0A        ByteBuffer
+// Enhanced switch statement would work better :(%0A        String surfaceExtension;%0A        switch (Platform.get()) %7B%0A            case WINDOWS: %7B%0A                surfaceExtension = VK_KHR_WIN32_SURFACE_EXTENSION_NAME;%0A                break;%0A            %7D%0A            case LINUX: %7B%0A                surfaceExtension =
  VK_KHR_
 OS_S
@@ -1619,34 +1619,36 @@
 ension = VK_KHR_
-OS
+XLIB
 _SURFACE_EXTENSI
@@ -1649,16 +1649,21 @@
 XTENSION
+_NAME
 ;%0A      
@@ -1668,206 +1668,322 @@
     
-if (Platform.get() == Platform.WINDOWS)%0A            VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);%0A        else if (Platform.get() == Platform.LINUX)%0A           
+        break;%0A            %7D%0A            case MACOSX: %7B%0A                surfaceExtension = VK_EXT_METAL_SURFACE_EXTENSION_NAME;%0A                break;%0A            %7D%0A            default: throw new RuntimeException(%22Failed to find the appropriate platform surface extension.%22);%0A        %7D%0A%0A%0A        ByteBuffer
  VK_KHR_
 OS_S
@@ -1970,35 +1970,32 @@
 teBuffer VK_KHR_
-OS_
 SURFACE_EXTENSIO
@@ -2009,29 +2009,24 @@
 UTF8(VK_KHR_
-XLIB_
 SURFACE_EXTE
@@ -2050,24 +2050,18 @@
     
-else%0A           
+ByteBuffer
  VK_
@@ -2099,46 +2099,28 @@
 TF8(
-VK_EXT_METAL_SURFACE_EXTENSION_NAME
+surfaceExtension
 );%0A
+%0A
     

Change elif to switch