-
Notifications
You must be signed in to change notification settings - Fork 0
LWJGL Interop
ExodusCoder9 edited this page Jun 20, 2026
·
1 revision
Zero-allocation interop between Jamma types and LWJGL's FloatBuffer, DoubleBuffer, and MemorySegment.
dependencies {
implementation 'com.github.ExodusCoder9:Jamma:v1.0'
implementation platform('org.lwjgl:lwjgl-bom:3.4.1')
implementation 'org.lwjgl:lwjgl'
}
OpenGL: Upload matrix to shader uniform
import static com.jamma.lwjgl.JammaLWJGL.*;
import static org.lwjgl.opengl.GL20.*;
try (var stack = MemoryStack.stackPush()) {
FloatBuffer buf = stack.mallocFloat(16);
put(matrix, buf);
buf.flip();
glUniformMatrix4fv(location, false, buf);
}
Vulkan: Push constants
try (var arena = Arena.ofConfined()) {
MemorySegment seg = arena.allocate(16 * 4);
put(matrix, seg, 0);
vkCmdPushConstants(cmdBuf, layout, stageFlags, 0, seg);
}
Vertex data
FloatBuffer buf = stack.mallocFloat(9); // 3 verts × 3 components
put(new Vector3f(1, 0, 0), buf);
put(new Vector3f(0, 1, 0), buf);
put(new Vector3f(0, 0, 1), buf);
buf.flip();
glBufferSubData(GL_ARRAY_BUFFER, 0, buf);
Reading from Assimp structs
Matrix4f boneMatrix = new Matrix4f();
get(aiBone.mOffsetMatrix().asFloatBuffer(), boneMatrix);
Available Methods
Method
Input
Output
put(Matrix4f, FloatBuffer)
Jamma type
LWJGL buffer (column-major)
put(Matrix4f, MemorySegment, long)
Jamma type
Off-heap memory
get(FloatBuffer, Matrix4f)
LWJGL buffer
Jamma type
put(Matrix4d, DoubleBuffer)
Jamma type
LWJGL buffer
put(Vector3f, FloatBuffer)
Jamma type
xyz in buffer
put(Vector3f, MemorySegment, long)
Jamma type
Off-heap memory
put(Vector4f, FloatBuffer)
Jamma type
xyzw in buffer
put(Vector2f, FloatBuffer)
Jamma type
xy in buffer
put(Quaternionf, FloatBuffer)
Jamma type
xyzw in buffer
segment(ByteBuffer/FloatBuffer/DoubleBuffer)
NIO buffer
MemorySegment
All methods are zero-allocation — they write directly into the provided buffer.