From c4ec6cd9a9d2e300f1c191145854754208a9eaa7 Mon Sep 17 00:00:00 2001 From: Natan Date: Thu, 29 Aug 2024 21:38:19 -0300 Subject: [PATCH] Fix a issue with gl calls. Create array only if some data changes. --- .../classlib/java/nio/ByteBufferImplEmu.java | 16 +--------------- .../java/nio/FloatBufferOverArrayEmu.java | 16 +--------------- .../java/nio/FloatBufferOverByteBufferEmu.java | 15 ++++++--------- .../classlib/java/nio/IntBufferOverArrayEmu.java | 16 +--------------- .../java/nio/IntBufferOverByteBufferEmu.java | 15 ++++++--------- .../java/nio/ShortBufferOverArrayEmu.java | 16 +--------------- .../java/nio/ShortBufferOverByteBufferEmu.java | 15 +++++++-------- .../imgui/example/tests/imgui/ImGuiTestsApp.java | 4 ++-- 8 files changed, 25 insertions(+), 88 deletions(-) diff --git a/backends/backend-teavm/emu/org/teavm/classlib/java/nio/ByteBufferImplEmu.java b/backends/backend-teavm/emu/org/teavm/classlib/java/nio/ByteBufferImplEmu.java index 82414472..7ed3bbfe 100644 --- a/backends/backend-teavm/emu/org/teavm/classlib/java/nio/ByteBufferImplEmu.java +++ b/backends/backend-teavm/emu/org/teavm/classlib/java/nio/ByteBufferImplEmu.java @@ -9,13 +9,6 @@ @Emulate(valueStr = "java.nio.ByteBufferImpl", updateCode = true) public abstract class ByteBufferImplEmu extends TByteBufferImpl implements HasArrayBufferView { - @Emulate - Int8ArrayWrapper backupArray; - @Emulate - int positionCache; - @Emulate - int remainingCache; - public ByteBufferImplEmu(int start, int capacity, byte[] array, int position, int limit, boolean direct, boolean readOnly) { super(start, capacity, array, position, limit, direct, readOnly); } @@ -24,14 +17,7 @@ public ByteBufferImplEmu(int start, int capacity, byte[] array, int position, in @Emulate public ArrayBufferViewWrapper getArrayBufferView() { Int8ArrayWrapper int8Array = (Int8ArrayWrapper)getOriginalArrayBufferView(); - int position1 = position(); - int remaining1 = remaining(); - if(backupArray == null || positionCache != position1 || remaining1 != remainingCache) { - positionCache = position1; - remainingCache = remaining1; - backupArray = int8Array.subarray(position1, remaining1); - } - return backupArray; + return int8Array; } @Override diff --git a/backends/backend-teavm/emu/org/teavm/classlib/java/nio/FloatBufferOverArrayEmu.java b/backends/backend-teavm/emu/org/teavm/classlib/java/nio/FloatBufferOverArrayEmu.java index 5418dc7b..a61e4b0a 100644 --- a/backends/backend-teavm/emu/org/teavm/classlib/java/nio/FloatBufferOverArrayEmu.java +++ b/backends/backend-teavm/emu/org/teavm/classlib/java/nio/FloatBufferOverArrayEmu.java @@ -8,13 +8,6 @@ @Emulate(valueStr = "java.nio.TFloatBufferOverArray", updateCode = true) public abstract class FloatBufferOverArrayEmu extends TFloatBufferOverArray implements HasArrayBufferView { - @Emulate - Float32ArrayWrapper backupArray; - @Emulate - int positionCache; - @Emulate - int remainingCache; - public FloatBufferOverArrayEmu(int start, int capacity, float[] array, int position, int limit, boolean readOnly) { super(start, capacity, array, position, limit, readOnly); } @@ -23,14 +16,7 @@ public FloatBufferOverArrayEmu(int start, int capacity, float[] array, int posit @Emulate public ArrayBufferViewWrapper getArrayBufferView() { Float32ArrayWrapper originalBuffer = (Float32ArrayWrapper)getOriginalArrayBufferView(); - int position1 = position(); - int remaining1 = remaining(); - if(backupArray == null || positionCache != position1 || remaining1 != remainingCache) { - positionCache = position1; - remainingCache = remaining1; - backupArray = originalBuffer.subarray(position1, remaining1); - } - return backupArray; + return originalBuffer; } @Override diff --git a/backends/backend-teavm/emu/org/teavm/classlib/java/nio/FloatBufferOverByteBufferEmu.java b/backends/backend-teavm/emu/org/teavm/classlib/java/nio/FloatBufferOverByteBufferEmu.java index f3d44665..008eb6b7 100644 --- a/backends/backend-teavm/emu/org/teavm/classlib/java/nio/FloatBufferOverByteBufferEmu.java +++ b/backends/backend-teavm/emu/org/teavm/classlib/java/nio/FloatBufferOverByteBufferEmu.java @@ -9,14 +9,14 @@ @Emulate(valueStr = "java.nio.FloatBufferOverByteBuffer", updateCode = true) public abstract class FloatBufferOverByteBufferEmu extends TFloatBufferOverByteBuffer implements HasArrayBufferView { - @Emulate - Float32ArrayWrapper backupArray; @Emulate Float32ArrayWrapper floatArray; @Emulate int positionCache; @Emulate int remainingCache; + @Emulate + int capacityCache; public FloatBufferOverByteBufferEmu(int start, int capacity, TByteBufferImpl byteBuffer, int position, int limit, boolean readOnly) { super(start, capacity, byteBuffer, position, limit, readOnly); @@ -27,18 +27,15 @@ public FloatBufferOverByteBufferEmu(int start, int capacity, TByteBufferImpl byt public ArrayBufferViewWrapper getArrayBufferView() { // Int8Array Int8ArrayWrapper int8Array = (Int8ArrayWrapper)getOriginalArrayBufferView(); - if(floatArray == null) { - floatArray = TypedArrays.createFloat32Array(int8Array.getBuffer()); - } - int position1 = position(); int remaining1 = remaining(); - if(backupArray == null || positionCache != position1 || remaining1 != remainingCache) { + int capacity1 = capacity(); + if(positionCache != position1 || remainingCache != remaining1 || capacityCache != capacity1) { + floatArray = TypedArrays.createFloat32Array(int8Array.getBuffer()); positionCache = position1; remainingCache = remaining1; - backupArray = floatArray.subarray(position1, remaining1); } - return backupArray; + return floatArray; } @Override diff --git a/backends/backend-teavm/emu/org/teavm/classlib/java/nio/IntBufferOverArrayEmu.java b/backends/backend-teavm/emu/org/teavm/classlib/java/nio/IntBufferOverArrayEmu.java index 778238c9..b618ef9f 100644 --- a/backends/backend-teavm/emu/org/teavm/classlib/java/nio/IntBufferOverArrayEmu.java +++ b/backends/backend-teavm/emu/org/teavm/classlib/java/nio/IntBufferOverArrayEmu.java @@ -8,13 +8,6 @@ @Emulate(valueStr = "java.nio.TIntBufferOverArray", updateCode = true) public abstract class IntBufferOverArrayEmu extends TIntBufferOverArray implements HasArrayBufferView { - @Emulate - Int32ArrayWrapper backupArray; - @Emulate - int positionCache; - @Emulate - int remainingCache; - public IntBufferOverArrayEmu(int start, int capacity, int[] array, int position, int limit, boolean readOnly) { super(start, capacity, array, position, limit, readOnly); } @@ -23,14 +16,7 @@ public IntBufferOverArrayEmu(int start, int capacity, int[] array, int position, @Emulate public ArrayBufferViewWrapper getArrayBufferView() { Int32ArrayWrapper originalBuffer = (Int32ArrayWrapper)getOriginalArrayBufferView(); - int position1 = position(); - int remaining1 = remaining(); - if(backupArray == null || positionCache != position1 || remaining1 != remainingCache) { - positionCache = position1; - remainingCache = remaining1; - backupArray = originalBuffer.subarray(position1, remaining1); - } - return backupArray; + return originalBuffer; } @Override diff --git a/backends/backend-teavm/emu/org/teavm/classlib/java/nio/IntBufferOverByteBufferEmu.java b/backends/backend-teavm/emu/org/teavm/classlib/java/nio/IntBufferOverByteBufferEmu.java index 92a4da2c..88900aa6 100644 --- a/backends/backend-teavm/emu/org/teavm/classlib/java/nio/IntBufferOverByteBufferEmu.java +++ b/backends/backend-teavm/emu/org/teavm/classlib/java/nio/IntBufferOverByteBufferEmu.java @@ -9,15 +9,14 @@ @Emulate(valueStr = "java.nio.IntBufferOverByteBuffer", updateCode = true) public abstract class IntBufferOverByteBufferEmu extends TIntBufferOverByteBuffer implements HasArrayBufferView { - @Emulate - Int32ArrayWrapper backupArray; @Emulate Int32ArrayWrapper intArray; @Emulate int positionCache; @Emulate int remainingCache; - + @Emulate + int capacityCache; public IntBufferOverByteBufferEmu(int start, int capacity, TByteBufferImpl byteBuffer, int position, int limit, boolean readOnly) { super(start, capacity, byteBuffer, position, limit, readOnly); @@ -28,17 +27,15 @@ public IntBufferOverByteBufferEmu(int start, int capacity, TByteBufferImpl byteB public ArrayBufferViewWrapper getArrayBufferView() { // Int8Array Int8ArrayWrapper int8Array = (Int8ArrayWrapper)getOriginalArrayBufferView(); - if(intArray == null) { - intArray = TypedArrays.createInt32Array(int8Array.getBuffer()); - } int position1 = position(); int remaining1 = remaining(); - if(backupArray == null || positionCache != position1 || remaining1 != remainingCache) { + int capacity1 = capacity(); + if(positionCache != position1 || remainingCache != remaining1 || capacityCache != capacity1) { + intArray = TypedArrays.createInt32Array(int8Array.getBuffer()); positionCache = position1; remainingCache = remaining1; - backupArray = intArray.subarray(position1, remaining1); } - return backupArray; + return intArray; } @Override diff --git a/backends/backend-teavm/emu/org/teavm/classlib/java/nio/ShortBufferOverArrayEmu.java b/backends/backend-teavm/emu/org/teavm/classlib/java/nio/ShortBufferOverArrayEmu.java index 379a37e9..02582b69 100644 --- a/backends/backend-teavm/emu/org/teavm/classlib/java/nio/ShortBufferOverArrayEmu.java +++ b/backends/backend-teavm/emu/org/teavm/classlib/java/nio/ShortBufferOverArrayEmu.java @@ -8,13 +8,6 @@ @Emulate(valueStr = "java.nio.TShortBufferOverArray", updateCode = true) public abstract class ShortBufferOverArrayEmu extends TShortBufferOverArray implements HasArrayBufferView { - @Emulate - Int16ArrayWrapper backupArray; - @Emulate - int positionCache; - @Emulate - int remainingCache; - public ShortBufferOverArrayEmu(int start, int capacity, short[] array, int position, int limit, boolean readOnly) { super(start, capacity, array, position, limit, readOnly); } @@ -23,14 +16,7 @@ public ShortBufferOverArrayEmu(int start, int capacity, short[] array, int posit @Emulate public ArrayBufferViewWrapper getArrayBufferView() { Int16ArrayWrapper originalBuffer = (Int16ArrayWrapper)getOriginalArrayBufferView(); - int position1 = position(); - int remaining1 = remaining(); - if(backupArray == null || positionCache != position1 || remaining1 != remainingCache) { - positionCache = position1; - remainingCache = remaining1; - backupArray = originalBuffer.subarray(position1, remaining1); - } - return backupArray; + return originalBuffer; } @Override diff --git a/backends/backend-teavm/emu/org/teavm/classlib/java/nio/ShortBufferOverByteBufferEmu.java b/backends/backend-teavm/emu/org/teavm/classlib/java/nio/ShortBufferOverByteBufferEmu.java index fc0cedb3..1d293cb8 100644 --- a/backends/backend-teavm/emu/org/teavm/classlib/java/nio/ShortBufferOverByteBufferEmu.java +++ b/backends/backend-teavm/emu/org/teavm/classlib/java/nio/ShortBufferOverByteBufferEmu.java @@ -9,14 +9,14 @@ @Emulate(valueStr = "java.nio.ShortBufferOverByteBuffer", updateCode = true) public abstract class ShortBufferOverByteBufferEmu extends TShortBufferOverByteBuffer implements HasArrayBufferView { - @Emulate - Int16ArrayWrapper backupArray; @Emulate Int16ArrayWrapper shortArray; @Emulate int positionCache; @Emulate int remainingCache; + @Emulate + int capacityCache; public ShortBufferOverByteBufferEmu(int start, int capacity, TByteBufferImpl byteBuffer, int position, int limit, boolean readOnly) { super(start, capacity, byteBuffer, position, limit, readOnly); @@ -27,17 +27,16 @@ public ShortBufferOverByteBufferEmu(int start, int capacity, TByteBufferImpl byt public ArrayBufferViewWrapper getArrayBufferView() { // Int8Array Int8ArrayWrapper int8Array = (Int8ArrayWrapper)getOriginalArrayBufferView(); - if(shortArray == null) { - shortArray = TypedArrays.createInt16Array(int8Array.getBuffer()); - } int position1 = position(); int remaining1 = remaining(); - if(backupArray == null || positionCache != position1 || remaining1 != remainingCache) { + int capacity1 = capacity(); + if(positionCache != position1 || remainingCache != remaining1 || capacityCache != capacity1) { + shortArray = TypedArrays.createInt16Array(int8Array.getBuffer()); positionCache = position1; remainingCache = remaining1; - backupArray = shortArray.subarray(position1, remaining1); + capacityCache = capacity1; } - return backupArray; + return shortArray; } @Override diff --git a/examples/gdx-tests/core/src/main/java/com/github/xpenatan/imgui/example/tests/imgui/ImGuiTestsApp.java b/examples/gdx-tests/core/src/main/java/com/github/xpenatan/imgui/example/tests/imgui/ImGuiTestsApp.java index 1b37ea16..5c31551a 100644 --- a/examples/gdx-tests/core/src/main/java/com/github/xpenatan/imgui/example/tests/imgui/ImGuiTestsApp.java +++ b/examples/gdx-tests/core/src/main/java/com/github/xpenatan/imgui/example/tests/imgui/ImGuiTestsApp.java @@ -48,7 +48,7 @@ public void show() { ImGui.CreateContext(); ImGuiIO io = ImGui.GetIO(); - io.ConfigFlags(ImGuiConfigFlags.ImGuiConfigFlags_DockingEnable); + io.set_ConfigFlags(ImGuiConfigFlags.ImGuiConfigFlags_DockingEnable); input = new ImGuiGdxInputMultiplexer(); impl = new ImGuiGdxImpl(); @@ -125,7 +125,7 @@ public void render(float delta) { Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - impl.update(); + impl.newFrame(); drawTestListWindow();