Skip to content

Commit

Permalink
Merge pull request #47 from Over-Run/marshal
Browse files Browse the repository at this point in the history
Update marshal
  • Loading branch information
squid233 authored Feb 26, 2024
2 parents 8a4ebed + fe1a7fd commit b0630a8
Show file tree
Hide file tree
Showing 545 changed files with 2,032 additions and 1,261 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
- name: Grant execute permission for gradlew
if: ${{ runner.os != 'Windows' }}
run: chmod +x gradlew
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: build --no-daemon -x :samples:test
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Execute Gradle build
run: ./gradlew build --no-daemon -x :samples:test
- name: Upload build reports
if: ${{ runner.os == 'Linux' && matrix.java == '22-ea' && failure() }}
uses: actions/upload-artifact@v4
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,16 @@ but OverrunGL uses [FFM API](https://openjdk.org/jeps/454), which has better per
You can check our [wiki](https://github.com/Over-Run/overrungl/wiki) or
the [samples](modules/samples/src/test/java/overrungl/demo).

### Enable native access

You must enable the access of OverrunGL by adding a VM argument or a manifest attribute.

```
--enable-preview-access=overrungl.core,...
```

## Import as a Dependency

We provided a modules customizer [here](https://over-run.github.io/overrungl-gen/).

Currently, we are developing with the first version,
and it uses preview features, which prevent users from using newer JDKs,
so you have to use `-SNAPSHOT` version.

You can import with `io.github.over-run:overrungl-bom:{the version}` and other submodules.

We have provided a modules customizer [here](https://over-run.github.io/overrungl-gen/).

### Using -SNAPSHOT Versions

We publish `-SNAPSHOT` versions frequently.
Expand All @@ -56,6 +48,14 @@ and include this maven repository:
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots" }
```

### Enable native access

You must enable the access of OverrunGL by adding a VM argument or a manifest attribute.

```
--enable-preview-access=overrungl.core,...
```

## List of Supported Bindings

### Khronos APIs
Expand Down Expand Up @@ -105,6 +105,8 @@ Javadoc can be found [here](https://over-run.github.io/overrungl-doc/).

The documentation of OpenGL can be found from [references](https://registry.khronos.org/OpenGL-Refpages/gl4/) and [docs.gl](https://docs.gl/).

OverrunGL uses [Marshal](https://github.com/Over-Run/marshal).

### Credits

[<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" alt="JetBrains Logo (Main) logo." width="128" height="128">](https://jb.gg/OpenSourceSupport)
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plugins {
`java-platform`
`maven-publish`
signing
id("me.champeau.jmh") version "0.7.2" apply false
}

val projGroupId: String by project
Expand Down Expand Up @@ -127,7 +126,6 @@ artifactNameMap.forEach { (subprojectName, artifactName) ->
project(subprojectName) {
apply(plugin = "java-library")
apply(plugin = "idea")
apply(plugin = "me.champeau.jmh")

group = projGroupId
version = projVersion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
embeddedKotlin("jvm") apply false
embeddedKotlin("jvm")
}

repositories { mavenCentral() }

val jdkVersion: String by rootProject
val jdkEnablePreview: String by rootProject
val kotlinTargetJdkVersion: String by rootProject

sourceSets {
create("generator")
}

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

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

tasks.register<JavaExec>("generate") {
classpath(sourceSets["generator"].runtimeClasspath)
classpath(sourceSets["main"].runtimeClasspath)
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")
workingDir = project(":opengl").projectDir.resolve("src/main/java/overrungl/opengl")
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ data class Type(val name: String, val layout: String?) {
const val fileHeader = """/*
* MIT License
*
* Copyright (c) 2022-present Overrun Organization
* Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -193,7 +193,7 @@ class OpenGLFile(
|/**
| * {@code $extName}
| */
|public interface GL${ext.extName}$name {
|public interface GL${ext.extName}$name extends overrun.marshal.DirectAccess {
""".trimMargin()
)
// constants
Expand Down Expand Up @@ -2524,10 +2524,9 @@ fun glExtension() {
|
|/**
| * The OpenGL extension functions.
| *
| * @since 0.1.0
| */
|public interface GLExtension extends
|public interface GLExtension extends overrun.marshal.DirectAccess,
""".trimMargin())
generatedExtClasses.joinTo(this, ",\n") { " GL${it.ext.extName}${it.name}" }
appendLine(" {")
Expand Down Expand Up @@ -3165,7 +3164,6 @@ fun glFlags() {
|
|/**
| * The OpenGL flags.
| *
| * @since 0.1.0
| */
|public final class GLFlags {
Expand All @@ -3177,7 +3175,7 @@ fun glFlags() {
| GL30, GL31, GL32, GL33,
| GL40, GL41, GL42, GL43, GL44, GL45, GL46;
| /** The OpenGL extension flags. */
| public final boolean ${caps.joinToString()};
| public final boolean ${caps.joinToString(separator = ",\n| ")};
|
| /**
| * Construct OpenGL flags.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ jdkEnablePreview=true
jdkEarlyAccessDoc=jdk22
kotlinTargetJdkVersion=21

overrunMarshalVersion=0.1.0-alpha.17-jdk22
overrunMarshalVersion=0.1.0-alpha.21-jdk22
overrunPlatformVersion=1.0.0
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class OverrunGL {
/**
* The version of STB native libraries.
*/
public static final String STB_VERSION = "0.1.0.2";
public static final String STB_VERSION = "0.1.0.3";
private static final Consumer<String> DEFAULT_LOGGER = System.err::println;
private static Consumer<String> apiLogger = DEFAULT_LOGGER;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package overrungl.glfw;

import org.jetbrains.annotations.Nullable;
import overrun.marshal.DirectAccess;
import overrun.marshal.Downcall;
import overrun.marshal.MemoryStack;
import overrun.marshal.Unmarshal;
Expand All @@ -40,7 +41,7 @@
* @author squid233
* @since 0.1.0
*/
public interface GLFW {
public interface GLFW extends DirectAccess {
/**
* The instance of GLFW.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import overrun.marshal.Upcall;

import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;

/**
* This is the function pointer type for Unicode character callbacks.
Expand All @@ -37,15 +39,14 @@ public interface GLFWCharFun extends Upcall {
/**
* The type.
*/
Type<GLFWCharFun> TYPE = Upcall.type();
Type<GLFWCharFun> TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT));

/**
* The function pointer type for Unicode character callbacks.
*
* @param window The window that received the event.
* @param codepoint The Unicode code point of the character.
*/
@Stub
void invoke(MemorySegment window, int codepoint);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import overrun.marshal.Upcall;

import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;

/**
* This is the function pointer type for cursor enter/leave callbacks.
Expand All @@ -37,7 +39,7 @@ public interface GLFWCursorEnterFun extends Upcall {
/**
* The type.
*/
Type<GLFWCursorEnterFun> TYPE = Upcall.type();
Type<GLFWCursorEnterFun> TYPE = Upcall.type("ninvoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT));

/**
* The function pointer type for cursor enter/leave callbacks.
Expand All @@ -55,7 +57,6 @@ public interface GLFWCursorEnterFun extends Upcall {
* @param entered {@code true} if the cursor entered the window's content
* area, or {@code false} if it left it.
*/
@Stub
default void ninvoke(MemorySegment window, int entered) {
invoke(window, entered != GLFW.FALSE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import overrun.marshal.Upcall;

import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;

/**
* This is the function pointer type for cursor position callbacks. A cursor
Expand All @@ -37,7 +39,7 @@ public interface GLFWCursorPosFun extends Upcall {
/**
* The type.
*/
Type<GLFWCursorPosFun> TYPE = Upcall.type();
Type<GLFWCursorPosFun> TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE));

/**
* The function pointer type for cursor position callbacks.
Expand All @@ -46,7 +48,6 @@ public interface GLFWCursorPosFun extends Upcall {
* @param xpos The new cursor x-coordinate, relative to the left edge of the content area.
* @param ypos The new cursor y-coordinate, relative to the top edge of the content area.
*/
@Stub
void invoke(MemorySegment window, double xpos, double ypos);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import overrun.marshal.Upcall;

import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;

Expand All @@ -41,7 +42,7 @@ public interface GLFWDropFun extends Upcall {
/**
* The type.
*/
Type<GLFWDropFun> TYPE = Upcall.type();
Type<GLFWDropFun> TYPE = Upcall.type("ninvoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.ADDRESS));

/**
* The function pointer type for path drop callbacks.
Expand All @@ -58,7 +59,6 @@ public interface GLFWDropFun extends Upcall {
* @param pathCount The number of dropped paths.
* @param paths The UTF-8 encoded file and/or directory path names.
*/
@Stub
default void ninvoke(MemorySegment window, int pathCount, MemorySegment paths) {
invoke(window, Unmarshal.unmarshalAsStringArray(paths.reinterpret(ValueLayout.ADDRESS.scale(0L, pathCount))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

import overrun.marshal.Unmarshal;
import overrun.marshal.Upcall;
import overrun.marshal.gen.SizedSeg;
import overrungl.NativeType;

import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;

import static java.lang.foreign.ValueLayout.*;

/**
* This is the function pointer type for error callbacks. An error callback
* function has the following signature:
Expand All @@ -43,7 +46,7 @@ public interface GLFWErrorFun extends Upcall {
/**
* The type.
*/
Type<GLFWErrorFun> TYPE = Upcall.type();
Type<GLFWErrorFun> TYPE = Upcall.type("ninvoke", FunctionDescriptor.ofVoid(JAVA_INT, ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(Unmarshal.STR_SIZE, JAVA_BYTE))));

/**
* The function pointer type for error callbacks.
Expand All @@ -60,8 +63,7 @@ public interface GLFWErrorFun extends Upcall {
* Future releases may add more error codes.
* @param description A UTF-8 encoded string describing the error.
*/
@Stub
default void ninvoke(int errorCode, @NativeType("const char*") @SizedSeg(Unmarshal.STR_SIZE) MemorySegment description) {
default void ninvoke(int errorCode, @NativeType("const char*") MemorySegment description) {
invoke(errorCode, Unmarshal.unmarshalAsString(description));
}

Expand Down
Loading

0 comments on commit b0630a8

Please sign in to comment.