Skip to content

Commit 2915518

Browse files
committed
reduce allocations
1 parent a844f84 commit 2915518

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

  • jme3-ios/src/main/java/com/jme3/renderer/ios

jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ private static void checkLimit(Buffer buffer) {
8484
throw new RendererException("Attempting to upload empty buffer (remaining = 0), that's an error");
8585
}
8686
}
87+
88+
private byte[] stringToCAscii(String value) {
89+
if (tempByteArray.length < value.length() + 1) {
90+
tempByteArray = new byte[value.length() + 1];
91+
}
92+
93+
for (int i = 0; i < value.length(); i++) {
94+
char ch = value.charAt(i);
95+
if (ch > 0x7f) {
96+
throw new IllegalArgumentException("GL names must be ASCII");
97+
}
98+
tempByteArray[i] = (byte) ch;
99+
}
100+
101+
tempByteArray[value.length()] = 0;
102+
return tempByteArray;
103+
}
87104

88105
@Override
89106
public void glActiveTexture(int texture) {
@@ -328,13 +345,7 @@ public void glGenQueries(int num, IntBuffer buff) {
328345

329346
@Override
330347
public int glGetAttribLocation(int program, String name) {
331-
byte[] bytes = name.getBytes(StandardCharsets.UTF_8);
332-
if (tempByteArray.length < bytes.length + 1) {
333-
tempByteArray = new byte[bytes.length + 1];
334-
}
335-
System.arraycopy(bytes, 0, tempByteArray, 0, bytes.length);
336-
tempByteArray[bytes.length] = 0;
337-
return GLES.glGetAttribLocation(program, tempByteArray);
348+
return GLES.glGetAttribLocation(program, stringToCAscii(name));
338349
}
339350

340351
@Override
@@ -465,13 +476,7 @@ public String glGetString(int name) {
465476

466477
@Override
467478
public int glGetUniformLocation(int program, String name) {
468-
byte[] bytes = name.getBytes(StandardCharsets.UTF_8);
469-
if (tempByteArray.length < bytes.length + 1) {
470-
tempByteArray = new byte[bytes.length + 1];
471-
}
472-
System.arraycopy(bytes, 0, tempByteArray, 0, bytes.length);
473-
tempByteArray[bytes.length] = 0;
474-
return GLES.glGetUniformLocation(program, tempByteArray);
479+
return GLES.glGetUniformLocation(program, stringToCAscii(name));
475480
}
476481

477482
@Override

0 commit comments

Comments
 (0)