mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 07:26:48 +01:00
Finally free
- Free from mojmath, have to flip many matrix field accesses. - Free the memory allocated in model cache. - Shout out to pepper's DebugMemoryBlock telling me *exactly* where a leak was from. - Instancing and batching seem to mostly work, indirect appears to be rendering instances in the wrong places, though they are culled from their real location.
This commit is contained in:
parent
7b0b1883ed
commit
5e42ecc1c6
2 changed files with 28 additions and 27 deletions
|
@ -11,27 +11,27 @@ import org.lwjgl.system.MemoryUtil;
|
|||
|
||||
public final class MatrixUtil {
|
||||
public static float transformPositionX(Matrix4f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m00(), x, fma(matrix.m01(), y, fma(matrix.m02(), z, matrix.m03())));
|
||||
return fma(matrix.m00(), x, fma(matrix.m10(), y, fma(matrix.m20(), z, matrix.m30())));
|
||||
}
|
||||
|
||||
public static float transformPositionY(Matrix4f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m10(), x, fma(matrix.m11(), y, fma(matrix.m12(), z, matrix.m13())));
|
||||
return fma(matrix.m01(), x, fma(matrix.m11(), y, fma(matrix.m21(), z, matrix.m31())));
|
||||
}
|
||||
|
||||
public static float transformPositionZ(Matrix4f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m20(), x, fma(matrix.m21(), y, fma(matrix.m22(), z, matrix.m23())));
|
||||
return fma(matrix.m02(), x, fma(matrix.m12(), y, fma(matrix.m22(), z, matrix.m32())));
|
||||
}
|
||||
|
||||
public static float transformNormalX(Matrix3f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m00(), x, fma(matrix.m01(), y, matrix.m02() * z));
|
||||
return fma(matrix.m00(), x, fma(matrix.m10(), y, matrix.m20() * z));
|
||||
}
|
||||
|
||||
public static float transformNormalY(Matrix3f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m10(), x, fma(matrix.m11(), y, matrix.m12() * z));
|
||||
return fma(matrix.m01(), x, fma(matrix.m11(), y, matrix.m21() * z));
|
||||
}
|
||||
|
||||
public static float transformNormalZ(Matrix3f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m20(), x, fma(matrix.m21(), y, matrix.m22() * z));
|
||||
return fma(matrix.m02(), x, fma(matrix.m12(), y, matrix.m22() * z));
|
||||
}
|
||||
|
||||
public static void write(Matrix4f matrix, ByteBuffer buf) {
|
||||
|
@ -40,20 +40,20 @@ public final class MatrixUtil {
|
|||
|
||||
public static void writeUnsafe(Matrix4f matrix, long ptr) {
|
||||
MemoryUtil.memPutFloat(ptr, matrix.m00());
|
||||
MemoryUtil.memPutFloat(ptr + 4, matrix.m10());
|
||||
MemoryUtil.memPutFloat(ptr + 8, matrix.m20());
|
||||
MemoryUtil.memPutFloat(ptr + 12, matrix.m30());
|
||||
MemoryUtil.memPutFloat(ptr + 16, matrix.m01());
|
||||
MemoryUtil.memPutFloat(ptr + 4, matrix.m01());
|
||||
MemoryUtil.memPutFloat(ptr + 8, matrix.m02());
|
||||
MemoryUtil.memPutFloat(ptr + 12, matrix.m03());
|
||||
MemoryUtil.memPutFloat(ptr + 16, matrix.m10());
|
||||
MemoryUtil.memPutFloat(ptr + 20, matrix.m11());
|
||||
MemoryUtil.memPutFloat(ptr + 24, matrix.m21());
|
||||
MemoryUtil.memPutFloat(ptr + 28, matrix.m31());
|
||||
MemoryUtil.memPutFloat(ptr + 32, matrix.m02());
|
||||
MemoryUtil.memPutFloat(ptr + 36, matrix.m12());
|
||||
MemoryUtil.memPutFloat(ptr + 24, matrix.m12());
|
||||
MemoryUtil.memPutFloat(ptr + 28, matrix.m13());
|
||||
MemoryUtil.memPutFloat(ptr + 32, matrix.m20());
|
||||
MemoryUtil.memPutFloat(ptr + 36, matrix.m21());
|
||||
MemoryUtil.memPutFloat(ptr + 40, matrix.m22());
|
||||
MemoryUtil.memPutFloat(ptr + 44, matrix.m32());
|
||||
MemoryUtil.memPutFloat(ptr + 48, matrix.m03());
|
||||
MemoryUtil.memPutFloat(ptr + 52, matrix.m13());
|
||||
MemoryUtil.memPutFloat(ptr + 56, matrix.m23());
|
||||
MemoryUtil.memPutFloat(ptr + 44, matrix.m23());
|
||||
MemoryUtil.memPutFloat(ptr + 48, matrix.m30());
|
||||
MemoryUtil.memPutFloat(ptr + 52, matrix.m31());
|
||||
MemoryUtil.memPutFloat(ptr + 56, matrix.m32());
|
||||
MemoryUtil.memPutFloat(ptr + 60, matrix.m33());
|
||||
}
|
||||
|
||||
|
@ -63,13 +63,13 @@ public final class MatrixUtil {
|
|||
|
||||
public static void writeUnsafe(Matrix3f matrix, long ptr) {
|
||||
MemoryUtil.memPutFloat(ptr, matrix.m00());
|
||||
MemoryUtil.memPutFloat(ptr + 4, matrix.m10());
|
||||
MemoryUtil.memPutFloat(ptr + 8, matrix.m20());
|
||||
MemoryUtil.memPutFloat(ptr + 12, matrix.m01());
|
||||
MemoryUtil.memPutFloat(ptr + 4, matrix.m01());
|
||||
MemoryUtil.memPutFloat(ptr + 8, matrix.m02());
|
||||
MemoryUtil.memPutFloat(ptr + 12, matrix.m10());
|
||||
MemoryUtil.memPutFloat(ptr + 16, matrix.m11());
|
||||
MemoryUtil.memPutFloat(ptr + 20, matrix.m21());
|
||||
MemoryUtil.memPutFloat(ptr + 24, matrix.m02());
|
||||
MemoryUtil.memPutFloat(ptr + 28, matrix.m12());
|
||||
MemoryUtil.memPutFloat(ptr + 20, matrix.m12());
|
||||
MemoryUtil.memPutFloat(ptr + 24, matrix.m20());
|
||||
MemoryUtil.memPutFloat(ptr + 28, matrix.m21());
|
||||
MemoryUtil.memPutFloat(ptr + 32, matrix.m22());
|
||||
}
|
||||
|
||||
|
@ -96,9 +96,9 @@ public final class MatrixUtil {
|
|||
* @return The greatest scale factor across all axes.
|
||||
*/
|
||||
public static float extractScale(Matrix4f matrix) {
|
||||
float scaleSqrX = matrix.m00() * matrix.m00() + matrix.m01() * matrix.m01() + matrix.m02() * matrix.m02();
|
||||
float scaleSqrY = matrix.m10() * matrix.m10() + matrix.m11() * matrix.m11() + matrix.m12() * matrix.m12();
|
||||
float scaleSqrZ = matrix.m20() * matrix.m20() + matrix.m21() * matrix.m21() + matrix.m22() * matrix.m22();
|
||||
float scaleSqrX = matrix.m00() * matrix.m00() + matrix.m10() * matrix.m10() + matrix.m20() * matrix.m20();
|
||||
float scaleSqrY = matrix.m01() * matrix.m01() + matrix.m11() * matrix.m11() + matrix.m21() * matrix.m21();
|
||||
float scaleSqrZ = matrix.m02() * matrix.m02() + matrix.m12() * matrix.m12() + matrix.m22() * matrix.m22();
|
||||
return Math.sqrt(Math.max(Math.max(scaleSqrX, scaleSqrY), scaleSqrZ));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ public class ModelCache<T> {
|
|||
}
|
||||
|
||||
public void clear() {
|
||||
map.values().forEach(Model::delete);
|
||||
map.clear();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue