update GLFWVulkan.java

This commit is contained in:
Tungstend 2024-01-13 18:09:29 +08:00
parent c262631d9b
commit 2a627754dc
3 changed files with 33 additions and 73 deletions

View File

@ -1 +1 @@
1705088630563 1705140535678

View File

@ -18,28 +18,16 @@ import static org.lwjgl.system.Checks.*;
import static org.lwjgl.system.JNI.*; import static org.lwjgl.system.JNI.*;
import static org.lwjgl.system.MemoryStack.*; import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*; import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.vulkan.EXTMetalSurface.VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
import static org.lwjgl.vulkan.EXTMetalSurface.vkCreateMetalSurfaceEXT;
import static org.lwjgl.vulkan.KHRAndroidSurface.VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
import static org.lwjgl.vulkan.KHRAndroidSurface.vkCreateAndroidSurfaceKHR;
import org.lwjgl.vulkan.*; import org.lwjgl.vulkan.*;
/** Native bindings to the GLFW library's Vulkan functions. */ /** Native bindings to the GLFW library's Vulkan functions. */
public class GLFWVulkan { public class GLFWVulkan {
/** Contains the function pointers loaded from {@code GLFW.getLibrary()}. */
public static final class Functions {
private Functions() {}
/** Function address. */
public static final long
InitVulkanLoader = apiGetFunctionAddress(GLFW.getLibrary(), "glfwInitVulkanLoader"),
VulkanSupported = apiGetFunctionAddress(GLFW.getLibrary(), "glfwVulkanSupported"),
GetRequiredInstanceExtensions = apiGetFunctionAddress(GLFW.getLibrary(), "glfwGetRequiredInstanceExtensions"),
GetInstanceProcAddress = apiGetFunctionAddress(GLFW.getLibrary(), "glfwGetInstanceProcAddress"),
GetPhysicalDevicePresentationSupport = apiGetFunctionAddress(GLFW.getLibrary(), "glfwGetPhysicalDevicePresentationSupport"),
CreateWindowSurface = apiGetFunctionAddress(GLFW.getLibrary(), "glfwCreateWindowSurface");
}
static { static {
if (Platform.get() == Platform.MACOSX) { if (Platform.get() == Platform.MACOSX) {
setPath(VK.getFunctionProvider()); setPath(VK.getFunctionProvider());
@ -78,8 +66,8 @@ public class GLFWVulkan {
* @since version 3.4 * @since version 3.4
*/ */
public static void glfwInitVulkanLoader(@NativeType("PFN_vkGetInstanceProcAddr") long loader) { public static void glfwInitVulkanLoader(@NativeType("PFN_vkGetInstanceProcAddr") long loader) {
long __functionAddress = Functions.InitVulkanLoader; //long __functionAddress = Functions.InitVulkanLoader;
invokePV(loader, __functionAddress); //invokePV(loader, __functionAddress);
} }
// --- [ glfwVulkanSupported ] --- // --- [ glfwVulkanSupported ] ---
@ -101,22 +89,13 @@ public class GLFWVulkan {
*/ */
@NativeType("int") @NativeType("int")
public static boolean glfwVulkanSupported() { public static boolean glfwVulkanSupported() {
long __functionAddress = Functions.VulkanSupported; //long __functionAddress = Functions.VulkanSupported;
return invokeI(__functionAddress) != 0; //return invokeI(__functionAddress) != 0;
return true;
} }
// --- [ glfwGetRequiredInstanceExtensions ] --- // --- [ glfwGetRequiredInstanceExtensions ] ---
/**
* Unsafe version of: {@link #glfwGetRequiredInstanceExtensions GetRequiredInstanceExtensions}
*
* @param count where to store the number of extensions in the returned array. This is set to zero if an error occurred.
*/
public static long nglfwGetRequiredInstanceExtensions(long count) {
long __functionAddress = Functions.GetRequiredInstanceExtensions;
return invokePP(count, __functionAddress);
}
/** /**
* Returns an array of names of Vulkan instance extensions required by GLFW for creating Vulkan surfaces for GLFW windows. If successful, the list will * Returns an array of names of Vulkan instance extensions required by GLFW for creating Vulkan surfaces for GLFW windows. If successful, the list will
* always contain {@code VK_KHR_surface}, so if you don't require any additional extensions you can pass this list directly to the {@link VkInstanceCreateInfo} * always contain {@code VK_KHR_surface}, so if you don't require any additional extensions you can pass this list directly to the {@link VkInstanceCreateInfo}
@ -144,22 +123,14 @@ public class GLFWVulkan {
@Nullable @Nullable
@NativeType("char const **") @NativeType("char const **")
public static PointerBuffer glfwGetRequiredInstanceExtensions() { public static PointerBuffer glfwGetRequiredInstanceExtensions() {
MemoryStack stack = stackGet(); int stackPointer = stack.getPointer(); MemoryStack stack = MemoryStack.stackPush();
IntBuffer count = stack.callocInt(1); String platformSurface;
try { if (Platform.get() == Platform.MACOSX) {
long __result = nglfwGetRequiredInstanceExtensions(memAddress(count)); platformSurface = "VK_EXT_metal_surface";
return memPointerBufferSafe(__result, count.get(0)); } else {
} finally { platformSurface = "VK_KHR_android_surface";
stack.setPointer(stackPointer);
} }
} return stack.pointers(stack.UTF8(KHRSurface.VK_KHR_SURFACE_EXTENSION_NAME), stack.UTF8(platformSurface));
// --- [ glfwGetInstanceProcAddress ] ---
/** Unsafe version of: {@link #glfwGetInstanceProcAddress GetInstanceProcAddress} */
public static long nglfwGetInstanceProcAddress(long instance, long procname) {
long __functionAddress = Functions.GetInstanceProcAddress;
return invokePPP(instance, procname, __functionAddress);
} }
/** /**
@ -196,7 +167,7 @@ public class GLFWVulkan {
if (CHECKS) { if (CHECKS) {
checkNT1(procname); checkNT1(procname);
} }
return nglfwGetInstanceProcAddress(memAddressSafe(instance), memAddress(procname)); return VK10.vkGetInstanceProcAddr(instance, procname);
} }
/** /**
@ -230,14 +201,7 @@ public class GLFWVulkan {
*/ */
@NativeType("GLFWvkproc") @NativeType("GLFWvkproc")
public static long glfwGetInstanceProcAddress(@Nullable VkInstance instance, @NativeType("char const *") CharSequence procname) { public static long glfwGetInstanceProcAddress(@Nullable VkInstance instance, @NativeType("char const *") CharSequence procname) {
MemoryStack stack = stackGet(); int stackPointer = stack.getPointer(); return VK10.vkGetInstanceProcAddr(instance, procname);
try {
stack.nASCII(procname, true);
long procnameEncoded = stack.getPointerAddress();
return nglfwGetInstanceProcAddress(memAddressSafe(instance), procnameEncoded);
} finally {
stack.setPointer(stackPointer);
}
} }
// --- [ glfwGetPhysicalDevicePresentationSupport ] --- // --- [ glfwGetPhysicalDevicePresentationSupport ] ---
@ -266,21 +230,11 @@ public class GLFWVulkan {
*/ */
@NativeType("int") @NativeType("int")
public static boolean glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, @NativeType("uint32_t") int queuefamily) { public static boolean glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, @NativeType("uint32_t") int queuefamily) {
long __functionAddress = Functions.GetPhysicalDevicePresentationSupport; return true;
return invokePPI(instance.address(), device.address(), queuefamily, __functionAddress) != 0;
} }
// --- [ glfwCreateWindowSurface ] --- // --- [ glfwCreateWindowSurface ] ---
/** Unsafe version of: {@link #glfwCreateWindowSurface CreateWindowSurface} */
public static int nglfwCreateWindowSurface(long instance, long window, long allocator, long surface) {
long __functionAddress = Functions.CreateWindowSurface;
if (CHECKS) {
check(window);
}
return invokePPPPI(instance, window, allocator, surface, __functionAddress);
}
/** /**
* Creates a Vulkan surface for the specified window. * Creates a Vulkan surface for the specified window.
* *
@ -329,18 +283,24 @@ public class GLFWVulkan {
if (CHECKS) { if (CHECKS) {
check(surface, 1); check(surface, 1);
} }
return nglfwCreateWindowSurface(instance.address(), window, memAddressSafe(allocator), memAddress(surface)); if (Platform.get() == Platform.FCL) {
VkAndroidSurfaceCreateInfoKHR pCreateInfo = VkAndroidSurfaceCreateInfoKHR
.calloc()
.sType(VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR)
.window(window);
return vkCreateAndroidSurfaceKHR(instance, pCreateInfo, null, surface);
}
return VK10.VK_ERROR_EXTENSION_NOT_PRESENT;
} }
/** Array version of: {@link #glfwCreateWindowSurface CreateWindowSurface} */ /** Array version of: {@link #glfwCreateWindowSurface CreateWindowSurface} */
@NativeType("VkResult") @NativeType("VkResult")
public static int glfwCreateWindowSurface(VkInstance instance, @NativeType("GLFWwindow *") long window, @Nullable @NativeType("VkAllocationCallbacks const *") VkAllocationCallbacks allocator, @NativeType("VkSurfaceKHR *") long[] surface) { public static int glfwCreateWindowSurface(VkInstance instance, @NativeType("GLFWwindow *") long window, @Nullable @NativeType("VkAllocationCallbacks const *") VkAllocationCallbacks allocator, @NativeType("VkSurfaceKHR *") long[] surface) {
long __functionAddress = Functions.CreateWindowSurface; MemoryStack stack = stackGet();
if (CHECKS) { LongBuffer pSurface = stack.mallocLong(1);
check(window); int result = glfwCreateWindowSurface(instance, window, allocator, pSurface);
check(surface, 1); surface[0] = pSurface.get(0);
} return result;
return invokePPPPI(instance.address(), window, memAddressSafe(allocator), surface, __functionAddress);
} }
/** /**