diff --git a/modules/overrungl.core/src/main/java/overrungl/Configurations.java b/modules/overrungl.core/src/main/java/overrungl/Configurations.java index 7bfb0acb..ad6dc91a 100644 --- a/modules/overrungl.core/src/main/java/overrungl/Configurations.java +++ b/modules/overrungl.core/src/main/java/overrungl/Configurations.java @@ -16,6 +16,8 @@ package overrungl; +import java.lang.foreign.SymbolLookup; +import java.util.function.Function; import java.util.function.Supplier; /** @@ -68,11 +70,32 @@ public final class Configurations { */ public static final Entry CHECKS = new Entry<>(() -> true); /** - * Forcing check all method handles for GL. + * Forcing to check all method handles for OpenGL. *

* The default value is {@code false}. */ public static final Entry GL_FORCE_CHECK_ALL = new Entry<>(() -> false); + /** + * The symbol lookup of GLFW. + * The returned value must not be null. + *

+ * The default value is {@code null}. + */ + public static final Entry> GLFW_SYMBOL_LOOKUP = new Entry<>(() -> null); + /** + * The symbol lookup of NFD. + * The returned value must not be null. + *

+ * The default value is {@code null}. + */ + public static final Entry> NFD_SYMBOL_LOOKUP = new Entry<>(() -> null); + /** + * The symbol lookup of STB. + * The returned value must not be null. + *

+ * The default value is {@code null}. + */ + public static final Entry> STB_SYMBOL_LOOKUP = new Entry<>(() -> null); private Configurations() { //no instance diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java index 7fe07306..d33247d6 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java @@ -845,10 +845,6 @@ public final class GLFW { */ public static final int DONT_CARE = -1; - static { - create(); - } - private GLFW() { throw new IllegalStateException("Do not construct instance"); } @@ -3287,7 +3283,7 @@ public static MemorySegment getWindowMonitor(MemorySegment window) { */ public static void setWindowMonitor(MemorySegment window, MemorySegment monitor, int xpos, int ypos, int width, int height, int refreshRate) { try { - glfwGetWindowMonitor.invokeExact(window, monitor, xpos, ypos, width, height, refreshRate); + glfwSetWindowMonitor.invokeExact(window, monitor, xpos, ypos, width, height, refreshRate); } catch (Throwable e) { throw new AssertionError("should not reach here", e); } @@ -3399,7 +3395,7 @@ public static void setWindowUserPointer(MemorySegment window, MemorySegment poin */ public static MemorySegment getWindowUserPointer(MemorySegment window) { try { - return (MemorySegment) glfwSetWindowUserPointer.invokeExact(window); + return (MemorySegment) glfwGetWindowUserPointer.invokeExact(window); } catch (Throwable e) { throw new AssertionError("should not reach here", e); } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWNative.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWNative.java index 71bd49f4..611c9e6f 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWNative.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWNative.java @@ -36,10 +36,6 @@ * @since 0.1.0 */ public final class GLFWNative { - static { - create(); - } - private GLFWNative() { //no instance } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVulkan.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVulkan.java index afa7c88c..5242d451 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVulkan.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVulkan.java @@ -30,10 +30,6 @@ * @since 0.1.0 */ public final class GLFWVulkan { - static { - create(); - } - /** * constructor */ diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/Handles.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/Handles.java index 82903ca9..6c2a6fd2 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/Handles.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/Handles.java @@ -16,6 +16,7 @@ package overrungl.glfw; +import overrungl.Configurations; import overrungl.FunctionDescriptors; import overrungl.internal.RuntimeHelper; @@ -35,42 +36,164 @@ * @since 0.1.0 */ final class Handles { - private static boolean initialized; - static SymbolLookup lookup; + private static final SymbolLookup lookup; + + static { + final SymbolLookup lib = RuntimeHelper.load("glfw", "glfw3", + STR. "\{ GLFW.VERSION_MAJOR }.\{ GLFW.VERSION_MINOR }.\{ GLFW.VERSION_REVISION }" ); + final var function = Configurations.GLFW_SYMBOL_LOOKUP.get(); + lookup = function != null ? function.apply(lib) : lib; + } + static MethodHandle - glfwInit, glfwTerminate, glfwInitHint, glfwGetVersion, glfwGetVersionString, glfwGetError, glfwSetErrorCallback, - glfwGetMonitors, glfwGetPrimaryMonitor, glfwGetMonitorPos, glfwGetMonitorWorkarea, glfwGetMonitorPhysicalSize, - glfwGetMonitorContentScale, glfwGetMonitorName, glfwSetMonitorUserPointer, glfwGetMonitorUserPointer, - glfwSetMonitorCallback, glfwGetVideoModes, glfwGetVideoMode, glfwSetGamma, glfwGetGammaRamp, glfwSetGammaRamp, - glfwDefaultWindowHints, glfwWindowHint, glfwWindowHintString, glfwCreateWindow, glfwDestroyWindow, glfwWindowShouldClose, - glfwSetWindowShouldClose, glfwSetWindowTitle, glfwSetWindowIcon, glfwGetWindowPos, glfwSetWindowPos, glfwGetWindowSize, - glfwSetWindowSizeLimits, glfwSetWindowAspectRatio, glfwSetWindowSize, glfwGetFramebufferSize, glfwGetWindowFrameSize, - glfwGetWindowContentScale, glfwGetWindowOpacity, glfwSetWindowOpacity, glfwIconifyWindow, glfwRestoreWindow, - glfwMaximizeWindow, glfwShowWindow, glfwHideWindow, glfwFocusWindow, glfwRequestWindowAttention, glfwGetWindowMonitor, - glfwSetWindowMonitor, glfwGetWindowAttrib, glfwSetWindowAttrib, glfwSetWindowUserPointer, glfwGetWindowUserPointer, - glfwSetWindowPosCallback, glfwSetWindowSizeCallback, glfwSetWindowCloseCallback, glfwSetWindowRefreshCallback, - glfwSetWindowFocusCallback, glfwSetWindowIconifyCallback, glfwSetWindowMaximizeCallback, glfwSetFramebufferSizeCallback, - glfwSetWindowContentScaleCallback, glfwPollEvents, glfwWaitEvents, glfwWaitEventsTimeout, glfwPostEmptyEvent, - glfwGetInputMode, glfwSetInputMode, glfwRawMouseMotionSupported, glfwGetKeyName, glfwGetKeyScancode, glfwGetKey, - glfwGetMouseButton, glfwGetCursorPos, glfwSetCursorPos, glfwCreateCursor, glfwCreateStandardCursor, glfwDestroyCursor, - glfwSetCursor, glfwSetKeyCallback, glfwSetCharCallback, glfwSetMouseButtonCallback, glfwSetCursorPosCallback, - glfwSetCursorEnterCallback, glfwSetScrollCallback, glfwSetDropCallback, glfwJoystickPresent, glfwGetJoystickAxes, - glfwGetJoystickButtons, glfwGetJoystickHats, glfwGetJoystickName, glfwGetJoystickGUID, glfwSetJoystickUserPointer, - glfwGetJoystickUserPointer, glfwJoystickIsGamepad, glfwSetJoystickCallback, glfwUpdateGamepadMappings, glfwGetGamepadName, - glfwGetGamepadState, glfwSetClipboardString, glfwGetClipboardString, glfwGetTime, glfwSetTime, glfwGetTimerValue, - glfwGetTimerFrequency, glfwMakeContextCurrent, glfwGetCurrentContext, glfwSwapBuffers, glfwSwapInterval, - glfwExtensionSupported, glfwGetProcAddress, glfwVulkanSupported, glfwGetRequiredInstanceExtensions; + glfwInit = downcall("glfwInit", I), + glfwTerminate = downcall("glfwTerminate", V), + glfwInitHint = downcall("glfwInitHint", IIV), + glfwGetVersion = downcallTrivial("glfwGetVersion", PPPV), + glfwGetVersionString = downcallTrivial("glfwGetVersionString", p), + glfwGetError = downcallTrivial("glfwGetError", fd_PI), + glfwSetErrorCallback = downcall("glfwSetErrorCallback", PP), + glfwGetMonitors = downcall("glfwGetMonitors", Pp), + glfwGetPrimaryMonitor = downcall("glfwGetPrimaryMonitor", P), + glfwGetMonitorPos = downcall("glfwGetMonitorPos", PPPV), + glfwGetMonitorWorkarea = downcall("glfwGetMonitorWorkarea", PPPPPV), + glfwGetMonitorPhysicalSize = downcall("glfwGetMonitorPhysicalSize", PPPV), + glfwGetMonitorContentScale = downcall("glfwGetMonitorContentScale", PPPV), + glfwGetMonitorName = downcall("glfwGetMonitorName", Pp), + glfwSetMonitorUserPointer = downcallTrivial("glfwSetMonitorUserPointer", PPV), + glfwGetMonitorUserPointer = downcallTrivial("glfwGetMonitorUserPointer", PP), + glfwSetMonitorCallback = downcall("glfwSetMonitorCallback", PP), + glfwGetVideoModes = downcall("glfwGetVideoModes", PPp), + glfwGetVideoMode = downcall("glfwGetVideoMode", FunctionDescriptor.of(ADDRESS.withTargetLayout(GLFWVidMode.LAYOUT), ADDRESS)), + glfwSetGamma = downcall("glfwSetGamma", PFV), + glfwGetGammaRamp = downcall("glfwGetGammaRamp", FunctionDescriptor.of(ADDRESS.withTargetLayout(GLFWGammaRamp.LAYOUT), ADDRESS)), + glfwSetGammaRamp = downcall("glfwSetGammaRamp", PPV), + glfwDefaultWindowHints = downcall("glfwDefaultWindowHints", V), + glfwWindowHint = downcall("glfwWindowHint", IIV), + glfwWindowHintString = downcall("glfwWindowHintString", IPV), + glfwCreateWindow = downcall("glfwCreateWindow", IIPPPP), + glfwDestroyWindow = downcall("glfwDestroyWindow", PV), + glfwWindowShouldClose = downcallTrivial("glfwWindowShouldClose", fd_PI), + glfwSetWindowShouldClose = downcallTrivial("glfwSetWindowShouldClose", PIV), + glfwSetWindowTitle = downcall("glfwSetWindowTitle", PPV), + glfwSetWindowIcon = downcall("glfwSetWindowIcon", PIPV), + glfwGetWindowPos = downcall("glfwGetWindowPos", PPPV), + glfwSetWindowPos = downcall("glfwSetWindowPos", PIIV), + glfwGetWindowSize = downcall("glfwGetWindowSize", PPPV), + glfwSetWindowSizeLimits = downcall("glfwSetWindowSizeLimits", PIIIIV), + glfwSetWindowAspectRatio = downcall("glfwSetWindowAspectRatio", PIIV), + glfwSetWindowSize = downcall("glfwSetWindowSize", PIIV), + glfwGetFramebufferSize = downcall("glfwGetFramebufferSize", PPPV), + glfwGetWindowFrameSize = downcall("glfwGetWindowFrameSize", PPPPPV), + glfwGetWindowContentScale = downcall("glfwGetWindowContentScale", PPPV), + glfwGetWindowOpacity = downcall("glfwGetWindowOpacity", PF), + glfwSetWindowOpacity = downcall("glfwSetWindowOpacity", PFV), + glfwIconifyWindow = downcall("glfwIconifyWindow", PV), + glfwRestoreWindow = downcall("glfwRestoreWindow", PV), + glfwMaximizeWindow = downcall("glfwMaximizeWindow", PV), + glfwShowWindow = downcall("glfwShowWindow", PV), + glfwHideWindow = downcall("glfwHideWindow", PV), + glfwFocusWindow = downcall("glfwFocusWindow", PV), + glfwRequestWindowAttention = downcall("glfwRequestWindowAttention", PV), + glfwGetWindowMonitor = downcall("glfwGetWindowMonitor", PP), + glfwSetWindowMonitor = downcall("glfwSetWindowMonitor", PPIIIIIV), + glfwGetWindowAttrib = downcall("glfwGetWindowAttrib", PII), + glfwSetWindowAttrib = downcall("glfwSetWindowAttrib", PIIV), + glfwSetWindowUserPointer = downcallTrivial("glfwSetWindowUserPointer", PPV), + glfwGetWindowUserPointer = downcallTrivial("glfwGetWindowUserPointer", PP), + glfwSetWindowPosCallback = downcall("glfwSetWindowPosCallback", PPP), + glfwSetWindowSizeCallback = downcall("glfwSetWindowSizeCallback", PPP), + glfwSetWindowCloseCallback = downcall("glfwSetWindowCloseCallback", PPP), + glfwSetWindowRefreshCallback = downcall("glfwSetWindowRefreshCallback", PPP), + glfwSetWindowFocusCallback = downcall("glfwSetWindowFocusCallback", PPP), + glfwSetWindowIconifyCallback = downcall("glfwSetWindowIconifyCallback", PPP), + glfwSetWindowMaximizeCallback = downcall("glfwSetWindowMaximizeCallback", PPP), + glfwSetFramebufferSizeCallback = downcall("glfwSetFramebufferSizeCallback", PPP), + glfwSetWindowContentScaleCallback = downcall("glfwSetWindowContentScaleCallback", PPP), + glfwPollEvents = downcall("glfwPollEvents", V), + glfwWaitEvents = downcall("glfwWaitEvents", V), + glfwWaitEventsTimeout = downcall("glfwWaitEventsTimeout", DV), + glfwPostEmptyEvent = downcallTrivial("glfwPostEmptyEvent", V), + glfwGetInputMode = downcall("glfwGetInputMode", PII), + glfwSetInputMode = downcall("glfwSetInputMode", PIIV), + glfwRawMouseMotionSupported = downcall("glfwRawMouseMotionSupported", I), + glfwGetKeyName = downcall("glfwGetKeyName", IIp), + glfwGetKeyScancode = downcallTrivial("glfwGetKeyScancode", II), + glfwGetKey = downcall("glfwGetKey", PII), + glfwGetMouseButton = downcall("glfwGetMouseButton", PII), + glfwGetCursorPos = downcall("glfwGetCursorPos", PPPV), + glfwSetCursorPos = downcall("glfwSetCursorPos", PDDV), + glfwCreateCursor = downcall("glfwCreateCursor", PIIP), + glfwCreateStandardCursor = downcall("glfwCreateStandardCursor", IP), + glfwDestroyCursor = downcall("glfwDestroyCursor", PV), + glfwSetCursor = downcall("glfwSetCursor", PPV), + glfwSetKeyCallback = downcall("glfwSetKeyCallback", PPP), + glfwSetCharCallback = downcall("glfwSetCharCallback", PPP), + glfwSetMouseButtonCallback = downcall("glfwSetMouseButtonCallback", PPP), + glfwSetCursorPosCallback = downcall("glfwSetCursorPosCallback", PPP), + glfwSetCursorEnterCallback = downcall("glfwSetCursorEnterCallback", PPP), + glfwSetScrollCallback = downcall("glfwSetScrollCallback", PPP), + glfwSetDropCallback = downcall("glfwSetDropCallback", PPP), + glfwJoystickPresent = downcall("glfwJoystickPresent", II), + glfwGetJoystickAxes = downcall("glfwGetJoystickAxes", IPp), + glfwGetJoystickButtons = downcall("glfwGetJoystickButtons", IPp), + glfwGetJoystickHats = downcall("glfwGetJoystickHats", IPP), + glfwGetJoystickName = downcall("glfwGetJoystickName", Ip), + glfwGetJoystickGUID = downcall("glfwGetJoystickGUID", Ip), + glfwSetJoystickUserPointer = downcallTrivial("glfwSetJoystickUserPointer", IPV), + glfwGetJoystickUserPointer = downcallTrivial("glfwGetJoystickUserPointer", IP), + glfwJoystickIsGamepad = downcall("glfwJoystickIsGamepad", II), + glfwSetJoystickCallback = downcall("glfwSetJoystickCallback", PP), + glfwUpdateGamepadMappings = downcall("glfwUpdateGamepadMappings", fd_PI), + glfwGetGamepadName = downcall("glfwGetGamepadName", Ip), + glfwGetGamepadState = downcall("glfwGetGamepadState", IPI), + glfwSetClipboardString = downcall("glfwSetClipboardString", PPV), + glfwGetClipboardString = downcall("glfwGetClipboardString", Pp), + glfwGetTime = downcallTrivial("glfwGetTime", D), + glfwSetTime = downcallTrivial("glfwSetTime", DV), + glfwGetTimerValue = downcallTrivial("glfwGetTimerValue", J), + glfwGetTimerFrequency = downcallTrivial("glfwGetTimerFrequency", J), + glfwMakeContextCurrent = downcall("glfwMakeContextCurrent", PV), + glfwGetCurrentContext = downcallTrivial("glfwGetCurrentContext", P), + glfwSwapBuffers = downcall("glfwSwapBuffers", PV), + glfwSwapInterval = downcall("glfwSwapInterval", IV), + glfwExtensionSupported = downcall("glfwExtensionSupported", fd_PI), + glfwGetProcAddress = downcall("glfwGetProcAddress", PP), + glfwVulkanSupported = downcall("glfwVulkanSupported", I), + glfwGetRequiredInstanceExtensions = downcall("glfwGetRequiredInstanceExtensions", Pp); // GLFW Vulkan static MethodHandle - glfwGetInstanceProcAddress, glfwGetPhysicalDevicePresentationSupport, glfwCreateWindowSurface; + glfwGetInstanceProcAddress = downcall("glfwGetInstanceProcAddress", PPP), + glfwGetPhysicalDevicePresentationSupport = downcall("glfwGetPhysicalDevicePresentationSupport", PPII), + glfwCreateWindowSurface = downcall("glfwCreateWindowSurface", PPPPI); // GLFW Native static MethodHandle - glfwGetWin32Adapter, glfwGetWin32Monitor, glfwGetWin32Window, glfwGetWGLContext, glfwGetCocoaMonitor, glfwGetCocoaWindow, - glfwGetNSGLContext, glfwGetX11Display, glfwGetX11Adapter, glfwGetX11Monitor, glfwGetX11Window, glfwSetX11SelectionString, - glfwGetX11SelectionString, glfwGetGLXContext, glfwGetGLXWindow, glfwGetWaylandDisplay, glfwGetWaylandMonitor, glfwGetWaylandWindow, - glfwGetEGLDisplay, glfwGetEGLContext, glfwGetEGLSurface, glfwGetOSMesaColorBuffer, glfwGetOSMesaDepthBuffer, glfwGetOSMesaContext; + glfwGetWin32Adapter = downcallNative("glfwGetWin32Adapter", Pp), + glfwGetWin32Monitor = downcallNative("glfwGetWin32Monitor", Pp), + glfwGetWin32Window = downcallNative("glfwGetWin32Window", PP), + glfwGetWGLContext = downcallNative("glfwGetWGLContext", PP), + glfwGetCocoaMonitor = downcallNative("glfwGetCocoaMonitor", fd_PI), + glfwGetCocoaWindow = downcallNative("glfwGetCocoaWindow", PP), + glfwGetNSGLContext = downcallNative("glfwGetNSGLContext", PP), + glfwGetX11Display = downcallNative("glfwGetX11Display", P), + glfwGetX11Adapter = downcallNative("glfwGetX11Adapter", PJ), + glfwGetX11Monitor = downcallNative("glfwGetX11Monitor", PJ), + glfwGetX11Window = downcallNative("glfwGetX11Window", PJ), + glfwSetX11SelectionString = downcallNative("glfwSetX11SelectionString", PV), + glfwGetX11SelectionString = downcallNative("glfwGetX11SelectionString", p), + glfwGetGLXContext = downcallNative("glfwGetGLXContext", PP), + glfwGetGLXWindow = downcallNative("glfwGetGLXWindow", PJ), + glfwGetWaylandDisplay = downcallNative("glfwGetWaylandDisplay", P), + glfwGetWaylandMonitor = downcallNative("glfwGetWaylandMonitor", PP), + glfwGetWaylandWindow = downcallNative("glfwGetWaylandWindow", PP), + glfwGetEGLDisplay = downcallNative("glfwGetEGLDisplay", P), + glfwGetEGLContext = downcallNative("glfwGetEGLContext", PP), + glfwGetEGLSurface = downcallNative("glfwGetEGLSurface", PP), + glfwGetOSMesaColorBuffer = downcallNative("glfwGetOSMesaColorBuffer", PPPPPI), + glfwGetOSMesaDepthBuffer = downcallNative("glfwGetOSMesaDepthBuffer", PPPPPI), + glfwGetOSMesaContext = downcallNative("glfwGetOSMesaContext", PP); private Handles() { //no instance @@ -97,162 +220,4 @@ private static MethodHandle downcallNative(String name, FunctionDescriptors function) { return RuntimeHelper.downcallSafe(lookup.find(name).orElse(MemorySegment.NULL), function); } - - private static void createNative() { - glfwGetWin32Adapter = downcallNative("glfwGetWin32Adapter", Pp); - glfwGetWin32Monitor = downcallNative("glfwGetWin32Monitor", Pp); - glfwGetWin32Window = downcallNative("glfwGetWin32Window", PP); - glfwGetWGLContext = downcallNative("glfwGetWGLContext", PP); - glfwGetCocoaMonitor = downcallNative("glfwGetCocoaMonitor", fd_PI); - glfwGetCocoaWindow = downcallNative("glfwGetCocoaWindow", PP); - glfwGetNSGLContext = downcallNative("glfwGetNSGLContext", PP); - glfwGetX11Display = downcallNative("glfwGetX11Display", P); - glfwGetX11Adapter = downcallNative("glfwGetX11Adapter", PJ); - glfwGetX11Monitor = downcallNative("glfwGetX11Monitor", PJ); - glfwGetX11Window = downcallNative("glfwGetX11Window", PJ); - glfwSetX11SelectionString = downcallNative("glfwSetX11SelectionString", PV); - glfwGetX11SelectionString = downcallNative("glfwGetX11SelectionString", p); - glfwGetGLXContext = downcallNative("glfwGetGLXContext", PP); - glfwGetGLXWindow = downcallNative("glfwGetGLXWindow", PJ); - glfwGetWaylandDisplay = downcallNative("glfwGetWaylandDisplay", P); - glfwGetWaylandMonitor = downcallNative("glfwGetWaylandMonitor", PP); - glfwGetWaylandWindow = downcallNative("glfwGetWaylandWindow", PP); - glfwGetEGLDisplay = downcallNative("glfwGetEGLDisplay", P); - glfwGetEGLContext = downcallNative("glfwGetEGLContext", PP); - glfwGetEGLSurface = downcallNative("glfwGetEGLSurface", PP); - glfwGetOSMesaColorBuffer = downcallNative("glfwGetOSMesaColorBuffer", PPPPPI); - glfwGetOSMesaDepthBuffer = downcallNative("glfwGetOSMesaDepthBuffer", PPPPPI); - glfwGetOSMesaContext = downcallNative("glfwGetOSMesaContext", PP); - } - - static void create() { - if (initialized) return; - initialized = true; - - lookup = RuntimeHelper.load("glfw", "glfw3", - STR."\{GLFW.VERSION_MAJOR}.\{GLFW.VERSION_MINOR}.\{GLFW.VERSION_REVISION}"); - glfwInit = downcall("glfwInit", I); - glfwTerminate = downcall("glfwTerminate", V); - glfwInitHint = downcall("glfwInitHint", IIV); - glfwGetVersion = downcallTrivial("glfwGetVersion", PPPV); - glfwGetVersionString = downcallTrivial("glfwGetVersionString", p); - glfwGetError = downcallTrivial("glfwGetError", fd_PI); - glfwSetErrorCallback = downcall("glfwSetErrorCallback", PP); - glfwGetMonitors = downcall("glfwGetMonitors", Pp); - glfwGetPrimaryMonitor = downcall("glfwGetPrimaryMonitor", P); - glfwGetMonitorPos = downcall("glfwGetMonitorPos", PPPV); - glfwGetMonitorWorkarea = downcall("glfwGetMonitorWorkarea", PPPPPV); - glfwGetMonitorPhysicalSize = downcall("glfwGetMonitorPhysicalSize", PPPV); - glfwGetMonitorContentScale = downcall("glfwGetMonitorContentScale", PPPV); - glfwGetMonitorName = downcall("glfwGetMonitorName", Pp); - glfwSetMonitorUserPointer = downcallTrivial("glfwSetMonitorUserPointer", PPV); - glfwGetMonitorUserPointer = downcallTrivial("glfwGetMonitorUserPointer", PP); - glfwSetMonitorCallback = downcall("glfwSetMonitorCallback", PP); - glfwGetVideoModes = downcall("glfwGetVideoModes", PPp); - glfwGetVideoMode = downcall("glfwGetVideoMode", FunctionDescriptor.of(ADDRESS.withTargetLayout(GLFWVidMode.LAYOUT), ADDRESS)); - glfwSetGamma = downcall("glfwSetGamma", PFV); - glfwGetGammaRamp = downcall("glfwGetGammaRamp", FunctionDescriptor.of(ADDRESS.withTargetLayout(GLFWGammaRamp.LAYOUT), ADDRESS)); - glfwSetGammaRamp = downcall("glfwSetGammaRamp", PPV); - glfwDefaultWindowHints = downcall("glfwDefaultWindowHints", V); - glfwWindowHint = downcall("glfwWindowHint", IIV); - glfwWindowHintString = downcall("glfwWindowHintString", IPV); - glfwCreateWindow = downcall("glfwCreateWindow", IIPPPP); - glfwDestroyWindow = downcall("glfwDestroyWindow", PV); - glfwWindowShouldClose = downcallTrivial("glfwWindowShouldClose", fd_PI); - glfwSetWindowShouldClose = downcallTrivial("glfwSetWindowShouldClose", PIV); - glfwSetWindowTitle = downcall("glfwSetWindowTitle", PPV); - glfwSetWindowIcon = downcall("glfwSetWindowIcon", PIPV); - glfwGetWindowPos = downcall("glfwGetWindowPos", PPPV); - glfwSetWindowPos = downcall("glfwSetWindowPos", PIIV); - glfwGetWindowSize = downcall("glfwGetWindowSize", PPPV); - glfwSetWindowSizeLimits = downcall("glfwSetWindowSizeLimits", PIIIIV); - glfwSetWindowAspectRatio = downcall("glfwSetWindowAspectRatio", PIIV); - glfwSetWindowSize = downcall("glfwSetWindowSize", PIIV); - glfwGetFramebufferSize = downcall("glfwGetFramebufferSize", PPPV); - glfwGetWindowFrameSize = downcall("glfwGetWindowFrameSize", PPPPPV); - glfwGetWindowContentScale = downcall("glfwGetWindowContentScale", PPPV); - glfwGetWindowOpacity = downcall("glfwGetWindowOpacity", PF); - glfwSetWindowOpacity = downcall("glfwSetWindowOpacity", PFV); - glfwIconifyWindow = downcall("glfwIconifyWindow", PV); - glfwRestoreWindow = downcall("glfwRestoreWindow", PV); - glfwMaximizeWindow = downcall("glfwMaximizeWindow", PV); - glfwShowWindow = downcall("glfwShowWindow", PV); - glfwHideWindow = downcall("glfwHideWindow", PV); - glfwFocusWindow = downcall("glfwFocusWindow", PV); - glfwRequestWindowAttention = downcall("glfwRequestWindowAttention", PV); - glfwGetWindowMonitor = downcall("glfwGetWindowMonitor", PP); - glfwSetWindowMonitor = downcall("glfwSetWindowMonitor", PPIIIIIV); - glfwGetWindowAttrib = downcall("glfwGetWindowAttrib", PII); - glfwSetWindowAttrib = downcall("glfwSetWindowAttrib", PIIV); - glfwSetWindowUserPointer = downcallTrivial("glfwSetWindowUserPointer", PPV); - glfwGetWindowUserPointer = downcallTrivial("glfwGetWindowUserPointer", PP); - glfwSetWindowPosCallback = downcall("glfwSetWindowPosCallback", PPP); - glfwSetWindowSizeCallback = downcall("glfwSetWindowSizeCallback", PPP); - glfwSetWindowCloseCallback = downcall("glfwSetWindowCloseCallback", PPP); - glfwSetWindowRefreshCallback = downcall("glfwSetWindowRefreshCallback", PPP); - glfwSetWindowFocusCallback = downcall("glfwSetWindowFocusCallback", PPP); - glfwSetWindowIconifyCallback = downcall("glfwSetWindowIconifyCallback", PPP); - glfwSetWindowMaximizeCallback = downcall("glfwSetWindowMaximizeCallback", PPP); - glfwSetFramebufferSizeCallback = downcall("glfwSetFramebufferSizeCallback", PPP); - glfwSetWindowContentScaleCallback = downcall("glfwSetWindowContentScaleCallback", PPP); - glfwPollEvents = downcall("glfwPollEvents", V); - glfwWaitEvents = downcall("glfwWaitEvents", V); - glfwWaitEventsTimeout = downcall("glfwWaitEventsTimeout", DV); - glfwPostEmptyEvent = downcallTrivial("glfwPostEmptyEvent", V); - glfwGetInputMode = downcall("glfwGetInputMode", PII); - glfwSetInputMode = downcall("glfwSetInputMode", PIIV); - glfwRawMouseMotionSupported = downcall("glfwRawMouseMotionSupported", I); - glfwGetKeyName = downcall("glfwGetKeyName", IIp); - glfwGetKeyScancode = downcallTrivial("glfwGetKeyScancode", II); - glfwGetKey = downcall("glfwGetKey", PII); - glfwGetMouseButton = downcall("glfwGetMouseButton", PII); - glfwGetCursorPos = downcall("glfwGetCursorPos", PPPV); - glfwSetCursorPos = downcall("glfwSetCursorPos", PDDV); - glfwCreateCursor = downcall("glfwCreateCursor", PIIP); - glfwCreateStandardCursor = downcall("glfwCreateStandardCursor", IP); - glfwDestroyCursor = downcall("glfwDestroyCursor", PV); - glfwSetCursor = downcall("glfwSetCursor", PPV); - glfwSetKeyCallback = downcall("glfwSetKeyCallback", PPP); - glfwSetCharCallback = downcall("glfwSetCharCallback", PPP); - glfwSetMouseButtonCallback = downcall("glfwSetMouseButtonCallback", PPP); - glfwSetCursorPosCallback = downcall("glfwSetCursorPosCallback", PPP); - glfwSetCursorEnterCallback = downcall("glfwSetCursorEnterCallback", PPP); - glfwSetScrollCallback = downcall("glfwSetScrollCallback", PPP); - glfwSetDropCallback = downcall("glfwSetDropCallback", PPP); - glfwJoystickPresent = downcall("glfwJoystickPresent", II); - glfwGetJoystickAxes = downcall("glfwGetJoystickAxes", IPp); - glfwGetJoystickButtons = downcall("glfwGetJoystickButtons", IPp); - glfwGetJoystickHats = downcall("glfwGetJoystickHats", IPP); - glfwGetJoystickName = downcall("glfwGetJoystickName", Ip); - glfwGetJoystickGUID = downcall("glfwGetJoystickGUID", Ip); - glfwSetJoystickUserPointer = downcallTrivial("glfwSetJoystickUserPointer", IPV); - glfwGetJoystickUserPointer = downcallTrivial("glfwGetJoystickUserPointer", IP); - glfwJoystickIsGamepad = downcall("glfwJoystickIsGamepad", II); - glfwSetJoystickCallback = downcall("glfwSetJoystickCallback", PP); - glfwUpdateGamepadMappings = downcall("glfwUpdateGamepadMappings", fd_PI); - glfwGetGamepadName = downcall("glfwGetGamepadName", Ip); - glfwGetGamepadState = downcall("glfwGetGamepadState", IPI); - glfwSetClipboardString = downcall("glfwSetClipboardString", PPV); - glfwGetClipboardString = downcall("glfwGetClipboardString", Pp); - glfwGetTime = downcallTrivial("glfwGetTime", D); - glfwSetTime = downcallTrivial("glfwSetTime", DV); - glfwGetTimerValue = downcallTrivial("glfwGetTimerValue", J); - glfwGetTimerFrequency = downcallTrivial("glfwGetTimerFrequency", J); - glfwMakeContextCurrent = downcall("glfwMakeContextCurrent", PV); - glfwGetCurrentContext = downcallTrivial("glfwGetCurrentContext", P); - glfwSwapBuffers = downcall("glfwSwapBuffers", PV); - glfwSwapInterval = downcall("glfwSwapInterval", IV); - glfwExtensionSupported = downcall("glfwExtensionSupported", fd_PI); - glfwGetProcAddress = downcall("glfwGetProcAddress", PP); - glfwVulkanSupported = downcall("glfwVulkanSupported", I); - glfwGetRequiredInstanceExtensions = downcall("glfwGetRequiredInstanceExtensions", Pp); - - // GLFW Vulkan - glfwGetInstanceProcAddress = downcall("glfwGetInstanceProcAddress", PPP); - glfwGetPhysicalDevicePresentationSupport = downcall("glfwGetPhysicalDevicePresentationSupport", PPII); - glfwCreateWindowSurface = downcall("glfwCreateWindowSurface", PPPPI); - - // GLFW Native - createNative(); - } } diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java index 2f4478f6..9d8894e3 100644 --- a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java @@ -16,9 +16,9 @@ package overrungl.nfd; +import overrungl.Configurations; import overrungl.FunctionDescriptors; import overrungl.NativeType; -import overrungl.OverrunGL; import overrungl.internal.RuntimeHelper; import overrungl.os.Platform; import overrungl.util.MemoryStack; @@ -119,7 +119,14 @@ * @since 0.1.0 */ public final class NFD { - private static final SymbolLookup LOOKUP = RuntimeHelper.load("nfd", "nfd", "0.1.0.0"); + private static final SymbolLookup LOOKUP; + + static { + final SymbolLookup lib = RuntimeHelper.load("nfd", "nfd", "0.1.0.0"); + final var function = Configurations.NFD_SYMBOL_LOOKUP.get(); + LOOKUP = function != null ? function.apply(lib) : lib; + } + private static final Platform os = Platform.current(); private static final boolean isOsWin = os instanceof Platform.Windows; private static final boolean isOsWinOrApple = isOsWin || os instanceof Platform.MacOSX; diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/Handles.java b/modules/overrungl.stb/src/main/java/overrungl/stb/Handles.java index 8d9e3a28..107fe2e0 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/Handles.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/Handles.java @@ -16,6 +16,7 @@ package overrungl.stb; +import overrungl.Configurations; import overrungl.FunctionDescriptors; import overrungl.internal.RuntimeHelper; @@ -30,8 +31,13 @@ * @since 0.1.0 */ final class Handles { - private static boolean loaded = false; - private static SymbolLookup lookup; + private static final SymbolLookup lookup; + + static { + final SymbolLookup lib = RuntimeHelper.load("stb", "stb", "0.1.0.0"); + final var function = Configurations.STB_SYMBOL_LOOKUP.get(); + lookup = function != null ? function.apply(lib) : lib; + } private Handles() { //no instance @@ -47,10 +53,4 @@ static MethodHandle downcallTrivial(String name, FunctionDescriptors function) { return downcall(name, function, Linker.Option.isTrivial()); } - - public static void initialize() { - if (loaded) return; - loaded = true; - lookup = RuntimeHelper.load("stb", "stb", "0.1.0.0"); - } } diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBEasyFont.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBEasyFont.java index f91581dd..c64a9643 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBEasyFont.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBEasyFont.java @@ -59,27 +59,18 @@ * @since 0.1.0 */ public final class STBEasyFont { - private static MethodHandle - stb_easy_font_draw_segs, stb_easy_font_get_spacing, stb_easy_font_spacing, stb_easy_font_print, stb_easy_font_width, stb_easy_font_height; - - static { - initialize(); - create(); - } + private static final MethodHandle + stb_easy_font_draw_segs = downcall("stb_easy_font_draw_segs", FFPIIPPIII), + stb_easy_font_get_spacing = downcall("stb_easy_font_get_spacing", F), + stb_easy_font_spacing = downcall("stb_easy_font_spacing", FV), + stb_easy_font_print = downcall("stb_easy_font_print", FFPPPII), + stb_easy_font_width = downcall("stb_easy_font_width", fd_PI), + stb_easy_font_height = downcall("stb_easy_font_height", fd_PI); private STBEasyFont() { //no instance } - private static void create() { - stb_easy_font_draw_segs = downcall("stb_easy_font_draw_segs", FFPIIPPIII); - stb_easy_font_get_spacing = downcall("stb_easy_font_get_spacing", F); - stb_easy_font_spacing = downcall("stb_easy_font_spacing", FV); - stb_easy_font_print = downcall("stb_easy_font_print", FFPPPII); - stb_easy_font_width = downcall("stb_easy_font_width", fd_PI); - stb_easy_font_height = downcall("stb_easy_font_height", fd_PI); - } - public static int ndrawSegs(float x, float y, MemorySegment segs, int numSegs, boolean vertical, MemorySegment c, MemorySegment vbuf, int vbufSize, int offset) { try { return (int) stb_easy_font_draw_segs.invokeExact(x, y, segs, numSegs, vertical ? 1 : 0, c, vbuf, vbufSize, offset); diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBImage.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBImage.java index 1aaeafe2..40cf44a5 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBImage.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBImage.java @@ -36,17 +36,50 @@ * @since 0.1.0 */ public final class STBImage { - private static MethodHandle - stbi_convert_iphone_png_to_rgb, stbi_convert_iphone_png_to_rgb_thread, stbi_failure_reason, stbi_hdr_to_ldr_gamma, - stbi_hdr_to_ldr_scale, stbi_image_free, stbi_info, stbi_info_from_callbacks, stbi_info_from_file, stbi_info_from_memory, - stbi_is_16_bit, stbi_is_16_bit_from_callbacks, stbi_is_16_bit_from_file, stbi_is_16_bit_from_memory, stbi_is_hdr, - stbi_is_hdr_from_callbacks, stbi_is_hdr_from_file, stbi_is_hdr_from_memory, stbi_ldr_to_hdr_gamma, stbi_ldr_to_hdr_scale, - stbi_load, stbi_load_16, stbi_load_16_from_callbacks, stbi_load_16_from_memory, stbi_load_from_callbacks, stbi_load_from_file, - stbi_load_from_file_16, stbi_load_from_memory, stbi_load_gif_from_memory, stbi_loadf, stbi_loadf_from_callbacks, - stbi_loadf_from_file, stbi_loadf_from_memory, stbi_set_flip_vertically_on_load, stbi_set_flip_vertically_on_load_thread, - stbi_set_unpremultiply_on_load, stbi_set_unpremultiply_on_load_thread, stbi_zlib_decode_buffer, stbi_zlib_decode_malloc, - stbi_zlib_decode_malloc_guesssize, stbi_zlib_decode_malloc_guesssize_headerflag, stbi_zlib_decode_noheader_buffer, - stbi_zlib_decode_noheader_malloc; + private static final MethodHandle + stbi_convert_iphone_png_to_rgb = downcall("stbi_convert_iphone_png_to_rgb", IV), + stbi_convert_iphone_png_to_rgb_thread = downcall("stbi_convert_iphone_png_to_rgb_thread", IV), + stbi_failure_reason = downcall("stbi_failure_reason", p), + stbi_hdr_to_ldr_gamma = downcall("stbi_hdr_to_ldr_gamma", FV), + stbi_hdr_to_ldr_scale = downcall("stbi_hdr_to_ldr_scale", FV), + stbi_image_free = downcall("stbi_image_free", PV), + stbi_info = downcall("stbi_info", PPPPI), + stbi_info_from_callbacks = downcall("stbi_info_from_callbacks", PPPPPI), + stbi_info_from_file = downcall("stbi_info_from_file", PPPPI), + stbi_info_from_memory = downcall("stbi_info_from_memory", PIPPPI), + stbi_is_16_bit = downcall("stbi_is_16_bit", fd_PI), + stbi_is_16_bit_from_callbacks = downcall("stbi_is_16_bit_from_callbacks", PPI), + stbi_is_16_bit_from_file = downcall("stbi_is_16_bit_from_file", fd_PI), + stbi_is_16_bit_from_memory = downcall("stbi_is_16_bit_from_memory", PII), + stbi_is_hdr = downcall("stbi_is_hdr", fd_PI), + stbi_is_hdr_from_callbacks = downcall("stbi_is_hdr_from_callbacks", PPI), + stbi_is_hdr_from_file = downcall("stbi_is_hdr_from_file", fd_PI), + stbi_is_hdr_from_memory = downcall("stbi_is_hdr_from_memory", PII), + stbi_ldr_to_hdr_gamma = downcall("stbi_ldr_to_hdr_gamma", FV), + stbi_ldr_to_hdr_scale = downcall("stbi_ldr_to_hdr_scale", FV), + stbi_load = downcall("stbi_load", PPPPIp), + stbi_load_16 = downcall("stbi_load_16", PPPPIp), + stbi_load_16_from_callbacks = downcall("stbi_load_16_from_callbacks", PPPPPIp), + stbi_load_16_from_memory = downcall("stbi_load_16_from_memory", PIPPPIp), + stbi_load_from_callbacks = downcall("stbi_load_from_callbacks", PPPPPIp), + stbi_load_from_file = downcall("stbi_load_from_file", PPPPIp), + stbi_load_from_file_16 = downcall("stbi_load_from_file_16", PPPPIp), + stbi_load_from_memory = downcall("stbi_load_from_memory", PIPPPIp), + stbi_load_gif_from_memory = downcall("stbi_load_gif_from_memory", PIPPPPPIp), + stbi_loadf = downcall("stbi_loadf", PPPPIp), + stbi_loadf_from_callbacks = downcall("stbi_loadf_from_callbacks", PPPPPIp), + stbi_loadf_from_file = downcall("stbi_loadf_from_file", PPPPIp), + stbi_loadf_from_memory = downcall("stbi_loadf_from_memory", PIPPPIp), + stbi_set_flip_vertically_on_load = downcall("stbi_set_flip_vertically_on_load", IV), + stbi_set_flip_vertically_on_load_thread = downcall("stbi_set_flip_vertically_on_load_thread", IV), + stbi_set_unpremultiply_on_load = downcall("stbi_set_unpremultiply_on_load", IV), + stbi_set_unpremultiply_on_load_thread = downcall("stbi_set_unpremultiply_on_load_thread", IV), + stbi_zlib_decode_buffer = downcall("stbi_zlib_decode_buffer", PIPII), + stbi_zlib_decode_malloc = downcall("stbi_zlib_decode_malloc", PIPp), + stbi_zlib_decode_malloc_guesssize = downcall("stbi_zlib_decode_malloc_guesssize", PIIPp), + stbi_zlib_decode_malloc_guesssize_headerflag = downcall("stbi_zlib_decode_malloc_guesssize_headerflag", PIIPIp), + stbi_zlib_decode_noheader_buffer = downcall("stbi_zlib_decode_noheader_buffer", PIPII), + stbi_zlib_decode_noheader_malloc = downcall("stbi_zlib_decode_noheader_malloc", PIPp); // only used for desiredChannels /** @@ -59,57 +92,6 @@ public final class STBImage { RGB = 3, RGB_ALPHA = 4; - static { - initialize(); - create(); - } - - private static void create() { - stbi_convert_iphone_png_to_rgb = downcall("stbi_convert_iphone_png_to_rgb", IV); - stbi_convert_iphone_png_to_rgb_thread = downcall("stbi_convert_iphone_png_to_rgb_thread", IV); - stbi_failure_reason = downcall("stbi_failure_reason", p); - stbi_hdr_to_ldr_gamma = downcall("stbi_hdr_to_ldr_gamma", FV); - stbi_hdr_to_ldr_scale = downcall("stbi_hdr_to_ldr_scale", FV); - stbi_image_free = downcall("stbi_image_free", PV); - stbi_info = downcall("stbi_info", PPPPI); - stbi_info_from_callbacks = downcall("stbi_info_from_callbacks", PPPPPI); - stbi_info_from_file = downcall("stbi_info_from_file", PPPPI); - stbi_info_from_memory = downcall("stbi_info_from_memory", PIPPPI); - stbi_is_16_bit = downcall("stbi_is_16_bit", fd_PI); - stbi_is_16_bit_from_callbacks = downcall("stbi_is_16_bit_from_callbacks", PPI); - stbi_is_16_bit_from_file = downcall("stbi_is_16_bit_from_file", fd_PI); - stbi_is_16_bit_from_memory = downcall("stbi_is_16_bit_from_memory", PII); - stbi_is_hdr = downcall("stbi_is_hdr", fd_PI); - stbi_is_hdr_from_callbacks = downcall("stbi_is_hdr_from_callbacks", PPI); - stbi_is_hdr_from_file = downcall("stbi_is_hdr_from_file", fd_PI); - stbi_is_hdr_from_memory = downcall("stbi_is_hdr_from_memory", PII); - stbi_ldr_to_hdr_gamma = downcall("stbi_ldr_to_hdr_gamma", FV); - stbi_ldr_to_hdr_scale = downcall("stbi_ldr_to_hdr_scale", FV); - stbi_load = downcall("stbi_load", PPPPIp); - stbi_load_16 = downcall("stbi_load_16", PPPPIp); - stbi_load_16_from_callbacks = downcall("stbi_load_16_from_callbacks", PPPPPIp); - stbi_load_16_from_memory = downcall("stbi_load_16_from_memory", PIPPPIp); - stbi_load_from_callbacks = downcall("stbi_load_from_callbacks", PPPPPIp); - stbi_load_from_file = downcall("stbi_load_from_file", PPPPIp); - stbi_load_from_file_16 = downcall("stbi_load_from_file_16", PPPPIp); - stbi_load_from_memory = downcall("stbi_load_from_memory", PIPPPIp); - stbi_load_gif_from_memory = downcall("stbi_load_gif_from_memory", PIPPPPPIp); - stbi_loadf = downcall("stbi_loadf", PPPPIp); - stbi_loadf_from_callbacks = downcall("stbi_loadf_from_callbacks", PPPPPIp); - stbi_loadf_from_file = downcall("stbi_loadf_from_file", PPPPIp); - stbi_loadf_from_memory = downcall("stbi_loadf_from_memory", PIPPPIp); - stbi_set_flip_vertically_on_load = downcall("stbi_set_flip_vertically_on_load", IV); - stbi_set_flip_vertically_on_load_thread = downcall("stbi_set_flip_vertically_on_load_thread", IV); - stbi_set_unpremultiply_on_load = downcall("stbi_set_unpremultiply_on_load", IV); - stbi_set_unpremultiply_on_load_thread = downcall("stbi_set_unpremultiply_on_load_thread", IV); - stbi_zlib_decode_buffer = downcall("stbi_zlib_decode_buffer", PIPII); - stbi_zlib_decode_malloc = downcall("stbi_zlib_decode_malloc", PIPp); - stbi_zlib_decode_malloc_guesssize = downcall("stbi_zlib_decode_malloc_guesssize", PIIPp); - stbi_zlib_decode_malloc_guesssize_headerflag = downcall("stbi_zlib_decode_malloc_guesssize_headerflag", PIIPIp); - stbi_zlib_decode_noheader_buffer = downcall("stbi_zlib_decode_noheader_buffer", PIPII); - stbi_zlib_decode_noheader_malloc = downcall("stbi_zlib_decode_noheader_malloc", PIPp); - } - private STBImage() { throw new IllegalStateException("Do not construct instance"); } diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBImageResize.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBImageResize.java index 07dd65a2..de1a6782 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBImageResize.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBImageResize.java @@ -25,7 +25,6 @@ import static java.lang.foreign.ValueLayout.*; import static overrungl.FunctionDescriptors.*; import static overrungl.stb.Handles.downcall; -import static overrungl.stb.Handles.initialize; /** * The STB image resizer. @@ -34,28 +33,17 @@ * @since 0.1.0 */ public final class STBImageResize { - private static MethodHandle - stbir_resize, stbir_resize_float, stbir_resize_float_generic, stbir_resize_region, stbir_resize_subpixel, - stbir_resize_uint16_generic, stbir_resize_uint8, stbir_resize_uint8_generic, stbir_resize_uint8_srgb, - stbir_resize_uint8_srgb_edgemode; - - static { - initialize(); - create(); - } - - private static void create() { - stbir_resize = downcall("stbir_resize", PIIIPIIIIIIIIIIIIPI); - stbir_resize_float = downcall("stbir_resize_float", PIIIPIIIII); - stbir_resize_float_generic = downcall("stbir_resize_float_generic", PIIIPIIIIIIIIIPI); - stbir_resize_region = downcall("stbir_resize_region", PIIIPIIIIIIIIIIIIPFFFFI); - stbir_resize_subpixel = downcall("stbir_resize_subpixel", PIIIPIIIIIIIIIIIIPFFFFI); - stbir_resize_uint16_generic = downcall("stbir_resize_uint16_generic", PIIIPIIIIIIIIIPI); - stbir_resize_uint8 = downcall("stbir_resize_uint8", PIIIPIIIII); - stbir_resize_uint8_generic = downcall("stbir_resize_uint8_generic", PIIIPIIIIIIIIIPI); - stbir_resize_uint8_srgb = downcall("stbir_resize_uint8_srgb", PIIIPIIIIIII); + private static final MethodHandle + stbir_resize = downcall("stbir_resize", PIIIPIIIIIIIIIIIIPI), + stbir_resize_float = downcall("stbir_resize_float", PIIIPIIIII), + stbir_resize_float_generic = downcall("stbir_resize_float_generic", PIIIPIIIIIIIIIPI), + stbir_resize_region = downcall("stbir_resize_region", PIIIPIIIIIIIIIIIIPFFFFI), + stbir_resize_subpixel = downcall("stbir_resize_subpixel", PIIIPIIIIIIIIIIIIPFFFFI), + stbir_resize_uint16_generic = downcall("stbir_resize_uint16_generic", PIIIPIIIIIIIIIPI), + stbir_resize_uint8 = downcall("stbir_resize_uint8", PIIIPIIIII), + stbir_resize_uint8_generic = downcall("stbir_resize_uint8_generic", PIIIPIIIIIIIIIPI), + stbir_resize_uint8_srgb = downcall("stbir_resize_uint8_srgb", PIIIPIIIIIII), stbir_resize_uint8_srgb_edgemode = downcall("stbir_resize_uint8_srgb_edgemode", PIIIPIIIIIIII); - } private STBImageResize() { throw new IllegalStateException("Do not construct instance"); diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBImageWrite.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBImageWrite.java index 7cbc8401..10e45017 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBImageWrite.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBImageWrite.java @@ -35,39 +35,26 @@ * @since 0.1.0 */ public final class STBImageWrite { - private static MethodHandle - stbi_flip_vertically_on_write, stbi_get_write_force_png_filter, stbi_get_write_png_compression_level, - stbi_get_write_tga_with_rle, stbi_set_write_force_png_filter, stbi_set_write_png_compression_level, - stbi_set_write_tga_with_rle, stbi_write_bmp, stbi_write_bmp_to_func, stbi_write_hdr, stbi_write_hdr_to_func, - stbi_write_jpg, stbi_write_jpg_to_func, stbi_write_png, stbi_write_png_to_func, stbi_write_png_to_mem, - stbi_write_tga, stbi_write_tga_to_func, stbi_zlib_compress; - - static { - initialize(); - create(); - } - - private static void create() { - stbi_flip_vertically_on_write = downcall("stbi_flip_vertically_on_write", IV); - stbi_get_write_force_png_filter = downcall("stbi_get_write_force_png_filter", I); - stbi_get_write_png_compression_level = downcall("stbi_get_write_png_compression_level", I); - stbi_get_write_tga_with_rle = downcall("stbi_get_write_tga_with_rle", I); - stbi_set_write_force_png_filter = downcall("stbi_set_write_force_png_filter", IV); - stbi_set_write_png_compression_level = downcall("stbi_set_write_png_compression_level", IV); - stbi_set_write_tga_with_rle = downcall("stbi_set_write_tga_with_rle", IV); - stbi_write_bmp = downcall("stbi_write_bmp", PIIIPI); - stbi_write_bmp_to_func = downcall("stbi_write_bmp_to_func", PPIIIP); - stbi_write_hdr = downcall("stbi_write_hdr", PIIIPI); - stbi_write_hdr_to_func = downcall("stbi_write_hdr_to_func", PPIIIP); - stbi_write_jpg = downcall("stbi_write_jpg", PIIIPII); - stbi_write_jpg_to_func = downcall("stbi_write_jpg_to_func", PPIIIPI); - stbi_write_png = downcall("stbi_write_png", PIIIPII); - stbi_write_png_to_func = downcall("stbi_write_png_to_func", PPIIIPI); - stbi_write_png_to_mem = downcall("stbi_write_png_to_mem", PIIIIPp); - stbi_write_tga = downcall("stbi_write_tga", PIIIP); - stbi_write_tga_to_func = downcall("stbi_write_tga_to_func", PPIIIP); + private static final MethodHandle + stbi_flip_vertically_on_write = downcall("stbi_flip_vertically_on_write", IV), + stbi_get_write_force_png_filter = downcall("stbi_get_write_force_png_filter", I), + stbi_get_write_png_compression_level = downcall("stbi_get_write_png_compression_level", I), + stbi_get_write_tga_with_rle = downcall("stbi_get_write_tga_with_rle", I), + stbi_set_write_force_png_filter = downcall("stbi_set_write_force_png_filter", IV), + stbi_set_write_png_compression_level = downcall("stbi_set_write_png_compression_level", IV), + stbi_set_write_tga_with_rle = downcall("stbi_set_write_tga_with_rle", IV), + stbi_write_bmp = downcall("stbi_write_bmp", PIIIPI), + stbi_write_bmp_to_func = downcall("stbi_write_bmp_to_func", PPIIIP), + stbi_write_hdr = downcall("stbi_write_hdr", PIIIPI), + stbi_write_hdr_to_func = downcall("stbi_write_hdr_to_func", PPIIIP), + stbi_write_jpg = downcall("stbi_write_jpg", PIIIPII), + stbi_write_jpg_to_func = downcall("stbi_write_jpg_to_func", PPIIIPI), + stbi_write_png = downcall("stbi_write_png", PIIIPII), + stbi_write_png_to_func = downcall("stbi_write_png_to_func", PPIIIPI), + stbi_write_png_to_mem = downcall("stbi_write_png_to_mem", PIIIIPp), + stbi_write_tga = downcall("stbi_write_tga", PIIIP), + stbi_write_tga_to_func = downcall("stbi_write_tga_to_func", PPIIIP), stbi_zlib_compress = downcall("stbi_zlib_compress", PIPIp); - } private STBImageWrite() { throw new IllegalStateException("Do not construct instance"); diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBPerlin.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBPerlin.java index fb55e72e..2ddb9e66 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBPerlin.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBPerlin.java @@ -28,22 +28,13 @@ * @since 0.1.0 */ public final class STBPerlin { - private static MethodHandle - stb_perlin_noise3, stb_perlin_noise3_seed, stb_perlin_ridge_noise3, stb_perlin_fbm_noise3, stb_perlin_turbulence_noise3, stb_perlin_noise3_wrap_nonpow2; - - static { - initialize(); - create(); - } - - private static void create() { - stb_perlin_noise3 = downcall("stb_perlin_noise3", FFFIIIF); - stb_perlin_noise3_seed = downcall("stb_perlin_noise3_seed", FFFIIIIF); - stb_perlin_ridge_noise3 = downcall("stb_perlin_ridge_noise3", FFFFFFIF); - stb_perlin_fbm_noise3 = downcall("stb_perlin_fbm_noise3", FFFFFIF); - stb_perlin_turbulence_noise3 = downcall("stb_perlin_turbulence_noise3", FFFFFIF); + private static final MethodHandle + stb_perlin_noise3 = downcall("stb_perlin_noise3", FFFIIIF), + stb_perlin_noise3_seed = downcall("stb_perlin_noise3_seed", FFFIIIIF), + stb_perlin_ridge_noise3 = downcall("stb_perlin_ridge_noise3", FFFFFFIF), + stb_perlin_fbm_noise3 = downcall("stb_perlin_fbm_noise3", FFFFFIF), + stb_perlin_turbulence_noise3 = downcall("stb_perlin_turbulence_noise3", FFFFFIF), stb_perlin_noise3_wrap_nonpow2 = downcall("stb_perlin_noise3_wrap_nonpow2", FFFIIIBF); - } private STBPerlin() { throw new IllegalStateException("Do not construct instance");