opengl: GLEncoder: Fix potential array buffer misbinding

When encoding a glDrawElements() or glDrawArrays() call, the encoder
needs to figure out whether each array (e.g. vertex, color, etc.) uses
a bound buffer or not. It is possible that some arrays use bound buffers
while others immediate buffers. In this case, there is a chance that the
encoder fails to preserve the semantics of the input GLES calls,
resulting in misinterpretation by the translator that all arrays use
bound buffers.

Fix this by encoding an unbind operation before any glXXXPointer() call
that does not mean to use a bound buffer. For GLESv2, that is already
done:

 40a674e Fix emulator crashes on glDrawElements command

This CL does the same for GLESv1.

Change-Id: Ifd17321b124a4f4b1037a43d5a54094541d367f1
Signed-off-by: Yu Ning <yu.ning@intel.com>
diff --git a/opengl/system/GLESv1_enc/GLEncoder.cpp b/opengl/system/GLESv1_enc/GLEncoder.cpp
index d6f45a8..a1bce63 100644
--- a/opengl/system/GLESv1_enc/GLEncoder.cpp
+++ b/opengl/system/GLESv1_enc/GLEncoder.cpp
@@ -421,6 +421,7 @@
             if (stride == 0) stride = state->elementSize;
             int firstIndex = stride * first;
 
+            this->m_glBindBuffer_enc(this, GL_ARRAY_BUFFER, state->bufferObject);
             if (state->bufferObject == 0) {
 
                 switch(i) {
@@ -461,7 +462,6 @@
                     break;
                 }
             } else {
-                this->m_glBindBuffer_enc(this, GL_ARRAY_BUFFER, state->bufferObject);
 
                 switch(i) {
                 case GLClientState::VERTEX_LOCATION:
@@ -500,8 +500,8 @@
                                               (uintptr_t)state->data+firstIndex);
                     break;
                 }
-                this->m_glBindBuffer_enc(this, GL_ARRAY_BUFFER, m_state->currentArrayVbo());
             }
+            this->m_glBindBuffer_enc(this, GL_ARRAY_BUFFER, m_state->currentArrayVbo());
         } else {
             this->m_glDisableClientState_enc(this, state->glConst);
         }