Skip to content

Commit

Permalink
Merge pull request #23 from Over-Run/stb
Browse files Browse the repository at this point in the history
Module: STB
  • Loading branch information
squid233 authored Jan 29, 2024
2 parents 5322b3e + 3901df6 commit 021f949
Show file tree
Hide file tree
Showing 54 changed files with 4,717 additions and 1,682 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots" }

| Library | Description |
|------------------|---------------------------------------------------------------------------------|
| stb_easy_font | Quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc. |
| stb_easy_font | Quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc. |
| stb_image | Image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC |
| stb_image_resize | Resize images larger/smaller with good quality. |
| stb_image_write | Image writing to disk: PNG, TGA, BMP |
| stb_image_write | Image writing to disk: PNG, TGA, BMP |
| stb_perlin | Revised Perlin noise (3D input, 1D output). |
| stb_truetype | Parse, decode, and rasterize characters from truetype fonts. |
| stb_vorbis | Decode ogg vorbis files from file/memory to float/16-bit signed output. |

### Other

Expand Down
12 changes: 8 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import org.gradle.plugins.ide.idea.model.IdeaModel
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.utils.addToStdlib.ifTrue
import java.nio.file.Files
import kotlin.io.path.Path

Expand Down Expand Up @@ -30,6 +29,8 @@ val kotlinTargetJdkVersion: String by rootProject

val targetJavaVersion = jdkVersion.toInt()

val overrunMarshalVersion: String by rootProject

group = projGroupId
version = projVersion

Expand Down Expand Up @@ -125,27 +126,30 @@ enum class Artifact(
}

subprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "java-library")
apply(plugin = "idea")
apply(plugin = "me.champeau.jmh")
apply(plugin = "org.jetbrains.kotlin.jvm")

group = projGroupId
version = projVersion
val artifactName = "$projArtifactId${ext["subName"]}"

repositories {
mavenCentral()
maven { url = uri("https://maven.aliyun.com/repository/central") }
// temporary maven repositories
maven { url = uri("https://s01.oss.sonatype.org/content/repositories/releases") }
maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") }
maven { url = uri("https://s01.oss.sonatype.org/content/repositories/releases") }
maven { url = uri("https://maven.aliyun.com/repository/central") }
}

val annotationProcessor by configurations
val api by configurations
val compileOnly by configurations
val implementation by configurations
dependencies {
compileOnly("org.jetbrains:annotations:24.1.0")
api("io.github.over-run:marshal:$overrunMarshalVersion")
if (project.name != "core") {
implementation(project(":core"))
}
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ jdkEarlyAccessDoc=jdk22
kotlinTargetJdkVersion=21

projModules=core, glfw, nfd, joml, opengl, stb
overrunMarshalVersion=0.1.0-alpha.8-jdk22
overrunPlatformVersion=1.0.0
1 change: 1 addition & 0 deletions modules/overrungl.core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
overrungl.opengl,
overrungl.stb;

requires transitive io.github.overrun.marshal;
requires io.github.overrun.platform;
requires static org.jetbrains.annotations;
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,26 @@ public enum FunctionDescriptors {
PJp, PPI, PPP, PPp, PPV, SSV,
// 4
BBBV, DDDV, FFFV, IDDV, IFFV, IIDV, IIFV, IIII, IIIV, IIJV, IIPI, IIPV, IJJV, IPIV, IPPV, IPPZ, ISSV, PDDV, PIIP, PIIV,
PIJI, PIJP, PIJV, PIPp, PIPV, PPII, PPIP, PPJP, PPPI, PPPV, SSSV,
PIJI, PIJP, PIJV, PIPp, PIPV, PPII, PPIP, PPJP, PPPI, PPPP, PPPV, SSSV,
// 5
BBBBV, DDDDV, FFFFV, IDDDV, IFFFV, IIDDV, IIFFV, IIFIV, IIIIV, IIIJV, IIIPV, IIJIV, IIJJV, IIPIV, IIPPV, IIZIV, IIZPV,
IJJIP, IJJJV, IJJPV, IJJZV, IJPIV, IPIIV, IPIPV, IPPIV, ISSSV, PIIIP, PIIPp, PIPII, PIPIp, PIPPV, PPIPI, PPPPI, PPPPV,
IJJIP, IJJJV, IJJPV, IJJZV, IJPIV, IPIIV, IPIPV, IPPIV, ISSSV, PIIIP, PIIPp, PIPII, PIPIp, PIPPP, PIPPV, PPIPI, PPPPI, PPPPV,
SSSSV, ZZZZV,
// 6
FFFFFV, IBBBBV, IDDDDV, IFFFFV, IIDDDV, IIFFFV, IIIFIV, IIIIIV, IIIIPV, IIIJIV, IIIJJV, IIIPIV, IIIPPP, IIIPPV, IIIPZV,
IIIZIV, IIIZPV, IIJJJV, IIPIIV, IIPIPV, IIPPPP, IIPPPV, IIZIIJ, IJJJJV, IPIPIV, IPIPPV, IPJIIV, IPPIPV, ISSSSV, IZIIPV,
IZZZZV, PIIIIV, PIIIPI, PIIPIp, PIIPPV, PIPPPI, PPIIIP, PPIPPI, PPPIIV, PPPPIp, PPPPPI, PPPPPV,
IZZZZV, PIIIIV, PIIIPI, PIIPIp, PIIPPV, PIPPIP, PIPPPI, PIPPPP, PPIIIP, PPIPPI, PPPIIV, PPPPIp, PPPPPI, PPPPPV,
// 7
BBBBFFV, DDDDDDV, FFFFFFV, FFFFFIF, FFFIIIF, FFPPPII, IDDIDDV, IDDIIPV, IFFFFFV, IFFIFFV, IFFIIPV, IIDDDDV, IIFFFFV,
IIIIIIV, IIIIIPV, IIIIIZV, IIIIPPV, IIIIPZV, IIIIZIV, IIIPIIV, IIIPPIV, IIIPPPV, IIIZIPV, IIJJJJV, IIPJIIV, IPIPIPV,
PIIIIPp, PIIIPII, PIPPPIp, PPIIIPI, PPIPIIV, PPPPPIp,
PIIIIPp, PIIIPII, PIPPPIp, PPIIIPI, PPIPIIV, PPIPPPI, PPPPPIp,
// 8
BBBBFFFV, FFFFFFIF, FFFIIIBF, FFFIIIIF, IFFFFFFV, IIDDIIPV, IIFFFFPV, IIFFIIPV, IIIIIIIV, IIIIIIPV, IIIIIIZV, IIIIIPIV,
IIIPIIIV, IIIPPPPV, IIIZIIIV, IIJJIIPV, IIPIIIIV, IIPPPPPI, IIPPPPPV, PPIIIIIV,
// 9
FFFFFFFFV, IBBBBFFFV, IIIIIIIIV, IIIIIIIPV, IIIIPIPPV, IIPPPPPPI, PIPPPPPIp,
// 10
FFBBBBFFFV, FFPIIPPIII, IFFFFFFFFV, IIIIIIIIIV, IIIIIIIIPV, IIIIIIIIZV, PIIIPIIIII,
FFBBBBFFFV, IFFFFFFFFV, IIIIIIIIIV, IIIIIIIIPV, IIIIIIIIZV, PIIIPIIIII,
// 11
FFFFFFFFFFV, IDDIIDDIIPV, IFFIIFFIIPV, IIIIIIIIIIV, IIIIIIIIIPV,
// 12
Expand Down
4 changes: 2 additions & 2 deletions modules/overrungl.core/src/main/java/overrungl/OverrunGL.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2023 Overrun Organization
* Copyright (c) 2023-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 @@ -41,7 +41,7 @@ public final class OverrunGL {
/**
* The version of STB native libraries.
*/
public static final String STB_VERSION = "0.1.0.0";
public static final String STB_VERSION = "0.1.0.1";
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
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Overrun Organization
* Copyright (c) 2023 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 All @@ -14,16 +14,19 @@
* copies or substantial portions of the Software.
*/

package overrungl.stb;
package overrungl.internal;

/**
* The STB image resizer color-space
*
* @author squid233
* @since 0.1.0
*/
public enum STBIRColorspace {
LINEAR,
SRGB,
MAX_COLORSPACES
public final class Checks {
public static void arraySize(byte[] arr, int size) {
if (arr == null) {
throw new IllegalArgumentException("Expected size " + size + ", got null");
}
if (arr.length != size) {
throw new IllegalArgumentException("Expected size " + size + ", got " + arr.length);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
import overrungl.OverrunGL;
import overrungl.util.MemoryUtil;

import java.io.File;
import java.io.IOException;
import java.lang.foreign.*;
import java.lang.invoke.MethodHandle;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
Expand All @@ -50,11 +49,15 @@ public final class RuntimeHelper {
* The native linker.
*/
public static final Linker LINKER = Linker.nativeLinker();
private static final File tmpdir = new File(System.getProperty("java.io.tmpdir"));
private static final Path tmpdir = Path.of(System.getProperty("java.io.tmpdir"));
/**
* An unbounded address layout.
*/
public static final AddressLayout ADDRESS_UNBOUNDED = ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(Long.MAX_VALUE, JAVA_BYTE));
/**
* @see Configurations#CHECKS
*/
public static final boolean CHECKS = Configurations.CHECKS.get();
private static final StackWalker STACK_WALKER = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
private static final Map<String, MemoryLayout> CANONICAL_LAYOUTS = LINKER.canonicalLayouts();
public static final MemoryLayout LONG = CANONICAL_LAYOUTS.get("long"),
Expand Down Expand Up @@ -139,41 +142,44 @@ public static SymbolLookup load(String module, String basename, String version)
final Platform os = Platform.current();
final var suffix = os.sharedLibrarySuffix();
final var path = os.sharedLibraryName(basename);
URI uri;
Path uri;
// 1. Load from natives directory
var localFile = new File(System.getProperty("overrungl.natives", "."), path);
if (localFile.exists()) {
uri = localFile.toURI();
var localFile = Path.of(System.getProperty("overrungl.natives", "."), path);
if (Files.exists(localFile)) {
uri = localFile;
} else {
// 2. Load from classpath
var file = new File(tmpdir, STR."overrungl\{System.getProperty("user.name")}");
if (!file.exists()) {
// Create directory
file.mkdir();
} else if (file.isFile()) {
// Remove
file.delete();
// Create directory
file.mkdir();
var file = tmpdir.resolve(STR."overrungl\{System.getProperty("user.name")}");
try {
if (!Files.exists(file)) {
// Create directory
Files.createDirectories(file);
} else if (!Files.isDirectory(file)) {
// Remove
Files.delete(file);
// Create directory
Files.createDirectories(file);
}
} catch (IOException e) {
throw new IllegalStateException(STR."Couldn't create directory: \{file}; try setting -Doverrungl.natives to a valid path", e);
}
var libFile = new File(file, STR."\{basename}-\{version}\{suffix}");
if (!libFile.exists()) {
var libFile = file.resolve(STR."\{basename}-\{version}\{suffix}");
if (!Files.exists(libFile)) {
// Extract
final String fromPath = STR."\{module}/\{os.familyName()}/\{Architecture.current()}/\{path}";
try (var is = STACK_WALKER.getCallerClass().getClassLoader().getResourceAsStream(fromPath)) {
Files.copy(Objects.requireNonNull(is, STR."File not found: \{fromPath}"),
Path.of(libFile.getAbsolutePath()));
Files.copy(Objects.requireNonNull(is, STR."File not found in classpath: \{fromPath}"), libFile);
} catch (Exception e) {
throw new IllegalStateException(STR."File not found: \{file}; try setting property -Doverrungl.natives to a valid path", e);
throw new IllegalStateException(STR."Couldn't load file: \{libFile} or \{localFile}; try setting -Doverrungl.natives to a valid path", e);
}
}
uri = libFile.toURI();
uri = libFile;
}
if (Configurations.DEBUG.get()) {
OverrunGL.apiLog(STR."[OverrunGL] Loading native library from: \{uri}");
}
// Load the library by the path with the global arena
return SymbolLookup.libraryLookup(Path.of(uri), Arena.global());
return SymbolLookup.libraryLookup(uri, Arena.global());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import overrungl.Configurations;
import overrungl.OverrunGL;
import overrungl.Pointer;
import overrungl.internal.RuntimeHelper;

import java.lang.foreign.*;
import java.util.Arrays;
Expand All @@ -39,7 +40,6 @@
* @since 0.1.0
*/
public sealed class MemoryStack extends Pointer implements Arena {
private static final boolean CHECKS = Configurations.CHECKS.get();
private static final boolean DEBUG = Configurations.DEBUG.get();
private static final boolean DEBUG_STACK = Configurations.DEBUG_STACK.get();
private static final long DEFAULT_STACK_SIZE = Configurations.STACK_SIZE.get() * 1024;
Expand Down Expand Up @@ -289,7 +289,7 @@ public long getPointer() {
* cases or in auto-generated code.</p>
*/
public void setPointer(long pointer) {
if (CHECKS) {
if (RuntimeHelper.CHECKS) {
checkPointer(pointer);
}

Expand Down Expand Up @@ -320,7 +320,7 @@ public MemorySegment malloc(long alignment, long size) {
long address = (rawLong + pointer - size) & -alignment;

pointer = address - rawLong;
if (CHECKS && pointer < 0) {
if (RuntimeHelper.CHECKS && pointer < 0) {
throw new OutOfMemoryError("Out of stack space.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

/**
* This describes the input state of a gamepad.
*
* <h2>Layout</h2>
* <pre><code>
* struct GLFWgamepadstate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

/**
* This describes the gamma ramp for a monitor.
*
* <h2>Layout</h2>
* <pre><code>
* struct GLFWgammaramp {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
/**
* This describes a single 2D image. See the documentation for each related
* function what the expected pixel format is.
*
* <h2>Layout</h2>
* <pre><code>
* struct GLFWimage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

/**
* This is the header file of the native access functions.
*
* <h2>Native access</h2>
* <strong>By using the native access functions you assert that you know what you're
* doing and how to fix problems caused by using them. If you don't, you
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

/**
* This describes a single video mode.
*
* <h2>Layout</h2>
* <pre><code>
* struct GLFWvidmode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
/**
* This is the function pointer type for path drop callbacks. A path drop
* callback function has the following signature:
* {@snippet :
* {@snippet lang=java:
* @Invoker(IGLFWDropFun::invoke)
* void functionName(MemorySegment window, String[] paths);
* }
*
* <h2>Pointer lifetime</h2>
* The path array and its strings are valid until the callback function returns.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@
/**
* This is the function pointer type for error callbacks. An error callback
* function has the following signature:
* {@snippet :
* {@snippet lang=java:
* @Invoker(IGLFWErrorFun::invoke)
* void callbackName(int errorCode, String description);
* }
*
* <h2>Pointer lifetime</h2>
* The error description string is valid until the callback
* function returns.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

/**
* The OpenGL 4.2 draw arrays indirect command.
*
* <h2>Layout</h2>
* <pre><code>
* struct DrawArraysIndirectCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

/**
* The OpenGL 4.2 draw elements indirect command.
*
* <h2>Layout</h2>
* <pre><code>
* struct DrawElementsIndirectCommand {
Expand Down
Loading

0 comments on commit 021f949

Please sign in to comment.