diff --git a/build.xml b/build.xml index 691b636b9b..beed44f1fb 100644 --- a/build.xml +++ b/build.xml @@ -129,7 +129,7 @@ License terms: http://lwjgl.org/license.php - + @@ -179,7 +179,7 @@ License terms: http://lwjgl.org/license.php - + @@ -188,12 +188,12 @@ License terms: http://lwjgl.org/license.php - - + + - + @@ -247,7 +247,7 @@ License terms: http://lwjgl.org/license.php - + @@ -277,7 +277,7 @@ License terms: http://lwjgl.org/license.php - + @@ -287,8 +287,8 @@ License terms: http://lwjgl.org/license.php - - + + @@ -406,18 +406,19 @@ License terms: http://lwjgl.org/license.php - + - + + - + @@ -475,24 +476,15 @@ License terms: http://lwjgl.org/license.php - + - - - - - - - - - - - + + @@ -551,97 +543,507 @@ License terms: http://lwjgl.org/license.php - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
-
-
- - - - - - - - - - + + + + + + + + + + + + + + - - - - - + + + + + + + - - + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+
+ + + + + +
+ + + + + LWJGL - @{title}]]> + Copyright LWJGL. All Rights Reserved. License terms.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + - LWJGL ${build.version} build ${build.revision} + + LWJGL @{title} ${build.version} ${revision} + LWJGL @{title} ${build.version} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config/build-assets.xml b/config/build-assets.xml index 436a4e1cb5..5264108ed4 100644 --- a/config/build-assets.xml +++ b/config/build-assets.xml @@ -8,7 +8,7 @@ This script downloads such assets from S3. This script is included in /build.xml and depends on /build-definitions.xml --> - + diff --git a/config/build-bindings.xml b/config/build-bindings.xml index 03a3f28065..2ae4dce71e 100644 --- a/config/build-bindings.xml +++ b/config/build-bindings.xml @@ -13,6 +13,7 @@ This script is included in /config/build-definitions.xml. + @@ -22,8 +23,10 @@ This script is included in /config/build-definitions.xml. + + diff --git a/config/windows/build.xml b/config/windows/build.xml index 88aaced691..9cbdf96bfe 100644 --- a/config/windows/build.xml +++ b/config/windows/build.xml @@ -5,22 +5,21 @@ License terms: http://lwjgl.org/license.php - + - - - - - - - - + + + + + - - - + + + + + @@ -28,191 +27,214 @@ License terms: http://lwjgl.org/license.php - + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + - - - - - + + + - + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - + + + + + + + + + + + + + - - - - - - - - - - - + + - - + + + + - - + + - - + + + + + + + - - - - - + + - - - - - - - - - + + + + - - + + + + + + + + + + - - + + + + - - - - - - - - - + + - - - - - + + + + + + + + + + - - + - - + - - - - - - - - - - - - - ${objects} - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/modules/core/src/main/c/system/common_tools.c b/modules/core/src/main/c/system/common_tools.c index 6b09db17c0..539ce79508 100644 --- a/modules/core/src/main/c/system/common_tools.c +++ b/modules/core/src/main/c/system/common_tools.c @@ -11,27 +11,6 @@ JavaVM *jvm; -mallocPROC lwjgl_malloc = malloc; -callocPROC lwjgl_calloc = calloc; -reallocPROC lwjgl_realloc = realloc; -freePROC lwjgl_free = free; - -#ifdef LWJGL_WINDOWS - aligned_allocPROC lwjgl_aligned_alloc = _aligned_malloc; - aligned_freePROC lwjgl_aligned_free = _aligned_free; -#else - #ifndef __USE_ISOC11 - static void* aligned_alloc(size_t alignment, size_t size) { - void *p; - if ( !posix_memalign(&p, alignment, size) ) - return p; - return NULL; - } - #endif - aligned_allocPROC lwjgl_aligned_alloc = aligned_alloc; - aligned_freePROC lwjgl_aligned_free = free; -#endif - inline JNIEnv *getThreadEnv(void) { JNIEnv *env; (*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_6); diff --git a/modules/core/src/main/c/system/lwjgl_malloc.c b/modules/core/src/main/c/system/lwjgl_malloc.c new file mode 100644 index 0000000000..09b79cac4e --- /dev/null +++ b/modules/core/src/main/c/system/lwjgl_malloc.c @@ -0,0 +1,38 @@ +/* + * Copyright LWJGL. All rights reserved. + * License terms: http://lwjgl.org/license.php + */ +#include "common_tools.h" +#include "lwjgl_malloc.h" + +// Overridable memory management functions + +mallocPROC lwjgl_malloc; +callocPROC lwjgl_calloc; +reallocPROC lwjgl_realloc; +freePROC lwjgl_free; + +aligned_allocPROC lwjgl_aligned_alloc; +aligned_freePROC lwjgl_aligned_free; + +EXTERN_C_ENTER + +JNIEXPORT void lwjgl_setup_malloc( + mallocPROC malloc, + callocPROC calloc, + reallocPROC realloc, + freePROC free, + + aligned_allocPROC aligned_alloc, + aligned_freePROC aligned_free +) { + lwjgl_malloc = malloc; + lwjgl_calloc = calloc; + lwjgl_realloc = realloc; + lwjgl_free = free; + + lwjgl_aligned_alloc = aligned_alloc; + lwjgl_aligned_free = aligned_free; +} + +EXTERN_C_EXIT diff --git a/modules/core/src/main/c/system/org_lwjgl_system_MemoryAccess.c b/modules/core/src/main/c/system/org_lwjgl_system_MemoryAccess.c index b439160e16..d1c1408ebb 100644 --- a/modules/core/src/main/c/system/org_lwjgl_system_MemoryAccess.c +++ b/modules/core/src/main/c/system/org_lwjgl_system_MemoryAccess.c @@ -4,51 +4,69 @@ */ #include "common_tools.h" DISABLE_WARNINGS() +#include #include ENABLE_WARNINGS() EXTERN_C_ENTER +#if !(defined(LWJGL_WINDOWS) || defined(__USE_ISOC11)) + static void* aligned_alloc(size_t alignment, size_t size) { + void *p; + if ( !posix_memalign(&p, alignment, size) ) + return p; + return NULL; + } +#endif + // malloc()J JNIEXPORT jlong JNICALL Java_org_lwjgl_system_MemoryAccess_malloc(JNIEnv *env, jclass clazz) { UNUSED_PARAMS(env, clazz) - return (jlong)(intptr_t)&lwjgl_malloc; + return (jlong)(intptr_t)&malloc; } // calloc()J JNIEXPORT jlong JNICALL Java_org_lwjgl_system_MemoryAccess_calloc(JNIEnv *env, jclass clazz) { UNUSED_PARAMS(env, clazz) - return (jlong)(intptr_t)&lwjgl_calloc; + return (jlong)(intptr_t)&calloc; } // realloc()J JNIEXPORT jlong JNICALL Java_org_lwjgl_system_MemoryAccess_realloc(JNIEnv *env, jclass clazz) { UNUSED_PARAMS(env, clazz) - return (jlong)(intptr_t)&lwjgl_realloc; + return (jlong)(intptr_t)&realloc; } // free()J JNIEXPORT jlong JNICALL Java_org_lwjgl_system_MemoryAccess_free(JNIEnv *env, jclass clazz) { UNUSED_PARAMS(env, clazz) - return (jlong)(intptr_t)&lwjgl_free; + return (jlong)(intptr_t)&free; } // aligned_alloc()J JNIEXPORT jlong JNICALL Java_org_lwjgl_system_MemoryAccess_aligned_1alloc(JNIEnv *env, jclass clazz) { UNUSED_PARAMS(env, clazz) - return (jlong)(intptr_t)&lwjgl_aligned_alloc; +#ifdef LWJGL_WINDOWS + return (jlong)(intptr_t)&_aligned_malloc; +#else + return (jlong)(intptr_t)&aligned_alloc; +#endif } // aligned_free()J JNIEXPORT jlong JNICALL Java_org_lwjgl_system_MemoryAccess_aligned_1free(JNIEnv *env, jclass clazz) { UNUSED_PARAMS(env, clazz) - return (jlong)(intptr_t)&lwjgl_aligned_free; +#ifdef LWJGL_WINDOWS + return (jlong)(intptr_t)&_aligned_free; +#else + return (jlong)(intptr_t)&free; +#endif } // memset(JIJ)V diff --git a/modules/core/src/main/include/nanovg/fontstash.h b/modules/core/src/main/include/nanovg/fontstash.h index 7349bb89d1..f032459488 100644 --- a/modules/core/src/main/include/nanovg/fontstash.h +++ b/modules/core/src/main/include/nanovg/fontstash.h @@ -238,7 +238,6 @@ int fons__tt_getGlyphKernAdvance(FONSttFontImpl *font, int glyph1, int glyph2) #else -//#define STB_TRUETYPE_IMPLEMENTATION //static void* fons__tmpalloc(size_t size, void* up); //static void fons__tmpfree(void* ptr, void* up); //#define STBTT_malloc(x,u) fons__tmpalloc(x,u) diff --git a/modules/core/src/main/include/nanovg/nanovg.c b/modules/core/src/main/include/nanovg/nanovg.c index b750eb2fb7..457b02de72 100644 --- a/modules/core/src/main/include/nanovg/nanovg.c +++ b/modules/core/src/main/include/nanovg/nanovg.c @@ -24,7 +24,6 @@ #include "nanovg.h" #define FONTSTASH_IMPLEMENTATION #include "fontstash.h" -//#define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" #ifdef _MSC_VER diff --git a/modules/core/src/main/include/system/common_tools.h b/modules/core/src/main/include/system/common_tools.h index c0a2614ef2..a9b3f885f9 100644 --- a/modules/core/src/main/include/system/common_tools.h +++ b/modules/core/src/main/include/system/common_tools.h @@ -45,24 +45,6 @@ extern void detachCurrentThread(void); // ----------------------------------------------------- -// Overridable memory management functions - -typedef void* (*mallocPROC) (size_t); -typedef void* (*callocPROC) (size_t num, size_t size); -typedef void* (*reallocPROC) (void *ptr, size_t size); -typedef void (*freePROC) (void *ptr); -typedef void* (*aligned_allocPROC) (size_t alignment, size_t size); -typedef void (*aligned_freePROC) (void *ptr); - -extern mallocPROC lwjgl_malloc; -extern callocPROC lwjgl_calloc; -extern reallocPROC lwjgl_realloc; -extern freePROC lwjgl_free; -extern aligned_allocPROC lwjgl_aligned_alloc; -extern aligned_freePROC lwjgl_aligned_free; - -// ----------------------------------------------------- - #ifdef __cplusplus #define EXTERN_C_ENTER extern "C" { #define EXTERN_C_EXIT } diff --git a/modules/core/src/main/include/system/lwjgl_malloc.h b/modules/core/src/main/include/system/lwjgl_malloc.h new file mode 100644 index 0000000000..fdd610fc8e --- /dev/null +++ b/modules/core/src/main/include/system/lwjgl_malloc.h @@ -0,0 +1,25 @@ +/* + * Copyright LWJGL. All rights reserved. + * License terms: http://lwjgl.org/license.php + */ +#ifndef __LWJGL_MALLOC_H__ +#define __LWJGL_MALLOC_H__ + +// Overridable memory management functions + +typedef void* (*mallocPROC) (size_t); +typedef void* (*callocPROC) (size_t num, size_t size); +typedef void* (*reallocPROC) (void *ptr, size_t size); +typedef void (*freePROC) (void *ptr); +typedef void* (*aligned_allocPROC) (size_t alignment, size_t size); +typedef void (*aligned_freePROC) (void *ptr); + +extern mallocPROC lwjgl_malloc; +extern callocPROC lwjgl_calloc; +extern reallocPROC lwjgl_realloc; +extern freePROC lwjgl_free; + +extern aligned_allocPROC lwjgl_aligned_alloc; +extern aligned_freePROC lwjgl_aligned_free; + +#endif diff --git a/modules/core/src/main/include/util/nfd/nfd_common.c b/modules/core/src/main/include/util/nfd/nfd_common.c index a80a109277..94b34e4d4b 100644 --- a/modules/core/src/main/include/util/nfd/nfd_common.c +++ b/modules/core/src/main/include/util/nfd/nfd_common.c @@ -8,7 +8,7 @@ #include #include #include "nfd_common.h" -#include "common_tools.h" +#include "lwjgl_malloc.h" static char g_errorstr[NFD_MAX_STRLEN] = {0}; diff --git a/modules/core/src/main/java/org/lwjgl/system/MemoryManage.java b/modules/core/src/main/java/org/lwjgl/system/MemoryManage.java index 992c1b6aff..d8969f3828 100644 --- a/modules/core/src/main/java/org/lwjgl/system/MemoryManage.java +++ b/modules/core/src/main/java/org/lwjgl/system/MemoryManage.java @@ -4,8 +4,6 @@ */ package org.lwjgl.system; -import org.lwjgl.system.jemalloc.JEmalloc; - import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -16,7 +14,6 @@ import static org.lwjgl.system.APIUtil.*; import static org.lwjgl.system.MemoryUtil.*; -import static org.lwjgl.system.jemalloc.JEmalloc.*; import static org.lwjgl.system.libc.Stdlib.*; /** Provides {@link MemoryAllocator} implementations for {@link MemoryUtil} to use. */ @@ -33,8 +30,8 @@ static MemoryAllocator getInstance() { if ( "jemalloc".equals(allocator) ) { try { // check if the jemalloc library is available - Class.forName("org.lwjgl.system.jemalloc.JEmalloc").getMethod("getLibrary").invoke(null); - return new JEmallocAllocator(); + Class JEmallocAllocator = Class.forName("org.lwjgl.system.jemalloc.JEmallocAllocator"); + return (MemoryAllocator)JEmallocAllocator.newInstance(); } catch (Throwable t) { if ( Checks.DEBUG ) t.printStackTrace(DEBUG_STREAM); @@ -56,84 +53,51 @@ static MemoryAllocator getInstance() { private static class StdlibAllocator implements MemoryAllocator { @Override - public void config(long malloc, long calloc, long realloc, long free, long aligned_alloc, long aligned_free) { - // stdlib functions are the default - } + public long getMalloc() { return MemoryAccess.malloc(); } @Override - public long malloc(long size) { - return nmalloc(size); - } + public long getCalloc() { return MemoryAccess.calloc(); } @Override - public long calloc(long num, long size) { - return ncalloc(num, size); - } + public long getRealloc() { return MemoryAccess.realloc(); } @Override - public long realloc(long ptr, long size) { - return nrealloc(ptr, size); - } + public long getFree() { return MemoryAccess.free(); } @Override - public void free(long ptr) { - nfree(ptr); - } - - @Override - public long aligned_alloc(long alignment, long size) { - return naligned_alloc(alignment, size); - } + public long getAlignedAlloc() { return MemoryAccess.aligned_alloc(); } @Override - public void aligned_free(long ptr) { - naligned_free(ptr); - } - - } - - /** jemalloc memory allocator. */ - private static class JEmallocAllocator implements MemoryAllocator { - - @Override - public void config(long malloc, long calloc, long realloc, long free, long aligned_alloc, long aligned_free) { - memPutAddress(malloc, JEmalloc.Functions.malloc); - memPutAddress(calloc, JEmalloc.Functions.calloc); - memPutAddress(realloc, JEmalloc.Functions.realloc); - memPutAddress(free, JEmalloc.Functions.free); - - memPutAddress(aligned_alloc, JEmalloc.Functions.aligned_alloc); - memPutAddress(aligned_free, JEmalloc.Functions.free); - } + public long getAlignedFree() { return MemoryAccess.aligned_free(); } @Override public long malloc(long size) { - return nje_malloc(size); + return nmalloc(size); } @Override public long calloc(long num, long size) { - return nje_calloc(num, size); + return ncalloc(num, size); } @Override public long realloc(long ptr, long size) { - return nje_realloc(ptr, size); + return nrealloc(ptr, size); } @Override public void free(long ptr) { - nje_free(ptr); + nfree(ptr); } @Override public long aligned_alloc(long alignment, long size) { - return nje_aligned_alloc(alignment, size); + return naligned_alloc(alignment, size); } @Override public void aligned_free(long ptr) { - nje_free(ptr); + naligned_free(ptr); } } @@ -175,6 +139,24 @@ public void run() { }); } + @Override + public long getMalloc() { return allocator.getMalloc(); } + + @Override + public long getCalloc() { return allocator.getCalloc(); } + + @Override + public long getRealloc() { return allocator.getRealloc(); } + + @Override + public long getFree() { return allocator.getFree(); } + + @Override + public long getAlignedAlloc() { return allocator.getAlignedAlloc(); } + + @Override + public long getAlignedFree() { return allocator.getAlignedFree(); } + @Override public long malloc(long size) { return track(allocator.malloc(size), size); @@ -210,11 +192,6 @@ public void aligned_free(long ptr) { untrack(ptr); } - @Override - public void config(long malloc, long calloc, long realloc, long free, long aligned_alloc, long aligned_free) { - allocator.config(malloc, calloc, realloc, free, aligned_alloc, aligned_free); - } - static long track(long address, long size) { if ( address != NULL ) { Thread t = Thread.currentThread(); diff --git a/modules/core/src/main/java/org/lwjgl/system/MemoryUtil.java b/modules/core/src/main/java/org/lwjgl/system/MemoryUtil.java index 19fb84ac73..ce8d4d191a 100644 --- a/modules/core/src/main/java/org/lwjgl/system/MemoryUtil.java +++ b/modules/core/src/main/java/org/lwjgl/system/MemoryUtil.java @@ -15,6 +15,7 @@ import static org.lwjgl.system.APIUtil.*; import static org.lwjgl.system.MemoryUtil.LazyInit.*; import static org.lwjgl.system.Pointer.*; +import static org.lwjgl.system.dyncall.DynCall.*; /** * This class provides functionality for managing native memory. @@ -78,16 +79,6 @@ private LazyInit() { ? new DebugAllocator(ALLOCATOR_IMPL) : ALLOCATOR_IMPL; - ALLOCATOR.config( - MemoryAccess.malloc(), - MemoryAccess.calloc(), - MemoryAccess.realloc(), - MemoryAccess.free(), - - MemoryAccess.aligned_alloc(), - MemoryAccess.aligned_free() - ); - apiLog("MemoryUtil allocator: " + ALLOCATOR.getClass().getSimpleName()); } } @@ -104,25 +95,18 @@ private MemoryUtil() { /** The interface implemented by the memory allocator used by the explicit memory management API ({@link #memAlloc}, {@link #memFree}, etc). */ public interface MemoryAllocator { - /** - * The memory allocator may override the default explicit memory management functions used internally by LWJGL bindings. - * - * @param malloc a pointer to the malloc function - * @param calloc a pointer to the calloc function - * @param realloc a pointer to the realloc function - * @param free a pointer to the free function - * @param aligned_alloc a pointer to the aligned_alloc function - * @param aligned_free a pointer to the aligned_free function - */ - void config( - long malloc, - long calloc, - long realloc, - long free, - - long aligned_alloc, - long aligned_free - ); + /** Returns a pointer to the malloc function. */ + long getMalloc(); + /** Returns a pointer to the calloc function. */ + long getCalloc(); + /** Returns a pointer to the realloc function. */ + long getRealloc(); + /** Returns a pointer to the free function. */ + long getFree(); + /** Returns a pointer to the aligned_alloc function. */ + long getAlignedAlloc(); + /** Returns a pointer to the aligned_free function. */ + long getAlignedFree(); /** Called by {@link MemoryUtil#memAlloc}. */ long malloc(long size); @@ -155,6 +139,31 @@ public static MemoryAllocator getAllocator() { return ALLOCATOR_IMPL; } + public static void setupAllocator(String libraryName) { + MemoryAllocator allocator = getAllocator(); + + long vm = dcNewCallVM(1024); + try ( SharedLibrary library = Library.loadNative(libraryName) ) { + long lwjgl_setup_malloc = library.getFunctionAddress("lwjgl_setup_malloc"); + + dcMode(vm, DC_CALL_C_DEFAULT); + { + dcReset(vm); + + dcArgPointer(vm, allocator.getMalloc()); + dcArgPointer(vm, allocator.getCalloc()); + dcArgPointer(vm, allocator.getRealloc()); + dcArgPointer(vm, allocator.getFree()); + dcArgPointer(vm, allocator.getAlignedAlloc()); + dcArgPointer(vm, allocator.getAlignedFree()); + + dcCallVoid(vm, lwjgl_setup_malloc); + } + } finally { + dcFree(vm); + } + } + // --- [ memAlloc ] --- /** Unsafe version of {@link #memAlloc}. */ diff --git a/modules/generator/src/main/kotlin/org/lwjgl/generator/Functions.kt b/modules/generator/src/main/kotlin/org/lwjgl/generator/Functions.kt index aa53279fb5..584327bb34 100644 --- a/modules/generator/src/main/kotlin/org/lwjgl/generator/Functions.kt +++ b/modules/generator/src/main/kotlin/org/lwjgl/generator/Functions.kt @@ -1493,7 +1493,11 @@ class NativeClassFunction( // Unused parameter macro if ( !critical ) - println("\tUNUSED_PARAMS($JNIENV, clazz)") + println(if ( parameters.contains(JNI_ENV) ) + "\tUNUSED_PARAM(clazz)" + else + "\tUNUSED_PARAMS($JNIENV, clazz)" + ) else getParams { it.nativeType is ArrayType }.forEach { println("\tUNUSED_PARAM(${it.name}__length)") diff --git a/modules/generator/src/main/kotlin/org/lwjgl/generator/Generator.kt b/modules/generator/src/main/kotlin/org/lwjgl/generator/Generator.kt index 7c17ac907d..1a51307e5f 100644 --- a/modules/generator/src/main/kotlin/org/lwjgl/generator/Generator.kt +++ b/modules/generator/src/main/kotlin/org/lwjgl/generator/Generator.kt @@ -38,6 +38,7 @@ enum class Binding(val key: String, val packageName: String) { EGL("binding.egl", "org.lwjgl.egl"), GLFW("binding.glfw", "org.lwjgl.glfw"), JAWT("binding.jawt", "org.lwjgl.system.jawt"), + JEMALLOC("binding.jemalloc", "org.lwjgl.system.jemalloc"), LMDB("binding.lmdb", "org.lwjgl.util.lmdb"), NANOVG("binding.nanovg", "org.lwjgl.nanovg"), NFD("binding.nfd", "org.lwjgl.util.nfd"), @@ -48,8 +49,10 @@ enum class Binding(val key: String, val packageName: String) { OPENGLES("binding.opengles", "org.lwjgl.opengles"), OVR("binding.ovr", "org.lwjgl.ovr"), PAR("binding.par", "org.lwjgl.util.par"), + SSE("binding.sse", "org.lwjgl.util.simd"), STB("binding.stb", "org.lwjgl.stb"), VULKAN("binding.vulkan", "org.lwjgl.vulkan"), + XXHASH("binding.xxhash", "org.lwjgl.util.xxhash"), MACOSX_OBJC("binding.macosx.objc", DUMMY_PACKAGE); @@ -191,6 +194,35 @@ class Generator( return customClass } + fun registerLibraryInit(packageName: String, className: String, libraryName: String, setupAllocator: Boolean = false) { + Generator.register(object : CustomClass(packageName, className) { + init { + access = Access.INTERNAL + documentation = "Initializes the $libraryName shared library." + javaImport("org.lwjgl.system.*") + } + + override fun PrintWriter.generateContent() { + println( + """${access.modifier}final class $className { + + static { + Library.loadSystem("lwjgl_$libraryName");${if ( setupAllocator ) """ + MemoryUtil.setupAllocator("lwjgl_$libraryName");""" else ""} + } + + private $className() { + } + + static void initialize() { + // intentionally empty to trigger static initializer + } + +}""") + } + }) + } + /** Registers state that will be added to `org.lwjgl.system.ThreadLocalState`. */ fun registerTLS(import: String, state: String) { tlsImport.add(import) @@ -198,8 +230,7 @@ class Generator( } init { - val CLASS = "ThreadLocalState" - Generator.register(object : GeneratorTarget("org.lwjgl.system", CLASS) { + Generator.register(object : GeneratorTarget("org.lwjgl.system", "ThreadLocalState") { override fun PrintWriter.generateJava() { print(HEADER) println("package $packageName;\n") @@ -211,7 +242,7 @@ class Generator( preamble.printJava(this) println("""/** Thread-local state used internally by LWJGL. */ -public final class $CLASS implements Runnable { +public final class $className implements Runnable { Runnable target; @@ -221,7 +252,7 @@ public final class $CLASS implements Runnable { println("\t$it") } println(""" - $CLASS() { + $className() { stack = MemoryStack.create(); } diff --git a/modules/generator/src/main/kotlin/org/lwjgl/generator/GeneratorTarget.kt b/modules/generator/src/main/kotlin/org/lwjgl/generator/GeneratorTarget.kt index cd0cc15439..7d2fe4bdc3 100644 --- a/modules/generator/src/main/kotlin/org/lwjgl/generator/GeneratorTarget.kt +++ b/modules/generator/src/main/kotlin/org/lwjgl/generator/GeneratorTarget.kt @@ -64,7 +64,7 @@ class Preamble { nativeDirectives.add(NativeDefine(expression, beforeIncludes)) } - internal fun printJava(writer: PrintWriter) { + fun printJava(writer: PrintWriter) { if ( javaImports.isEmpty() ) return @@ -162,7 +162,7 @@ abstract class GeneratorTarget( var documentation: String? = null - internal val preamble = Preamble() + val preamble = Preamble() fun T.javaImport(vararg classes: String): T { preamble.javaImport(*classes) diff --git a/modules/generator/src/main/kotlin/org/lwjgl/generator/JavaDoc.kt b/modules/generator/src/main/kotlin/org/lwjgl/generator/JavaDoc.kt index 0b7a35a4d8..0b8df1b167 100644 --- a/modules/generator/src/main/kotlin/org/lwjgl/generator/JavaDoc.kt +++ b/modules/generator/src/main/kotlin/org/lwjgl/generator/JavaDoc.kt @@ -128,7 +128,7 @@ private fun StringBuilder.appendParagraph(linePrefix: String, text: String, star append("

") } -internal fun String.toJavaDoc(indentation: String = "\t", allowSingleLine: Boolean = true): String { +fun String.toJavaDoc(indentation: String = "\t", allowSingleLine: Boolean = true): String { val clean = cleanup("$indentation * ") return if ( allowSingleLine && clean.indexOf('\n') == -1 ) diff --git a/modules/generator/src/main/kotlin/org/lwjgl/generator/NativeClass.kt b/modules/generator/src/main/kotlin/org/lwjgl/generator/NativeClass.kt index 464f6604d7..a0fe6f65a5 100644 --- a/modules/generator/src/main/kotlin/org/lwjgl/generator/NativeClass.kt +++ b/modules/generator/src/main/kotlin/org/lwjgl/generator/NativeClass.kt @@ -178,7 +178,8 @@ class NativeClass( val prefixConstant: String, val prefixTemplate: String, val postfix: String, - val binding: APIBinding? + val binding: APIBinding?, + val library: String? ) : GeneratorTargetNative(packageName, className, nativeSubPath) { companion object { private val JDOC_LINK_PATTERN = Pattern.compile("""(? Unit)? = null ): NativeClass { - val ext = NativeClass(packageName, this, nativeSubPath, templateName, prefix, prefixMethod, prefixConstant, prefixTemplate, postfix, binding) + val ext = NativeClass(packageName, this, nativeSubPath, templateName, prefix, prefixMethod, prefixConstant, prefixTemplate, postfix, binding, library) if ( init != null ) ext.init() diff --git a/modules/generator/src/main/kotlin/org/lwjgl/generator/Structs.kt b/modules/generator/src/main/kotlin/org/lwjgl/generator/Structs.kt index 48237f5829..ce0b6e6589 100644 --- a/modules/generator/src/main/kotlin/org/lwjgl/generator/Structs.kt +++ b/modules/generator/src/main/kotlin/org/lwjgl/generator/Structs.kt @@ -140,6 +140,11 @@ class Struct( usageResultPointer = true } + private var static: String? = null + fun static(expression: String) { + static = expression + } + private val members = ArrayList() private val visibleMembers: Sequence @@ -475,11 +480,17 @@ $indentation}""" println(";") } + print(""" + static {""") + if ( static != null ) + print(""" + $static +""") + // Member offset initialization if ( nativeLayout ) { print(""" - static { try ( MemoryStack stack = stackPush() ) { IntBuffer offsets = stack.mallocInt(${memberCount + 1}); SIZEOF = offsets(memAddress(offsets)); @@ -491,7 +502,6 @@ $indentation}""" }""") } else { print(""" - static { Layout layout = """) generateLayout(this@Struct) print("""; @@ -506,7 +516,12 @@ $indentation}""" print("\t}") } else { print(""" - static { + static {""") + if (static != null) + print(""" + $static +""") + print(""" try ( MemoryStack stack = stackPush() ) { IntBuffer offsets = stack.mallocInt(1); SIZEOF = offsets(memAddress(offsets)); diff --git a/modules/templates/src/main/kotlin/org/lwjgl/nanovg/NVGTypes.kt b/modules/templates/src/main/kotlin/org/lwjgl/nanovg/NVGTypes.kt index 66869de582..0aa0d103aa 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/nanovg/NVGTypes.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/nanovg/NVGTypes.kt @@ -7,6 +7,7 @@ package org.lwjgl.nanovg import org.lwjgl.generator.* val NANOVG_PACKAGE = "org.lwjgl.nanovg" +val NANOVG_LIBRARY = "LibNanoVG.initialize();" fun config() { packageInfo( @@ -16,6 +17,8 @@ fun config() { lean API modeled after HTML5 canvas API. It is aimed to be a practical and fun toolset for building scalable user interfaces and visualizations. """ ) + + Generator.registerLibraryInit(NANOVG_PACKAGE, "LibNanoVG", "nanovg", setupAllocator = true) } fun GeneratorTargetNative.includeNanoVGAPI(directives: String) = nativeDirective( diff --git a/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg.kt b/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg.kt index a07b453c26..d9c07e6c94 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg.kt @@ -7,7 +7,7 @@ package org.lwjgl.nanovg.templates import org.lwjgl.generator.* import org.lwjgl.nanovg.* -val nanovg = "NanoVG".nativeClass(packageName = NANOVG_PACKAGE, prefix = "NVG") { +val nanovg = "NanoVG".nativeClass(packageName = NANOVG_PACKAGE, prefix = "NVG", library = NANOVG_LIBRARY) { nativeDirective( """#ifdef LWJGL_WINDOWS #define _CRT_SECURE_NO_WARNINGS @@ -19,6 +19,19 @@ val nanovg = "NanoVG".nativeClass(packageName = NANOVG_PACKAGE, prefix = "NVG") #ifdef LWJGL_WINDOWS __pragma(warning(disable : 4711)) #endif +#include "lwjgl_malloc.h" +#define STBI_MALLOC(sz) lwjgl_malloc(sz) +#define STBI_REALLOC(p,sz) lwjgl_realloc(p,sz) +#define STBI_FREE(p) lwjgl_free(p) +#define STBI_FAILURE_USERMSG +#define STBI_ASSERT(x) +#define STB_IMAGE_IMPLEMENTATION +#define STB_IMAGE_STATIC +#define STBTT_malloc(x,u) ((void)(u),lwjgl_malloc(x)) +#define STBTT_free(x,u) ((void)(u),lwjgl_free(x)) +#define STBTT_assert +#define STB_TRUETYPE_IMPLEMENTATION +#define STBTT_STATIC #include "nanovg.c"""") documentation = diff --git a/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg_gl2.kt b/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg_gl2.kt index af2aff808e..a6744ac61d 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg_gl2.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg_gl2.kt @@ -9,7 +9,7 @@ import org.lwjgl.nanovg.* import org.lwjgl.opengl.GLuint val nanovg_gl2 = dependsOn(Binding.OPENGL) { - "NanoVGGL2".nativeClass(packageName = NANOVG_PACKAGE, prefix = "NVG") { + "NanoVGGL2".nativeClass(packageName = NANOVG_PACKAGE, prefix = "NVG", library = NANOVG_LIBRARY) { nativeDirective( """#ifdef LWJGL_WINDOWS __pragma(warning(disable : 4710 4711)) diff --git a/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg_gl3.kt b/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg_gl3.kt index abe0cb2b4a..2e0628db11 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg_gl3.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg_gl3.kt @@ -9,7 +9,7 @@ import org.lwjgl.nanovg.* import org.lwjgl.opengl.GLuint val nanovg_gl3 = dependsOn(Binding.OPENGL) { - "NanoVGGL3".nativeClass(packageName = NANOVG_PACKAGE, prefix = "NVG") { + "NanoVGGL3".nativeClass(packageName = NANOVG_PACKAGE, prefix = "NVG", library = NANOVG_LIBRARY) { nativeDirective( """#ifdef LWJGL_WINDOWS __pragma(warning(disable : 4710 4711)) diff --git a/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg_gles2.kt b/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg_gles2.kt index 1ea245ffc8..300486bc2e 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg_gles2.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg_gles2.kt @@ -9,7 +9,7 @@ import org.lwjgl.nanovg.* import org.lwjgl.opengl.GLuint val nanovg_gles2 = dependsOn(Binding.OPENGLES) { - "NanoVGGLES2".nativeClass(packageName = NANOVG_PACKAGE, prefix = "NVG") { + "NanoVGGLES2".nativeClass(packageName = NANOVG_PACKAGE, prefix = "NVG", library = NANOVG_LIBRARY) { nativeDirective( """#ifdef LWJGL_WINDOWS __pragma(warning(disable : 4710 4711)) diff --git a/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg_gles3.kt b/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg_gles3.kt index d2719e251e..f3a1b27017 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg_gles3.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/nanovg/templates/nanovg_gles3.kt @@ -9,7 +9,7 @@ import org.lwjgl.nanovg.* import org.lwjgl.opengl.GLuint val nanovg_gles3 = dependsOn(Binding.OPENGLES) { - "NanoVGGLES3".nativeClass(packageName = NANOVG_PACKAGE, prefix = "NVG") { + "NanoVGGLES3".nativeClass(packageName = NANOVG_PACKAGE, prefix = "NVG", library = NANOVG_LIBRARY) { nativeDirective( """#ifdef LWJGL_WINDOWS __pragma(warning(disable : 4710 4711)) diff --git a/modules/templates/src/main/kotlin/org/lwjgl/nuklear/templates/nuklear.kt b/modules/templates/src/main/kotlin/org/lwjgl/nuklear/templates/nuklear.kt index 97b77afbe2..3199ac39da 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/nuklear/templates/nuklear.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/nuklear/templates/nuklear.kt @@ -7,7 +7,7 @@ package org.lwjgl.nuklear.templates import org.lwjgl.generator.* import org.lwjgl.nuklear.* -val nuklear = "Nuklear".nativeClass(packageName = NUKLEAR_PACKAGE, prefix = "NK", prefixMethod = "nk_") { +val nuklear = "Nuklear".nativeClass(packageName = NUKLEAR_PACKAGE, prefix = "NK", prefixMethod = "nk_", library = "lwjgl_nuklear") { initializeAllocator() nativeDirective("""#ifdef LWJGL_LINUX #pragma GCC diagnostic ignored "-Wunused-function" diff --git a/modules/templates/src/main/kotlin/org/lwjgl/ovr/OVRTypes.kt b/modules/templates/src/main/kotlin/org/lwjgl/ovr/OVRTypes.kt index 522a78f1e3..958a0e3553 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/ovr/OVRTypes.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/ovr/OVRTypes.kt @@ -18,10 +18,10 @@ fun GeneratorTargetNative.includeOVRCAPI_GL() = nativeDirective( ENABLE_WARNINGS()""") val OVR_PACKAGE = "org.lwjgl.ovr" +val OVR_LIBRARY = "LibOVR.initialize();" val long_long = IntegerType("long long", PrimitiveMapping.LONG) -//val ovrBool = NativeType("ovrBool", TypeMapping.BOOLEAN) val ovrBool = IntegerType("ovrBool", PrimitiveMapping.BOOLEAN) val ovrResult = IntegerType("ovrResult", PrimitiveMapping.INT) @@ -533,6 +533,8 @@ fun config() { """ ) + Generator.registerLibraryInit(OVR_PACKAGE, "LibOVR", "ovr") + struct(OVR_PACKAGE, "OVRLayerEyeMatrix", nativeName = "ovrLayerEyeMatrix") { documentation = """ diff --git a/modules/templates/src/main/kotlin/org/lwjgl/ovr/templates/OVR.kt b/modules/templates/src/main/kotlin/org/lwjgl/ovr/templates/OVR.kt index fc8b6220e4..54c68acc22 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/ovr/templates/OVR.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/ovr/templates/OVR.kt @@ -7,7 +7,7 @@ package org.lwjgl.ovr.templates import org.lwjgl.generator.* import org.lwjgl.ovr.* -val OVR = "OVR".nativeClass(packageName = OVR_PACKAGE, prefixMethod = "ovr_", prefixConstant = "ovr") { +val OVR = "OVR".nativeClass(packageName = OVR_PACKAGE, prefixMethod = "ovr_", prefixConstant = "ovr", library = OVR_LIBRARY) { nativeDirective( """#ifdef LWJGL_WINDOWS __pragma(warning(disable : 4710)) diff --git a/modules/templates/src/main/kotlin/org/lwjgl/ovr/templates/OVRGL.kt b/modules/templates/src/main/kotlin/org/lwjgl/ovr/templates/OVRGL.kt index 65073562d7..d97dcb58f4 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/ovr/templates/OVRGL.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/ovr/templates/OVRGL.kt @@ -7,7 +7,7 @@ package org.lwjgl.ovr.templates import org.lwjgl.generator.* import org.lwjgl.ovr.* -val OVRGL = "OVRGL".nativeClass(packageName = OVR_PACKAGE, prefixMethod = "ovr_", prefixConstant = "ovr") { +val OVRGL = "OVRGL".nativeClass(packageName = OVR_PACKAGE, prefixMethod = "ovr_", prefixConstant = "ovr", library = OVR_LIBRARY) { includeOVRCAPI_GL() documentation = diff --git a/modules/templates/src/main/kotlin/org/lwjgl/ovr/templates/OVR_ErrorCode.kt b/modules/templates/src/main/kotlin/org/lwjgl/ovr/templates/OVR_ErrorCode.kt index 78b18ca1df..921b9d34f1 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/ovr/templates/OVR_ErrorCode.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/ovr/templates/OVR_ErrorCode.kt @@ -7,7 +7,7 @@ package org.lwjgl.ovr.templates import org.lwjgl.generator.* import org.lwjgl.ovr.* -val OVR_ErrorCode = "OVRErrorCode".nativeClass(OVR_PACKAGE, prefixMethod = "OVR_", prefixConstant = "ovr") { +val OVR_ErrorCode = "OVRErrorCode".nativeClass(OVR_PACKAGE, prefixMethod = "OVR_", prefixConstant = "ovr", library = OVR_LIBRARY) { nativeImport("OVR_ErrorCode.h") documentation = "LibOVR error code declarations." diff --git a/modules/templates/src/main/kotlin/org/lwjgl/ovr/templates/OVR_Util.kt b/modules/templates/src/main/kotlin/org/lwjgl/ovr/templates/OVR_Util.kt index d734a45904..693f0933eb 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/ovr/templates/OVR_Util.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/ovr/templates/OVR_Util.kt @@ -7,7 +7,11 @@ package org.lwjgl.ovr.templates import org.lwjgl.generator.* import org.lwjgl.ovr.* -val OVR_Util = "OVRUtil".nativeClass(packageName = OVR_PACKAGE, prefixMethod = "ovr", prefixConstant = "ovr") { +val OVR_Util = "OVRUtil".nativeClass(packageName = OVR_PACKAGE, prefixMethod = "ovr", prefixConstant = "ovr", library = OVR_LIBRARY) { + nativeDirective( + """#ifdef LWJGL_WINDOWS + __pragma(warning(disable : 4711)) +#endif""", beforeIncludes = true) includeOVRCAPI() documentation = "Native bindings to the libOVR utility functions." diff --git a/modules/templates/src/main/kotlin/org/lwjgl/stb/STBTypes.kt b/modules/templates/src/main/kotlin/org/lwjgl/stb/STBTypes.kt index 869011d283..3a5947ddf4 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/stb/STBTypes.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/stb/STBTypes.kt @@ -7,6 +7,7 @@ package org.lwjgl.stb import org.lwjgl.generator.* val STB_PACKAGE = "org.lwjgl.stb" +val STB_LIBRARY = "LibSTB.initialize();" fun config() { packageInfo( @@ -26,6 +27,8 @@ fun config() { )} """ ) + + Generator.registerLibraryInit(STB_PACKAGE, "LibSTB", "stb", setupAllocator = true) } fun GeneratorTargetNative.includeSTBAPI(directives: String) = nativeDirective( @@ -139,6 +142,7 @@ val stbrp_coord = typedef(unsigned_short, "stbrp_coord") // int is also supporte val stbrp_context_p = struct_p(STB_PACKAGE, "STBRPContext", nativeName = "stbrp_context", mutable = false) { documentation = "The opaque {@code stbrp_context} struct." includeSTBAPI("#include \"stb_rect_pack.h\"") + static(STB_LIBRARY) } val stbrp_rect_p = struct_p(STB_PACKAGE, "STBRPRect", nativeName = "stbrp_rect") { @@ -155,6 +159,7 @@ val stbrp_rect_p = struct_p(STB_PACKAGE, "STBRPRect", nativeName = "stbrp_rect") val stbrp_node_p = struct_p(STB_PACKAGE, "STBRPNode", nativeName = "stbrp_node") { documentation = "The opaque {@code stbrp_node} struct." includeSTBAPI("#include \"stb_rect_pack.h\"") + static(STB_LIBRARY) } // stb_truetype.h @@ -187,6 +192,7 @@ val stbtt_aligned_quad_p = struct_p(STB_PACKAGE, "STBTTAlignedQuad", nativeName val stbtt_pack_context_p = struct_p(STB_PACKAGE, "STBTTPackContext", nativeName = "stbtt_pack_context", mutable = false) { documentation = "An opaque structure which holds all the context needed from STBTruetype#stbtt_PackBegin to STBTruetype#stbtt_PackEnd." includeSTBAPI("#include \"stb_truetype.h\"") + static(STB_LIBRARY) } val stbtt_packedchar_p = struct_p(STB_PACKAGE, "STBTTPackedchar", nativeName = "stbtt_packedchar", mutable = false) { @@ -217,6 +223,7 @@ val stbtt_pack_range_p = struct_p(STB_PACKAGE, "STBTTPackRange", nativeName = "s val stbtt_fontinfo_p = struct_p(STB_PACKAGE, "STBTTFontinfo", nativeName = "stbtt_fontinfo", mutable = false) { documentation = "An opaque structure that contains font information." includeSTBAPI("#include \"stb_truetype.h\"") + static(STB_LIBRARY) } val stbtt_vertex_type = PrimitiveType("stbtt_vertex_type", PrimitiveMapping.SHORT) diff --git a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_dxt.kt b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_dxt.kt index b7792038c0..8555e9e851 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_dxt.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_dxt.kt @@ -7,7 +7,7 @@ package org.lwjgl.stb.templates import org.lwjgl.generator.* import org.lwjgl.stb.* -val stb_dxt = "STBDXT".nativeClass(packageName = STB_PACKAGE, prefix = "STB", prefixMethod = "stb_") { +val stb_dxt = "STBDXT".nativeClass(packageName = STB_PACKAGE, prefix = "STB", prefixMethod = "stb_", library = STB_LIBRARY) { includeSTBAPI( """#define STB_DXT_IMPLEMENTATION #include "stb_dxt.h"""") diff --git a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_easy_font.kt b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_easy_font.kt index ccea3548d1..f3b949011e 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_easy_font.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_easy_font.kt @@ -7,7 +7,7 @@ package org.lwjgl.stb.templates import org.lwjgl.generator.* import org.lwjgl.stb.* -val stb_easy_font = "STBEasyFont".nativeClass(packageName = STB_PACKAGE, prefix = "STB", prefixMethod = "stb_") { +val stb_easy_font = "STBEasyFont".nativeClass(packageName = STB_PACKAGE, prefix = "STB", prefixMethod = "stb_", library = STB_LIBRARY) { includeSTBAPI("#include \"stb_easy_font.h\"") documentation = diff --git a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_image.kt b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_image.kt index 00cfb2f18b..f56cc2b07c 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_image.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_image.kt @@ -7,15 +7,16 @@ package org.lwjgl.stb.templates import org.lwjgl.generator.* import org.lwjgl.stb.* -val stb_image = "STBImage".nativeClass(packageName = STB_PACKAGE, prefix = "STBI_") { - initializeAllocator() +val stb_image = "STBImage".nativeClass(packageName = STB_PACKAGE, prefix = "STBI_", library = STB_LIBRARY) { includeSTBAPI( - """#define STB_IMAGE_IMPLEMENTATION${if ( Binding.NANOVG.enabled ) "" else "\n#define STB_IMAGE_STATIC"} -#define STBI_FAILURE_USERMSG -#define STBI_ASSERT(x) + """#include "lwjgl_malloc.h" #define STBI_MALLOC(sz) lwjgl_malloc(sz) #define STBI_REALLOC(p,sz) lwjgl_realloc(p,sz) #define STBI_FREE(p) lwjgl_free(p) +#define STBI_FAILURE_USERMSG +#define STBI_ASSERT(x) +#define STB_IMAGE_IMPLEMENTATION +#define STB_IMAGE_STATIC #include "stb_image.h"""") documentation = diff --git a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_image_resize.kt b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_image_resize.kt index 5af1e8a4d8..fd82e9f630 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_image_resize.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_image_resize.kt @@ -7,14 +7,14 @@ package org.lwjgl.stb.templates import org.lwjgl.generator.* import org.lwjgl.stb.* -val stb_image_resize = "STBImageResize".nativeClass(packageName = STB_PACKAGE, prefix = "STBIR", prefixMethod = "stbir_") { - initializeAllocator() +val stb_image_resize = "STBImageResize".nativeClass(packageName = STB_PACKAGE, prefix = "STBIR", prefixMethod = "stbir_", library = STB_LIBRARY) { includeSTBAPI( - """#define STB_IMAGE_RESIZE_IMPLEMENTATION -#define STB_IMAGE_RESIZE_STATIC -#define STBIR_ASSERT(x) + """#include "lwjgl_malloc.h" #define STBIR_MALLOC(size,c) lwjgl_malloc(size) #define STBIR_FREE(ptr,c) lwjgl_free(ptr) +#define STBIR_ASSERT(x) +#define STB_IMAGE_RESIZE_IMPLEMENTATION +#define STB_IMAGE_RESIZE_STATIC #include "stb_image_resize.h"""") documentation = diff --git a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_image_write.kt b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_image_write.kt index 94c2e8b6e6..5cf698ed51 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_image_write.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_image_write.kt @@ -7,7 +7,7 @@ package org.lwjgl.stb.templates import org.lwjgl.generator.* import org.lwjgl.stb.* -val stb_image_write = "STBImageWrite".nativeClass(packageName = STB_PACKAGE, prefix = "STBI", prefixMethod = "stbi_") { +val stb_image_write = "STBImageWrite".nativeClass(packageName = STB_PACKAGE, prefix = "STBI", prefixMethod = "stbi_", library = STB_LIBRARY) { nativeDirective( """#ifdef LWJGL_WINDOWS __pragma(warning(disable : 4710)) @@ -15,12 +15,13 @@ val stb_image_write = "STBImageWrite".nativeClass(packageName = STB_PACKAGE, pre initializeAllocator() includeSTBAPI( - """#define STB_IMAGE_WRITE_IMPLEMENTATION -#define STB_IMAGE_WRITE_STATIC -#define STBIW_ASSERT(x) + """#include "lwjgl_malloc.h" #define STBIW_MALLOC(sz) lwjgl_malloc(sz) #define STBIW_REALLOC(p,sz) lwjgl_realloc(p,sz) #define STBIW_FREE(p) lwjgl_free(p) +#define STBIW_ASSERT(x) +#define STB_IMAGE_WRITE_IMPLEMENTATION +#define STB_IMAGE_WRITE_STATIC #include "stb_image_write.h"""") documentation = diff --git a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_perlin.kt b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_perlin.kt index 367f049900..3a64085e93 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_perlin.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_perlin.kt @@ -7,7 +7,7 @@ package org.lwjgl.stb.templates import org.lwjgl.generator.* import org.lwjgl.stb.* -val stb_perlin = "STBPerlin".nativeClass(packageName = STB_PACKAGE, prefix = "STB", prefixMethod = "stb_") { +val stb_perlin = "STBPerlin".nativeClass(packageName = STB_PACKAGE, prefix = "STB", prefixMethod = "stb_", library = STB_LIBRARY) { includeSTBAPI( """#define STB_PERLIN_IMPLEMENTATION #include "stb_perlin.h"""") diff --git a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_rect_pack.kt b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_rect_pack.kt index 2c8d36bb43..32cf4435c4 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_rect_pack.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_rect_pack.kt @@ -7,10 +7,10 @@ package org.lwjgl.stb.templates import org.lwjgl.generator.* import org.lwjgl.stb.* -val stb_rect_pack = "STBRectPack".nativeClass(packageName = STB_PACKAGE, prefix = "STBRP", prefixMethod = "stbrp_") { +val stb_rect_pack = "STBRectPack".nativeClass(packageName = STB_PACKAGE, prefix = "STBRP", prefixMethod = "stbrp_", library = STB_LIBRARY) { includeSTBAPI( - """#define STB_RECT_PACK_IMPLEMENTATION -#define STBRP_ASSERT + """#define STBRP_ASSERT +#define STB_RECT_PACK_IMPLEMENTATION #include "stb_rect_pack.h"""") documentation = diff --git a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_truetype.kt b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_truetype.kt index 2d21b44f8b..f8da35dc79 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_truetype.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_truetype.kt @@ -7,13 +7,14 @@ package org.lwjgl.stb.templates import org.lwjgl.generator.* import org.lwjgl.stb.* -val stb_truetype = "STBTruetype".nativeClass(packageName = STB_PACKAGE, prefix = "STBTT", prefixMethod = "stbtt_") { - initializeAllocator() +val stb_truetype = "STBTruetype".nativeClass(packageName = STB_PACKAGE, prefix = "STBTT", prefixMethod = "stbtt_", library = STB_LIBRARY) { includeSTBAPI( - """#define STB_TRUETYPE_IMPLEMENTATION${if ( Binding.NANOVG.enabled ) "" else "\n#define STBTT_STATIC"} -#define STBTT_assert + """#include "lwjgl_malloc.h" #define STBTT_malloc(x,u) ((void)(u),lwjgl_malloc(x)) #define STBTT_free(x,u) ((void)(u),lwjgl_free(x)) +#define STBTT_assert +#define STB_TRUETYPE_IMPLEMENTATION +#define STBTT_STATIC #include "stb_rect_pack.h" #include "stb_truetype.h"""") diff --git a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_vorbis.kt b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_vorbis.kt index fa35e99d58..2fd955c158 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_vorbis.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/stb/templates/stb_vorbis.kt @@ -7,7 +7,7 @@ package org.lwjgl.stb.templates import org.lwjgl.generator.* import org.lwjgl.stb.* -val stb_vorbis = "STBVorbis".nativeClass(packageName = STB_PACKAGE, prefixMethod = "stb_vorbis_", prefixConstant = "VORBIS_") { +val stb_vorbis = "STBVorbis".nativeClass(packageName = STB_PACKAGE, prefixMethod = "stb_vorbis_", prefixConstant = "VORBIS_", library = STB_LIBRARY) { includeSTBAPI( """#ifdef LWJGL_LINUX #include diff --git a/modules/templates/src/main/kotlin/org/lwjgl/system/jawt/templates/jawt.kt b/modules/templates/src/main/kotlin/org/lwjgl/system/jawt/templates/jawt.kt index 2c5af261a0..9f133fde52 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/system/jawt/templates/jawt.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/system/jawt/templates/jawt.kt @@ -8,7 +8,7 @@ import org.lwjgl.generator.* import org.lwjgl.system.jawt.* private val JAWT_BINDING = simpleBinding("jawt", callingConvention = CallingConvention.STDCALL) -val jawt = "JAWTFunctions".nativeClass(JAWT_PACKAGE, prefix = "JAWT_", prefixMethod = "JAWT_", binding = JAWT_BINDING) { +val jawt = "JAWTFunctions".nativeClass(JAWT_PACKAGE, prefix = "JAWT_", prefixMethod = "JAWT_", binding = JAWT_BINDING, library = "lwjgl_jawt") { nativeDirective( """DISABLE_WARNINGS() #include "jawt_md.h" diff --git a/modules/templates/src/main/kotlin/org/lwjgl/system/jemalloc/jemallocTypes.kt b/modules/templates/src/main/kotlin/org/lwjgl/system/jemalloc/jemallocTypes.kt index 91ad675fab..066d81858f 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/system/jemalloc/jemallocTypes.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/system/jemalloc/jemallocTypes.kt @@ -5,6 +5,7 @@ package org.lwjgl.system.jemalloc import org.lwjgl.generator.* +import java.io.PrintWriter val JEMALLOC_PACKAGE = "org.lwjgl.system.jemalloc" @@ -35,6 +36,69 @@ fun config() { {@code mallctl*} functions. """ ) + + Generator.register(object : CustomClass(JEMALLOC_PACKAGE, "JEmallocAllocator") { + + init { + javaImport("org.lwjgl.system.MemoryUtil.*") + javaImport("static org.lwjgl.system.jemalloc.JEmalloc.*") + documentation = "A {@link MemoryAllocator} implementation using the jemalloc library." + } + + override fun PrintWriter.generateContent() { + println("""public class JEmallocAllocator implements MemoryAllocator { + + @Override + public long getMalloc() { return JEmalloc.Functions.malloc; } + + @Override + public long getCalloc() { return JEmalloc.Functions.calloc; } + + @Override + public long getRealloc() { return JEmalloc.Functions.realloc; } + + @Override + public long getFree() { return JEmalloc.Functions.free; } + + @Override + public long getAlignedAlloc() { return JEmalloc.Functions.aligned_alloc; } + + @Override + public long getAlignedFree() { return JEmalloc.Functions.free; } + + @Override + public long malloc(long size) { + return nje_malloc(size); + } + + @Override + public long calloc(long num, long size) { + return nje_calloc(num, size); + } + + @Override + public long realloc(long ptr, long size) { + return nje_realloc(ptr, size); + } + + @Override + public void free(long ptr) { + nje_free(ptr); + } + + @Override + public long aligned_alloc(long alignment, long size) { + return nje_aligned_alloc(alignment, size); + } + + @Override + public void aligned_free(long ptr) { + nje_free(ptr); + } + +}""") + } + }) } val je_malloc_message_cb = "je_malloc_message_cb".callback( diff --git a/modules/templates/src/main/kotlin/org/lwjgl/util/lmdb/templates/lmdb.kt b/modules/templates/src/main/kotlin/org/lwjgl/util/lmdb/templates/lmdb.kt index 4f6ee13f54..8b56f540ef 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/util/lmdb/templates/lmdb.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/util/lmdb/templates/lmdb.kt @@ -7,7 +7,7 @@ package org.lwjgl.util.lmdb.templates import org.lwjgl.generator.* import org.lwjgl.util.lmdb.* -val lmdb = "LMDB".nativeClass(LMDB_PACKAGE, prefix = "MDB", prefixMethod = "mdb_") { +val lmdb = "LMDB".nativeClass(LMDB_PACKAGE, prefix = "MDB", prefixMethod = "mdb_", library = "lwjgl_lmdb") { nativeDirective( """#ifdef LWJGL_WINDOWS __pragma(warning(disable : 4710 4711)) diff --git a/modules/templates/src/main/kotlin/org/lwjgl/util/nfd/NFDTypes.kt b/modules/templates/src/main/kotlin/org/lwjgl/util/nfd/NFDTypes.kt index 49305e1431..60e17f7367 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/util/nfd/NFDTypes.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/util/nfd/NFDTypes.kt @@ -7,6 +7,7 @@ package org.lwjgl.util.nfd import org.lwjgl.generator.* val NFD_PACKAGE = "org.lwjgl.util.nfd" +val NFD_LIBRARY = "LibNFD.initialize();" fun config() { packageInfo( @@ -16,6 +17,8 @@ fun config() { file open and save dialogs. Write dialog code once and have it popup native dialogs on all """ ) + + Generator.registerLibraryInit(NFD_PACKAGE, "LibNFD", "nfd", setupAllocator = true) } val nfdchar_t = CharType("nfdchar_t", CharMapping.UTF8) @@ -25,6 +28,7 @@ val nfdchar_t_pp = nfdchar_t_p.p val nfdpathset_t_p = struct_p(NFD_PACKAGE, "NFDPathSet", nativeName = "nfdpathset_t", mutable = false) { nativeImport("nfd.h") documentation = "An opaque data structure to be used with #OpenDialogMultiple()." + static(NFD_LIBRARY) } val nfdresult_t = "nfdresult_t".enumType diff --git a/modules/templates/src/main/kotlin/org/lwjgl/util/nfd/templates/nativefiledialog.kt b/modules/templates/src/main/kotlin/org/lwjgl/util/nfd/templates/nativefiledialog.kt index bf966443ce..7704933a7c 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/util/nfd/templates/nativefiledialog.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/util/nfd/templates/nativefiledialog.kt @@ -7,13 +7,14 @@ package org.lwjgl.util.nfd.templates import org.lwjgl.generator.* import org.lwjgl.util.nfd.* -val nativefiledialog = "NativeFileDialog".nativeClass(packageName = NFD_PACKAGE, prefix = "NFD_", prefixMethod = "NFD_") { +val nativefiledialog = "NativeFileDialog".nativeClass(packageName = NFD_PACKAGE, prefix = "NFD_", prefixMethod = "NFD_", library = NFD_LIBRARY) { initializeAllocator() nativeDirective( """#ifdef LWJGL_WINDOWS #define _CRT_SECURE_NO_WARNINGS #endif""", beforeIncludes = true) + nativeImport("lwjgl_malloc.h") nativeImport("nfd_common.h") nativeImport("nfd.h") diff --git a/modules/templates/src/main/kotlin/org/lwjgl/util/par/ParTypes.kt b/modules/templates/src/main/kotlin/org/lwjgl/util/par/ParTypes.kt index 22d829cfb9..0947d7dbb9 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/util/par/ParTypes.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/util/par/ParTypes.kt @@ -15,6 +15,8 @@ fun config() { Contains bindings to the par library. """ ) + + Generator.registerLibraryInit(PAR_PACKAGE, "LibPar", "par", setupAllocator = true) } val PAR_SHAPES_T = typedef(uint16_t, "PAR_SHAPES_T") diff --git a/modules/templates/src/main/kotlin/org/lwjgl/util/par/templates/par_shapes.kt b/modules/templates/src/main/kotlin/org/lwjgl/util/par/templates/par_shapes.kt index ba642fd395..41289ee00e 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/util/par/templates/par_shapes.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/util/par/templates/par_shapes.kt @@ -7,7 +7,7 @@ package org.lwjgl.util.par.templates import org.lwjgl.generator.* import org.lwjgl.util.par.* -val par_shapes = "ParShapes".nativeClass(packageName = PAR_PACKAGE, prefix = "par_shapes_") { +val par_shapes = "ParShapes".nativeClass(packageName = PAR_PACKAGE, prefix = "par_shapes_", library = "LibPar.initialize();") { nativeDirective( """#ifdef LWJGL_WINDOWS #define _CRT_SECURE_NO_WARNINGS @@ -18,7 +18,7 @@ val par_shapes = "ParShapes".nativeClass(packageName = PAR_PACKAGE, prefix = "pa initializeAllocator() nativeDirective( - """#define PAR_SHAPES_IMPLEMENTATION + """#include "lwjgl_malloc.h" #define PAR_MALLOC(T, N) ((T*) lwjgl_malloc(N * sizeof(T))) #define PAR_CALLOC(T, N) ((T*) lwjgl_calloc(N, sizeof(T))) #define PAR_REALLOC(T, BUF, N) ((T*) lwjgl_realloc(BUF, sizeof(T) * N)) @@ -29,6 +29,7 @@ DISABLE_WARNINGS() #elif LWJGL_LINUX #pragma GCC diagnostic ignored "-Wunused-parameter" #endif +#define PAR_SHAPES_IMPLEMENTATION #include "par_shapes.h" ENABLE_WARNINGS()""") diff --git a/modules/templates/src/main/kotlin/org/lwjgl/util/simd/SSETypes.kt b/modules/templates/src/main/kotlin/org/lwjgl/util/simd/SSETypes.kt new file mode 100644 index 0000000000..ad0480ebc4 --- /dev/null +++ b/modules/templates/src/main/kotlin/org/lwjgl/util/simd/SSETypes.kt @@ -0,0 +1,19 @@ +/* + * Copyright LWJGL. All rights reserved. + * License terms: http://lwjgl.org/license.php + */ +package org.lwjgl.util.simd + +import org.lwjgl.generator.* + +val SSE_PACKAGE = "org.lwjgl.util.simd" +val SSE_LIBRARY = "LibSSE.initialize();" + +fun config() { + packageInfo( + SSE_PACKAGE, + "Contains bindings to SSE macros." + ) + + Generator.registerLibraryInit(SSE_PACKAGE, "LibSSE", "sse") +} \ No newline at end of file diff --git a/modules/templates/src/main/kotlin/org/lwjgl/util/simd/templates/SSE.kt b/modules/templates/src/main/kotlin/org/lwjgl/util/simd/templates/SSE.kt index 8fb6b2a26a..b1067a95d4 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/util/simd/templates/SSE.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/util/simd/templates/SSE.kt @@ -5,8 +5,9 @@ package org.lwjgl.util.simd.templates import org.lwjgl.generator.* +import org.lwjgl.util.simd.* -val SSE = "SSE".nativeClass("org.lwjgl.util.simd", prefix = "_MM", prefixMethod = "_MM_") { +val SSE = "SSE".nativeClass("org.lwjgl.util.simd", prefix = "_MM", prefixMethod = "_MM_", library = SSE_LIBRARY) { nativeImport( "simd/intrinsics.h" ) diff --git a/modules/templates/src/main/kotlin/org/lwjgl/util/simd/templates/SSE3.kt b/modules/templates/src/main/kotlin/org/lwjgl/util/simd/templates/SSE3.kt index 40300c10ce..2418050ee6 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/util/simd/templates/SSE3.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/util/simd/templates/SSE3.kt @@ -5,8 +5,9 @@ package org.lwjgl.util.simd.templates import org.lwjgl.generator.* +import org.lwjgl.util.simd.* -val SSE3 = "SSE3".nativeClass("org.lwjgl.util.simd", prefix = "_MM", prefixMethod = "_MM_") { +val SSE3 = "SSE3".nativeClass("org.lwjgl.util.simd", prefix = "_MM", prefixMethod = "_MM_", library = SSE_LIBRARY) { nativeImport( "simd/intrinsics.h" ) diff --git a/modules/templates/src/main/kotlin/org/lwjgl/util/xxhash/templates/xxhash.kt b/modules/templates/src/main/kotlin/org/lwjgl/util/xxhash/templates/xxhash.kt index 895db3d5a2..d1297baf2a 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/util/xxhash/templates/xxhash.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/util/xxhash/templates/xxhash.kt @@ -7,7 +7,7 @@ package org.lwjgl.util.xxhash.templates import org.lwjgl.generator.* import org.lwjgl.util.xxhash.* -val xxhash = "XXHash".nativeClass(XXHASH_PACKAGE, prefix = "XXH", prefixMethod = "XXH") { +val xxhash = "XXHash".nativeClass(XXHASH_PACKAGE, prefix = "XXH", prefixMethod = "XXH", library = "LibXXHash.initialize();") { initializeAllocator() nativeDirective( @@ -21,6 +21,7 @@ val xxhash = "XXHash".nativeClass(XXHASH_PACKAGE, prefix = "XXH", prefixMethod = __pragma(warning(disable : 4711)) #endif #define XXH_PRIVATE_API +#include "lwjgl_malloc.h" #include "xxhash.c" ENABLE_WARNINGS()""") diff --git a/modules/templates/src/main/kotlin/org/lwjgl/util/xxhash/xxHashTypes.kt b/modules/templates/src/main/kotlin/org/lwjgl/util/xxhash/xxHashTypes.kt index 6ed68c26a8..f3a2df136f 100644 --- a/modules/templates/src/main/kotlin/org/lwjgl/util/xxhash/xxHashTypes.kt +++ b/modules/templates/src/main/kotlin/org/lwjgl/util/xxhash/xxHashTypes.kt @@ -18,6 +18,8 @@ fun config() { dispersion and randomness qualities of hash functions. """ ) + + Generator.registerLibraryInit(XXHASH_PACKAGE, "LibXXHash", "xxhash", setupAllocator = true) } val unsigned_long_long = IntegerType("long long", PrimitiveMapping.LONG, unsigned = true)