@@ -882,17 +882,15 @@ public void disposeSourceBuffer() {
882
882
}
883
883
884
884
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.
886
889
BufferData data = null ;
887
890
if (usedBuffers != null && 0 < usedBuffers .size ()) {
888
- // the last used buffer is the one currently stored in the opengl
889
- // texture
890
891
data = usedBuffers .getLast ();
891
892
} 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 ();
896
894
}
897
895
if (data != null ) {
898
896
if ((data .w != width ) || (data .h != height )) {
@@ -903,10 +901,14 @@ public void getBufferPixels(int[] pixels) {
903
901
data .rgbBuf .get (pixels );
904
902
convertToARGB (pixels );
905
903
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 );
910
912
usedBuffers .add (data );
911
913
}
912
914
}
0 commit comments