Skip to content
This repository was archived by the owner on Jun 12, 2019. It is now read-only.

Commit 0570612

Browse files
committed
Lifted the vertex limit of the native drawer - the buffer now gets enlarged as needed.
Signed-off-by: Patrick Dinklage <pdinklag@googlemail.com>
1 parent 834e4ff commit 0570612

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

src/java/org/jsfml/graphics/SFMLNativeDrawer.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,22 @@
1010
*/
1111
final class SFMLNativeDrawer {
1212
private static final int NATIVE_VERTEX_SIZE = 20;
13-
private static final int MAX_VERTICES = 1024;
1413

15-
private static final ThreadLocal<ByteBuffer> vertexBuffer = new ThreadLocal<ByteBuffer>() {
16-
@Override
17-
protected ByteBuffer initialValue() {
18-
return ByteBuffer.allocateDirect(MAX_VERTICES * NATIVE_VERTEX_SIZE).order(ByteOrder.nativeOrder());
14+
private static final ThreadLocal<ByteBuffer> vertexBuffer = new ThreadLocal<ByteBuffer>();
15+
16+
static {
17+
ensureBuffer(1024);
18+
}
19+
20+
private static ByteBuffer ensureBuffer(int numVertices) {
21+
ByteBuffer buffer = vertexBuffer.get();
22+
if(buffer == null || (buffer.capacity() / NATIVE_VERTEX_SIZE) < numVertices) {
23+
buffer = ByteBuffer.allocateDirect(numVertices * NATIVE_VERTEX_SIZE).order(ByteOrder.nativeOrder());
24+
vertexBuffer.set(buffer);
1925
}
20-
};
26+
27+
return buffer;
28+
}
2129

2230
private static native void nativeDrawVertices(
2331
int num,
@@ -30,7 +38,7 @@ private static native void nativeDrawVertices(
3038
ConstShader shader);
3139

3240
static void drawVertices(Vertex[] vertices, PrimitiveType type, RenderTarget target, RenderStates states) {
33-
final ByteBuffer vbuf = vertexBuffer.get();
41+
final ByteBuffer vbuf = ensureBuffer(vertices.length);
3442
final FloatBuffer vfloats = vbuf.asFloatBuffer();
3543
final IntBuffer vints = vbuf.asIntBuffer();
3644

0 commit comments

Comments
 (0)