All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.lwjgl.vulkan.VkInstance Maven / Gradle / Ivy

Go to download

A new generation graphics and compute API that provides high-efficiency, cross-platform access to modern GPUs used in a wide variety of devices from PCs and consoles to mobile phones and embedded platforms.

There is a newer version: 3.3.4
Show newest version
/*
 * Copyright LWJGL. All rights reserved.
 * License terms: https://www.lwjgl.org/license
 */
package org.lwjgl.vulkan;

import org.lwjgl.system.Checks;

import static org.lwjgl.system.APIUtil.*;
import static org.lwjgl.system.JNI.*;
import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.vulkan.VK10.*;

/** Wraps a Vulkan instance handle. */
public class VkInstance extends DispatchableHandle {

	/**
	 * Creates a {@link VkInstance} instance for the specified native handle.
	 *
	 * @param handle the native {@code VkInstance} handle
	 * @param ci     the {@link VkInstanceCreateInfo} structured used to create the {@code VkInstance}.
	 */
	public VkInstance(long handle, VkInstanceCreateInfo ci) {
		super(handle, getInstanceCapabilities(handle, ci));
	}

	private static VKCapabilities getInstanceCapabilities(long handle, VkInstanceCreateInfo ci) {
		VkApplicationInfo appInfo = ci.pApplicationInfo();
		int apiVersion;
		if ( appInfo != null )
			apiVersion = appInfo.apiVersion();
		else {
			// TODO: Do a better job here when new Vulkan versions are released
			apiVersion = VK_MAKE_VERSION(1, 0, 0);
		}

		long GetInstanceProcAddr = VK.getFunctionProvider().getFunctionAddress("vkGetInstanceProcAddr");
		if ( GetInstanceProcAddr == NULL )
			throw new IllegalStateException("A core Vulkan function is missing. Make sure that Vulkan is available.");

		return new VKCapabilities(functionName -> {
			long address = GetInstanceProcAddr(GetInstanceProcAddr, handle, memAddress(functionName));
			if ( address == NULL ) {
				address = VK.getFunctionProvider().getFunctionAddress(functionName);
				if ( address == NULL && Checks.DEBUG_FUNCTIONS )
					apiLog("Failed to locate address for VK instance function " + memASCII(functionName));
			}
			return address;
		}, apiVersion, VK.getEnabledExtensionSet(apiVersion, ci.ppEnabledExtensionNames()));
	}

	static long GetInstanceProcAddr(long __functionAddress, long handle, long functionName) {
		long address = callPPP(__functionAddress, handle, functionName);
		if ( address == NULL )
			address = callPPP(__functionAddress, NULL, functionName);

		return address;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy