Skip to content

Commit

Permalink
Merge pull request #32 from Over-Run/opengl
Browse files Browse the repository at this point in the history
[OpenGL] Update core and extensions
  • Loading branch information
squid233 authored Dec 29, 2023
2 parents 5a28397 + d44845b commit 5507894
Show file tree
Hide file tree
Showing 470 changed files with 42,554 additions and 10,015 deletions.
35 changes: 17 additions & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.gradle.plugins.ide.idea.model.IdeaModel
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.nio.file.Files
import kotlin.io.path.Path

Expand All @@ -7,6 +8,7 @@ plugins {
`maven-publish`
signing
id("me.champeau.jmh") version "0.7.1" apply false
embeddedKotlin("jvm") apply false
}

val projGroupId: String by project
Expand All @@ -19,9 +21,12 @@ val orgName: String by project
val orgUrl: String by project
val developers: String by project

val jdkEABuildDoc: String? = null
val targetJavaVersion = 21
val enablePreview = true
val jdkVersion: String by rootProject
val jdkEnablePreview: String by rootProject
val jdkEarlyAccessDoc: String? by rootProject
val kotlinTargetJdkVersion: String by rootProject

val targetJavaVersion = jdkVersion.toInt()

group = projGroupId
version = projVersion
Expand Down Expand Up @@ -121,6 +126,7 @@ subprojects {
apply(plugin = "java-library")
apply(plugin = "idea")
apply(plugin = "me.champeau.jmh")
apply(plugin = "org.jetbrains.kotlin.jvm")

group = projGroupId
version = projVersion
Expand All @@ -145,12 +151,16 @@ subprojects {

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
if (enablePreview) options.compilerArgs.add("--enable-preview")
if (jdkEnablePreview.toBoolean()) options.compilerArgs.add("--enable-preview")
options.release.set(targetJavaVersion)
}

tasks.withType<KotlinCompile> {
kotlinOptions { jvmTarget = kotlinTargetJdkVersion }
}

tasks.withType<Test> {
if (enablePreview) jvmArgs("--enable-preview")
if (jdkEnablePreview.toBoolean()) jvmArgs("--enable-preview")
}

extensions.configure<JavaPluginExtension>("java") {
Expand Down Expand Up @@ -241,10 +251,10 @@ allprojects {
charSet = "UTF-8"
docEncoding = "UTF-8"
isAuthor = true
if (jdkEABuildDoc == null) {
if (jdkEarlyAccessDoc == null) {
links("https://docs.oracle.com/en/java/javase/$targetJavaVersion/docs/api/")
} else {
links("https://download.java.net/java/early_access/$jdkEABuildDoc/docs/api/")
links("https://download.java.net/java/early_access/$jdkEarlyAccessDoc/docs/api/")
}

tags(
Expand Down Expand Up @@ -288,17 +298,6 @@ publishing.publications {
name.set(orgName)
url.set(orgUrl)
}
developers {
developers.split(',')
.map { it.split(':', limit = 3) }
.forEach { (id1, name1, email1) ->
developer {
id.set(id1)
name.set(name1)
email.set(email1)
}
}
}
scm {
connection.set("scm:git:https://github.com/${projVcs}.git")
developerConnection.set("scm:git:https://github.com/${projVcs}.git")
Expand Down
6 changes: 4 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ projBranch=main
orgName=Overrun Organization
orgUrl=https://over-run.github.io/

# Developers
developers=squid233:squid233:[email protected]
jdkVersion=21
jdkEnablePreview=true
#jdkEarlyAccessDoc=jdk22
kotlinTargetJdkVersion=21

projModules=core, glfw, nfd, joml, opengl, stb
20 changes: 20 additions & 0 deletions modules/overrungl.core/src/main/java/overrungl/Callback.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.util.function.Function;

/**
* The upcall stub which can be passed to other foreign functions as a function pointer,
Expand Down Expand Up @@ -58,6 +59,16 @@ default MemorySegment address(Arena arena) {
*/
MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException;

/**
* Creates a method handle that invokes a native function callback.
*
* @param segment the segment of the native function.
* @return the method handle
*/
default MethodHandle nativeHandle(MemorySegment segment) {
return RuntimeHelper.LINKER.downcallHandle(segment, descriptor());
}

/**
* Gets the memory segment of the upcall stub with the given arena.
*
Expand All @@ -72,4 +83,13 @@ default MemorySegment segment(Arena arena, FunctionDescriptor function) {
throw new RuntimeException(e);
}
}

/**
* Method handle getter.
*
* @author squid233
* @since 0.1.0
*/
interface Native<T> extends Function<MemorySegment, T> {
}
}
18 changes: 16 additions & 2 deletions modules/overrungl.opengl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
val jdkVersion: String by rootProject
val jdkEnablePreview: String by rootProject
val kotlinTargetJdkVersion: String by rootProject

sourceSets {
create("generator")
}

tasks.named<JavaCompile>("compileGeneratorJava") {
javaCompiler.set(javaToolchains.compilerFor {
targetCompatibility = kotlinTargetJdkVersion
languageVersion.set(JavaLanguageVersion.of(jdkVersion))
})
}

tasks.register<JavaExec>("generate") {
classpath(sourceSets["generator"].runtimeClasspath)
jvmArgs("--enable-preview")
mainClass.set("overrungl.opengl.OpenGLGenerator")
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(jdkVersion))
})
if (jdkEnablePreview.toBoolean()) jvmArgs("--enable-preview")
mainClass.set("overrungl.opengl.OpenGLGeneratorKt")
workingDir = File("src/main/java/overrungl/opengl")
}
Loading

0 comments on commit 5507894

Please sign in to comment.