Skip to content

Commit

Permalink
Fix a issue with gl calls. Create array only if some data changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
xpenatan committed Aug 30, 2024
1 parent a694dcf commit c4ec6cd
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit c4ec6cd

Please sign in to comment.