Skip to content

Commit

Permalink
feat(par): add par_octasphere.h bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Spasi committed Jan 19, 2020
1 parent 4434600 commit 85176e7
Show file tree
Hide file tree
Showing 17 changed files with 1,913 additions and 125 deletions.
1 change: 1 addition & 0 deletions doc/notes/3.2.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This build includes the following changes:
- Nuklear: Updated to 4.01.5 (up from 4.01.0)
- OpenAL Soft: Updated to 1.20.0 (up from 1.19.1)
- OpenVR: Updated to 1.8.19 (up from 1.6.10)
- par: Added [par_octasphere](https://prideout.net/blog/octasphere/) bindings.
- rpmalloc: Updated to 1.4.1 pre-release (up from 1.4.0)
- tinyfiledialogs: Updated to 3.4.3 (up from 3.3.9)
- vma: Updated to 2.3.0 (up from 2.2.0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
* MACHINE GENERATED FILE, DO NOT EDIT
*/
#include "common_tools.h"
#define PAR_OCTASPHERE_IMPLEMENTATION
#include "par_octasphere.h"

EXTERN_C_ENTER

JNIEXPORT void JNICALL Java_org_lwjgl_util_par_ParOctasphere_npar_1octasphere_1get_1counts__JJJ(JNIEnv *__env, jclass clazz, jlong configAddress, jlong num_indicesAddress, jlong num_verticesAddress) {
par_octasphere_config const *config = (par_octasphere_config const *)(intptr_t)configAddress;
uint32_t *num_indices = (uint32_t *)(intptr_t)num_indicesAddress;
uint32_t *num_vertices = (uint32_t *)(intptr_t)num_verticesAddress;
UNUSED_PARAMS(__env, clazz)
par_octasphere_get_counts(config, num_indices, num_vertices);
}

JNIEXPORT void JNICALL Java_org_lwjgl_util_par_ParOctasphere_npar_1octasphere_1populate(JNIEnv *__env, jclass clazz, jlong configAddress, jlong meshAddress) {
par_octasphere_config const *config = (par_octasphere_config const *)(intptr_t)configAddress;
par_octasphere_mesh *mesh = (par_octasphere_mesh *)(intptr_t)meshAddress;
UNUSED_PARAMS(__env, clazz)
par_octasphere_populate(config, mesh);
}

JNIEXPORT void JNICALL Java_org_lwjgl_util_par_ParOctasphere_npar_1octasphere_1get_1counts__J_3I_3I(JNIEnv *__env, jclass clazz, jlong configAddress, jintArray num_indicesAddress, jintArray num_verticesAddress) {
par_octasphere_config const *config = (par_octasphere_config const *)(intptr_t)configAddress;
jint *num_indices = (*__env)->GetIntArrayElements(__env, num_indicesAddress, NULL);
jint *num_vertices = (*__env)->GetIntArrayElements(__env, num_verticesAddress, NULL);
UNUSED_PARAMS(__env, clazz)
par_octasphere_get_counts(config, (uint32_t *)num_indices, (uint32_t *)num_vertices);
(*__env)->ReleaseIntArrayElements(__env, num_verticesAddress, num_vertices, 0);
(*__env)->ReleaseIntArrayElements(__env, num_indicesAddress, num_indices, 0);
}

EXTERN_C_EXIT
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_util_par_ParShapes_npar_1shapes_1create_1
return (jlong)(intptr_t)par_shapes_create_rock(seed, nsubdivisions);
}

JNIEXPORT jlong JNICALL Java_org_lwjgl_util_par_ParShapes_npar_1shapes_1create_1lsystem(JNIEnv *__env, jclass clazz, jlong programAddress, jint slices, jint maxdepth) {
JNIEXPORT jlong JNICALL Java_org_lwjgl_util_par_ParShapes_npar_1shapes_1create_1lsystem(JNIEnv *__env, jclass clazz, jlong programAddress, jint slices, jint maxdepth, jlong rand_fnAddress, jlong contextAddress) {
char const *program = (char const *)(intptr_t)programAddress;
par_shapes_rand_fn rand_fn = (par_shapes_rand_fn)(intptr_t)rand_fnAddress;
void *context = (void *)(intptr_t)contextAddress;
UNUSED_PARAMS(__env, clazz)
return (jlong)(intptr_t)par_shapes_create_lsystem(program, slices, maxdepth);
return (jlong)(intptr_t)par_shapes_create_lsystem(program, slices, maxdepth, rand_fn, context);
}

JNIEXPORT void JNICALL Java_org_lwjgl_util_par_ParShapes_npar_1shapes_1export(JNIEnv *__env, jclass clazz, jlong meshAddress, jlong objfileAddress) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
* MACHINE GENERATED FILE, DO NOT EDIT
*/
package org.lwjgl.util.par;

import java.nio.*;

import org.lwjgl.system.*;

import static org.lwjgl.system.Checks.*;
import static org.lwjgl.system.MemoryUtil.*;

/**
* Bindings to <a target="_blank" href="https://prideout.net/blog/octasphere">par_octasphere.h</a>, a tiny malloc-free library that generates triangle meshes for spheres,
* rounded boxes, and capsules.
*
* <p>Usage example:</p>
*
* <pre><code>
* // Specify a 100x100x20 rounded box.
* const par_octasphere_config cfg = {
* .corner_radius = 5,
* .width = 100,
* .height = 100,
* .depth = 20,
* .num_subdivisions = 3,
* };
*
* // Allocate memory for the mesh and opt-out of normals.
* uint32_t num_indices;
* uint32_t num_vertices;
* par_octasphere_get_counts(&amp;cfg, &amp;num_indices, &amp;num_vertices);
* par_octasphere_mesh mesh = {
* .positions = malloc(sizeof(float) * 3 * num_vertices),
* .normals = NULL,
* .texcoords = malloc(sizeof(float) * 2 * num_vertices),
* .indices = malloc(sizeof(uint16_t) * num_indices),
* };
*
* // Generate vertex coordinates, UV's, and triangle indices.
* par_octasphere_populate(&amp;cfg, &amp;mesh);</code></pre>
*
* <p>To generate a sphere: set width, height, and depth to 0 in your configuration. To generate a capsule shape: set only two of these dimensions to 0.</p>
*/
public class ParOctasphere {

public static final int par_octasphere_PAR_OCTASPHERE_MAX_SUBDIVISIONS = 5;

/** {@code par_octasphere_uv_mode} */
public static final int par_octasphere_UV_LATLONG = 0;

/** {@code par_octasphere_normals_mode} */
public static final int par_octasphere_NORMALS_SMOOTH = 0;

static { LibPar.initialize(); }

protected ParOctasphere() {
throw new UnsupportedOperationException();
}

// --- [ par_octasphere_get_counts ] ---

/** Unsafe version of: {@link #par_octasphere_get_counts get_counts} */
public static native void npar_octasphere_get_counts(long config, long num_indices, long num_vertices);

/** Computes the maximum possible number of indices and vertices for the given octasphere config. */
public static void par_octasphere_get_counts(@NativeType("par_octasphere_config const *") ParOctasphereConfig config, @NativeType("uint32_t *") IntBuffer num_indices, @NativeType("uint32_t *") IntBuffer num_vertices) {
if (CHECKS) {
check(num_indices, 1);
check(num_vertices, 1);
}
npar_octasphere_get_counts(config.address(), memAddress(num_indices), memAddress(num_vertices));
}

// --- [ par_octasphere_populate ] ---

/** Unsafe version of: {@link #par_octasphere_populate populate} */
public static native void npar_octasphere_populate(long config, long mesh);

/** Populates a pre-allocated mesh structure with indices and vertices. */
public static void par_octasphere_populate(@NativeType("par_octasphere_config const *") ParOctasphereConfig config, @NativeType("par_octasphere_mesh *") ParOctasphereMesh mesh) {
npar_octasphere_populate(config.address(), mesh.address());
}

/** Array version of: {@link #npar_octasphere_get_counts} */
public static native void npar_octasphere_get_counts(long config, int[] num_indices, int[] num_vertices);

/** Array version of: {@link #par_octasphere_get_counts get_counts} */
public static void par_octasphere_get_counts(@NativeType("par_octasphere_config const *") ParOctasphereConfig config, @NativeType("uint32_t *") int[] num_indices, @NativeType("uint32_t *") int[] num_vertices) {
if (CHECKS) {
check(num_indices, 1);
check(num_vertices, 1);
}
npar_octasphere_get_counts(config.address(), num_indices, num_vertices);
}

}
Loading

0 comments on commit 85176e7

Please sign in to comment.