Skip to content

Commit 54af550

Browse files
committed
CustomLoader: add static newLoader() method for the typical use case
1 parent e79cfd2 commit 54af550

2 files changed

Lines changed: 23 additions & 22 deletions

File tree

src/main/java/com/github/stephengold/joltjni/CustomLoader.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ public CustomLoader() {
5252
public ByteBuffer loadShader(String shaderName) {
5353
return null;
5454
}
55+
56+
/**
57+
* Create a custom loader that loads from the specified resource directory.
58+
*
59+
* @param resourcePath the path to the resource directory (not {@code null})
60+
* @return a new loader
61+
*/
62+
public static CustomLoader newLoader(String resourcePath) {
63+
CustomLoader result = new CustomLoader() {
64+
@Override
65+
public ByteBuffer loadShader(String shaderName) {
66+
String path = resourcePath + "/" + shaderName;
67+
ByteBuffer result = Jolt.loadResourceAsBytes(path);
68+
return result;
69+
}
70+
};
71+
72+
return result;
73+
}
5574
// *************************************************************************
5675
// native private methods
5776

src/test/java/testjoltjni/app/samples/SmokeTestAll.java

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ of this software and associated documentation files (the "Software"), to deal
2525
import com.github.stephengold.joltjni.*;
2626
import com.github.stephengold.joltjni.enumerate.EPhysicsUpdateError;
2727
import com.github.stephengold.joltjni.std.OfStream;
28-
import java.nio.ByteBuffer;
2928
import testjoltjni.TestUtils;
3029
import testjoltjni.app.samples.broadphase.*;
3130
import testjoltjni.app.samples.character.*;
@@ -156,13 +155,15 @@ private static void createSharedObjects() {
156155

157156
case "Metal":
158157
// Assign a loader for Metal compute shaders:
159-
Loader mtlLoader = makeLoader("/mtl/com/github/stephengold");
158+
Loader mtlLoader = CustomLoader.newLoader(
159+
"/mtl/com/github/stephengold");
160160
computeSystem.setShaderLoader(mtlLoader);
161161
break;
162162

163163
case "Vulkan":
164164
// Assign a loader for Vulkan compute shaders:
165-
Loader vkLoader = makeLoader("/vk/com/github/stephengold");
165+
Loader vkLoader = CustomLoader.newLoader(
166+
"/vk/com/github/stephengold");
166167
computeSystem.setShaderLoader(vkLoader);
167168
break;
168169

@@ -177,25 +178,6 @@ private static void createSharedObjects() {
177178
queue = queueRef.getPtr();
178179
}
179180

180-
/**
181-
* Create a custom loader that loads from the specified resource directory.
182-
*
183-
* @param resourcePath the path to the resource directory (not {@code null})
184-
* @return a new loader
185-
*/
186-
private static Loader makeLoader(String resourcePath) {
187-
Loader result = new CustomLoader() {
188-
@Override
189-
public ByteBuffer loadShader(String shaderName) {
190-
String path = resourcePath + "/" + shaderName;
191-
ByteBuffer result = Jolt.loadResourceAsBytes(path);
192-
return result;
193-
}
194-
};
195-
196-
return result;
197-
}
198-
199181
/**
200182
* Allocate and initialize a {@code PhysicsSystem} in the customary
201183
* configuration.

0 commit comments

Comments
 (0)