Skip to content

Commit d2269f3

Browse files
committed
android sync from desktop gl
1 parent 3eec84d commit d2269f3

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

core/src/processing/opengl/Texture.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -882,17 +882,15 @@ public void disposeSourceBuffer() {
882882
}
883883

884884
public void getBufferPixels(int[] pixels) {
885-
boolean addToUsed = false;
885+
// We get the buffer either from the used buffers or the cache, giving
886+
// priority to the used buffers. Why? Because the used buffer was already
887+
// transferred to the texture, so the pixels should be in sync with the
888+
// texture.
886889
BufferData data = null;
887890
if (usedBuffers != null && 0 < usedBuffers.size()) {
888-
// the last used buffer is the one currently stored in the opengl
889-
// texture
890891
data = usedBuffers.getLast();
891892
} else if (bufferCache != null && 0 < bufferCache.size()) {
892-
// The first buffer in the cache will be uploaded to the opengl texture
893-
// the next time it is rendered
894-
data = bufferCache.remove(0);
895-
addToUsed = true;
893+
data = bufferCache.getLast();
896894
}
897895
if (data != null) {
898896
if ((data.w != width) || (data.h != height)) {
@@ -903,10 +901,14 @@ public void getBufferPixels(int[] pixels) {
903901
data.rgbBuf.get(pixels);
904902
convertToARGB(pixels);
905903

906-
if (addToUsed) {
907-
if (usedBuffers == null) {
908-
usedBuffers = new LinkedList<BufferData>();
909-
}
904+
// In order to avoid a cached buffer to overwrite the texture when the
905+
// renderer draws the texture, and hence put the pixels put of sync, we
906+
// simply empty the cache.
907+
if (usedBuffers == null) {
908+
usedBuffers = new LinkedList<BufferData>();
909+
}
910+
while (0 < bufferCache.size()) {
911+
data = bufferCache.remove(0);
910912
usedBuffers.add(data);
911913
}
912914
}

0 commit comments

Comments
 (0)