Skip to content

Commit

Permalink
feat(core) add MemoryStack.pointersOfElements(CustomBuffer)
Browse files Browse the repository at this point in the history
  • Loading branch information
httpdigest authored and Spasi committed Mar 2, 2022
1 parent 8567ff1 commit 6b6327a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions modules/lwjgl/core/src/main/java/org/lwjgl/system/MemoryStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,27 @@ public PointerBuffer pointers(Buffer... values) {

// -------------------------------------------------

/**
* Allocates a new {@link PointerBuffer} of size {@code buffer.remaining()}
* and fills it with the addresses of the values within the provided {@link CustomBuffer}
* starting at {@code buffer.position()}.
*
* @param buffer the {@link CustomBuffer} to obtain its element addresses of
* @return a {@link PointerBuffer} containing the buffer's element addresses
*/
public PointerBuffer pointersOfElements(CustomBuffer<?> buffer) {
int remaining = buffer.remaining();
long addr = buffer.address();
long sizeof = buffer.sizeof();
PointerBuffer pointerBuffer = mallocPointer(remaining);
for (int i = 0; i < remaining; i++) {
pointerBuffer.put(i, addr + sizeof * i);
}
return pointerBuffer;
}

// -------------------------------------------------

/**
* Encodes the specified text on the stack using ASCII encoding and returns a {@code ByteBuffer} that points to the encoded text, including a
* null-terminator.
Expand Down

0 comments on commit 6b6327a

Please sign in to comment.