• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java VkInstance类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中org.lwjgl.vulkan.VkInstance的典型用法代码示例。如果您正苦于以下问题:Java VkInstance类的具体用法?Java VkInstance怎么用?Java VkInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

VkInstance类属于org.lwjgl.vulkan包,在下文中一共展示了VkInstance类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: main

点赞 3

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
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);
}
 

开发者ID:httpdigest,
项目名称:lwjgl3-awt,
代码行数:23,
代码来源:SimpleDemo.java

示例2: setupDebugging

点赞 3

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
/**
 * This function sets up the debug callback which the validation layers will use to yell at us when we make mistakes.
 */
private static long setupDebugging(VkInstance instance, int flags, VkDebugReportCallbackEXT callback) {
    // Again, a struct to create something, in this case the debug report callback
    VkDebugReportCallbackCreateInfoEXT dbgCreateInfo = VkDebugReportCallbackCreateInfoEXT.callocStack()
            .sType(VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT) // <- the struct type
            .pNext(NULL) // <- must be NULL
            .pfnCallback(callback) // <- the actual function pointer (in LWJGL a Closure)
            .pUserData(NULL) // <- any user data provided to the debug report callback function
            .flags(flags); // <- indicates which kind of messages we want to receive
    LongBuffer pCallback = stackMallocLong(1); // <- allocate a LongBuffer (for a non-dispatchable handle)
    // Actually create the debug report callback
    int err = vkCreateDebugReportCallbackEXT(instance, dbgCreateInfo, null, pCallback);
    long callbackHandle = pCallback.get(0);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    return callbackHandle;
}
 

开发者ID:LWJGLX,
项目名称:autostack,
代码行数:21,
代码来源:ClearScreenDemoUseNewStack.java

示例3: getFirstPhysicalDevice

点赞 3

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
/**
 * Returns the handle to the first physical device connected to the system.
 *
 * @param instance The instance of the vulkan
 *
 * @return The handle to the first physical device.
 */
public static VkPhysicalDevice getFirstPhysicalDevice(VkInstance instance)
{
    IntBuffer gpuCount = memAllocInt(1);

    vkEnumeratePhysicalDevices(instance, gpuCount, null);
    PointerBuffer devices = memAllocPointer(gpuCount.get(0));
    vkEnumeratePhysicalDevices(instance, gpuCount, devices);

    VkPhysicalDevice firstPhysicalDevice = new VkPhysicalDevice(devices.get(0), instance);

    memFree(gpuCount);
    memFree(devices);

    return firstPhysicalDevice;
}
 

开发者ID:sriharshachilakapati,
项目名称:Vulkan-Tests,
代码行数:23,
代码来源:VkUtils.java

示例4: setupDebugging

点赞 3

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
private long setupDebugging(VkInstance instance, int flags, VkDebugReportCallbackEXT callback) {
    VkDebugReportCallbackCreateInfoEXT dbgCreateInfo = VkDebugReportCallbackCreateInfoEXT.calloc()
            .sType(VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT)
            .pNext(0)
            .pfnCallback(callback)
            .pUserData(0)
            .flags(flags);
    LongBuffer pCallback = memAllocLong(1);
    int err = vkCreateDebugReportCallbackEXT(instance, dbgCreateInfo, null, pCallback);
    long callbackHandle = pCallback.get(0);
    memFree(pCallback);
    dbgCreateInfo.free();
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to create VkInstance: " + VKUtil.translateVulkanResult(err));
    }
    return callbackHandle;
}
 

开发者ID:oreonengine,
项目名称:oreon-engine,
代码行数:18,
代码来源:VKRenderEngine.java

示例5: getFirstPhysicalDevice

点赞 3

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
private VkPhysicalDevice getFirstPhysicalDevice(VkInstance instance) {
    IntBuffer pPhysicalDeviceCount = memAllocInt(1);
    int err = vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, null);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to get number of physical devices: " + VKUtil.translateVulkanResult(err));
    }
    PointerBuffer pPhysicalDevices = memAllocPointer(pPhysicalDeviceCount.get(0));
    err = vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
    long physicalDevice = pPhysicalDevices.get(0);
    memFree(pPhysicalDeviceCount);
    memFree(pPhysicalDevices);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to get physical devices: " + VKUtil.translateVulkanResult(err));
    }
    return new VkPhysicalDevice(physicalDevice, instance);
}
 

开发者ID:oreonengine,
项目名称:oreon-engine,
代码行数:17,
代码来源:VKRenderEngine.java

示例6: setupDebugging

点赞 3

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
/**
 * This function sets up the debug callback which the validation layers will use to yell at us when we make mistakes.
 */
private static long setupDebugging(VkInstance instance, int flags, VkDebugReportCallbackEXT callback) {
    // Again, a struct to create something, in this case the debug report callback
    VkDebugReportCallbackCreateInfoEXT dbgCreateInfo = VkDebugReportCallbackCreateInfoEXT.calloc()
            .sType(VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT) // <- the struct type
            .pNext(NULL) // <- must be NULL
            .pfnCallback(callback) // <- the actual function pointer (in LWJGL a Closure)
            .pUserData(NULL) // <- any user data provided to the debug report callback function
            .flags(flags); // <- indicates which kind of messages we want to receive
    LongBuffer pCallback = memAllocLong(1); // <- allocate a LongBuffer (for a non-dispatchable handle)
    // Actually create the debug report callback
    int err = vkCreateDebugReportCallbackEXT(instance, dbgCreateInfo, null, pCallback);
    long callbackHandle = pCallback.get(0);
    memFree(pCallback); // <- and free the LongBuffer
    dbgCreateInfo.free(); // <- and also the create-info struct
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    return callbackHandle;
}
 

开发者ID:httpdigest,
项目名称:lwjgl3-swt,
代码行数:23,
代码来源:ClearScreenDemo.java

示例7: getFirstPhysicalDevice

点赞 3

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
/**
 * This method will enumerate the physical devices (i.e. GPUs) the system has available for us, and will just return
 * the first one. 
 */
private static VkPhysicalDevice getFirstPhysicalDevice(VkInstance instance) {
    IntBuffer pPhysicalDeviceCount = memAllocInt(1);
    int err = vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, null);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to get number of physical devices: " + translateVulkanResult(err));
    }
    PointerBuffer pPhysicalDevices = memAllocPointer(pPhysicalDeviceCount.get(0));
    err = vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
    long physicalDevice = pPhysicalDevices.get(0);
    memFree(pPhysicalDeviceCount);
    memFree(pPhysicalDevices);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to get physical devices: " + translateVulkanResult(err));
    }
    return new VkPhysicalDevice(physicalDevice, instance);
}
 

开发者ID:httpdigest,
项目名称:lwjgl3-swt,
代码行数:21,
代码来源:ClearScreenDemo.java

示例8: getFirstPhysicalDevice

点赞 2

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
/**
 * This method will enumerate the physical devices (i.e. GPUs) the system has available for us, and will just return
 * the first one. 
 */
private static VkPhysicalDevice getFirstPhysicalDevice(VkInstance instance) {
    IntBuffer pPhysicalDeviceCount = stackMallocInt(1);
    int err = vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, null);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to get number of physical devices: " + translateVulkanResult(err));
    }
    PointerBuffer pPhysicalDevices = stackMallocPointer(pPhysicalDeviceCount.get(0));
    err = vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
    long physicalDevice = pPhysicalDevices.get(0);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to get physical devices: " + translateVulkanResult(err));
    }
    return new VkPhysicalDevice(physicalDevice, instance);
}
 

开发者ID:LWJGLX,
项目名称:autostack,
代码行数:19,
代码来源:ClearScreenDemoUseNewStack.java

示例9: createInstance

点赞 2

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
private 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(0)
            .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: " + VKUtil.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;
}
 

开发者ID:oreonengine,
项目名称:oreon-engine,
代码行数:39,
代码来源:VKRenderEngine.java

示例10: createInstance

点赞 2

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
/**
 * 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;
}
 

开发者ID:httpdigest,
项目名称:lwjgl3-swt,
代码行数:43,
代码来源:SimpleDemo.java

示例11: main

点赞 2

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
public static void main(String[] args) {
    // Create the Vulkan instance
    VkInstance instance = createInstance();

    // Create SWT Display, Shell and VKCanvas
    final Display display = new Display();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE);
    shell.setLayout(new FillLayout());
    shell.addListener(SWT.Traverse, new Listener() {
        public void handleEvent(Event event) {
            switch (event.detail) {
            case SWT.TRAVERSE_ESCAPE:
                shell.close();
                event.detail = SWT.TRAVERSE_NONE;
                event.doit = false;
                break;
            }
        }
    });
    VKData data = new VKData();
    data.instance = instance; // <- set Vulkan instance
    final VKCanvas canvas = new VKCanvas(shell, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE, data);
    shell.setSize(800, 600);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    canvas.dispose();
    display.dispose();
}
 

开发者ID:httpdigest,
项目名称:lwjgl3-swt,
代码行数:32,
代码来源:SimpleDemo.java

示例12: createInstance

点赞 2

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
/**
 * 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;
}
 

开发者ID:httpdigest,
项目名称:lwjgl3-awt,
代码行数:43,
代码来源:SimpleDemo.java

示例13: createInstance

点赞 2

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
/**
 * 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.callocStack()
            .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
            .pApplicationName(stackUTF8("GLFW Vulkan Demo"))
            .pEngineName(stackUTF8(""))
            .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 = stackUTF8(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
    PointerBuffer ppEnabledExtensionNames = stackMallocPointer(requiredExtensions.remaining() + 1);
    ppEnabledExtensionNames.put(requiredExtensions) // <- platform-dependent required extensions
                           .put(VK_EXT_DEBUG_REPORT_EXTENSION) // <- the debug extensions
                           .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 = stackMallocPointer(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.callocStack()
            .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO) // <- identifies what kind of struct this is (this is useful for extending the struct type later)
            .pNext(NULL) // <- must always be NULL until any next Vulkan version tells otherwise
            .pApplicationInfo(appInfo) // <- the application info we created above
            .ppEnabledExtensionNames(ppEnabledExtensionNames) // <- and the extension names themselves
            .ppEnabledLayerNames(ppEnabledLayerNames); // <- and the layer names themselves
    PointerBuffer pInstance = stackMallocPointer(1); // <- create a PointerBuffer which will hold the handle to the created VkInstance
    int err = vkCreateInstance(pCreateInfo, null, pInstance); // <- actually create the VkInstance now!
    long instance = pInstance.get(0); // <- get the VkInstance handle
    // One word about freeing memory:
    // Every host-allocated memory directly or indirectly referenced via a parameter to any Vulkan function can always
    // be freed right after the invocation of the Vulkan function returned.

    // 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);
    return ret;
}
 

开发者ID:LWJGLX,
项目名称:autostack,
代码行数:61,
代码来源:ClearScreenDemoUseNewStack.java

示例14: start

点赞 2

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
/**
 * The main heart of an example, it runs the event loop and manages the creation and destruction of the window and
 * also creates the surface for Vulkan.
 */
public void start()
{
    glfwInit();

    // Check if Vulkan is available, if not, exit early.
    if (!glfwVulkanSupported())
        throw new UnsupportedOperationException("Vulkan driver is not found on this machine. Please update your drivers.");

    // Create a GLFW window with no API
    glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);

    if (title == null)
        title = "Vulkan Tests";

    windowID = glfwCreateWindow(800, 600, title, NULL, NULL);

    // Initialize Vulkan and get the instance.
    VkInstance vulkanInstance = initVulkan();

    // Create the surface and attach to the window.
    LongBuffer pSurface = memAllocLong(1);
    int err = glfwCreateWindowSurface(vulkanInstance, windowID, null, pSurface);

    if (err != 0)
        throw new IllegalStateException("Could not create surface for Vulkan");

    long surfaceID = pSurface.get();

    memFree(pSurface);

    while (!glfwWindowShouldClose(windowID))
    {
        glfwPollEvents();
        render();
    }

    vkDestroySurfaceKHR(vulkanInstance, surfaceID, null);
    cleanUp();

    glfwTerminate();
}
 

开发者ID:sriharshachilakapati,
项目名称:Vulkan-Tests,
代码行数:46,
代码来源:VulkanExample.java

示例15: initVulkan

点赞 2

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
@Override
public VkInstance initVulkan()
{
    // We need to say which extensions to enable at the time of creating the instance. We should also add in the
    // extensions required by GLFW to create the surface. Note that this should not be freed manually.
    PointerBuffer glfwExtensions = glfwGetRequiredInstanceExtensions();

    // Create a PointerBuffer with memory enough to hold pointers for all the extension names.
    PointerBuffer enabledExtensionNames = memAllocPointer(glfwExtensions.remaining() + 1);

    // Encode the surface extension names into a ByteBuffer so we can put it in the PointerBuffer.
    ByteBuffer KHR_SURFACE_EXTENSION = memASCII(VK_KHR_SURFACE_EXTENSION_NAME);

    // Add the extensions to the PointerBuffer and flip the buffer. In order to present something
    // we must request the KHR_SURFACE_EXTENSION, without which, the instance will act like an offscreen context.
    enabledExtensionNames.put(KHR_SURFACE_EXTENSION);

    // Also put in the GLFW extensions into the enabledExtensionNames list so they get enabled too.
    while (glfwExtensions.remaining() > 0)
        enabledExtensionNames.put(glfwExtensions.get());

    // Flip the buffer so that the system can read from the buffer.
    enabledExtensionNames.flip();

    // The VkApplicationInfo struct contains information about the application that we are going to create.
    VkApplicationInfo appInfo = VkApplicationInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
            .pApplicationName(memASCII("Vulkan Instance Example"))
            .pEngineName(memASCII(""))
            .apiVersion(VK_MAKE_VERSION(1, 0, 4));

    // The VkInstanceCreateInfo struct contains information about the Vulkan instance, and refers to the appInfo.
    VkInstanceCreateInfo instInfo = VkInstanceCreateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
            .pNext(NULL)
            .pApplicationInfo(appInfo)
            .ppEnabledExtensionNames(enabledExtensionNames);

    // The PointerBuffer enough to hold one pointer, the PointerBuffer is not a pointer, but it's contents are.
    PointerBuffer pInstance = memAllocPointer(1);

    // Create the instance. The instance handle is stored in the PointerBuffer which we can use now.
    vkCreateInstance(instInfo, null, pInstance);

    // Get the VkInstance handle from the pointer
    instance = new VkInstance(pInstance.get(), instInfo);

    // Free the pointer buffer, not the VkInstance struct
    memFree(pInstance);

    // Free the VkApplicationInfo and VkInstanceCreateInfo structs, we no longer need them in our application.
    appInfo.free();
    instInfo.free();

    // Free the extension names, we don't need them now.
    memFree(enabledExtensionNames);
    memFree(KHR_SURFACE_EXTENSION);

    // Print out the instance capabilities
    VKCapabilities capabilities = instance.getCapabilities();

    System.out.println("Vulkan10: " + capabilities.Vulkan10);
    System.out.println("VK_KHR_display: " + capabilities.VK_KHR_display);
    System.out.println("VK_KHR_surface: " + capabilities.VK_KHR_surface);
    System.out.println("VK_KHR_swapchain: " + capabilities.VK_KHR_swapchain);
    System.out.println("VK_EXT_debug_report: " + capabilities.VK_EXT_debug_report);
    System.out.println("VK_KHR_xlib_surface: " + capabilities.VK_KHR_xlib_surface);
    System.out.println("VK_KHR_win32_surface: " + capabilities.VK_KHR_win32_surface);
    System.out.println("VK_KHR_display_swapchain: " + capabilities.VK_KHR_display_swapchain);
    System.out.println("VK_KHR_sampler_mirror_clamp_to_edge: " + capabilities.VK_KHR_sampler_mirror_clamp_to_edge);

    // Return instance to attach to the display so rendering can be done.
    return instance;
}
 

开发者ID:sriharshachilakapati,
项目名称:Vulkan-Tests,
代码行数:75,
代码来源:InstanceExample.java

示例16: createInstance

点赞 2

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
/**
 * 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;
}
 

开发者ID:httpdigest,
项目名称:lwjgl3-swt,
代码行数:53,
代码来源:ClearScreenDemo.java

示例17: initVulkan

点赞 1

import org.lwjgl.vulkan.VkInstance; //导入依赖的package包/类
/**
 * The job of this method is to initialize Vulkan and return the VkInstance struct handle so that it is used to
 * create a surface and attaches with the window. The initialization code should request the KHR_SURFACE extension
 * to be able to create the surface.
 *
 * @return The VkInstance handle to the successfully initialized Vulkan instance.
 */
public abstract VkInstance initVulkan();
 

开发者ID:sriharshachilakapati,
项目名称:Vulkan-Tests,
代码行数:9,
代码来源:VulkanExample.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)