More accurate validation on gl vertex attributes

This CL has more accurate validation for gl vertex attributes, and is
more tolerable if the user forgot to disable some vertex attribute
arrays.

Change-Id: I6bb205add25bf51f0ba70a5cb267c3319a17a842
diff --git a/system/GLESv2_enc/GL2Encoder.cpp b/system/GLESv2_enc/GL2Encoder.cpp
index 544c8cc..78051d4 100755
--- a/system/GLESv2_enc/GL2Encoder.cpp
+++ b/system/GLESv2_enc/GL2Encoder.cpp
@@ -653,6 +653,12 @@
             int firstIndex = stride * first;
 
             if (state->bufferObject == 0) {
+                if (state->elementSize == 0) {
+                    // The vertex attribute array is uninitialized. Abandon it.
+                    ALOGE("a vertex attribute array is uninitialized. Skipping corresponding vertex attribute.");
+                    this->m_glDisableVertexAttribArray_enc(this, i);
+                    continue;
+                }
                 m_glEnableVertexAttribArray_enc(this, i);
                 this->glVertexAttribPointerData(this, i, state->size, state->type, state->normalized, state->stride,
                                                 (unsigned char *)state->data + firstIndex, datalen);
@@ -720,22 +726,6 @@
     SET_ERROR_IF(!isValidDrawMode(mode), GL_INVALID_ENUM);
     SET_ERROR_IF(count < 0, GL_INVALID_VALUE);
 
-    bool has_arrays = false;
-    int nLocations = ctx->m_state->nLocations();
-    for (int i = 0; i < nLocations; i++) {
-        const GLClientState::VertexAttribState *state = ctx->m_state->getState(i);
-        if (state->enabled) {
-            if (state->bufferObject || state->data)  {
-                has_arrays = true;
-            }
-            else {
-                ALOGE("glDrawArrays: a vertex attribute array is enabled with no data bound\n");
-                ctx->setError(GL_INVALID_OPERATION);
-                return;
-            }
-        }
-    }
-
     ctx->sendVertexAttributes(first, count);
     ctx->m_glDrawArrays_enc(ctx, mode, 0, count);
     ctx->m_stream->flush();
@@ -763,19 +753,14 @@
                 has_indirect_arrays = true;
             } else if (state->data) {
                 has_immediate_arrays = true;
-            } else {
-                ALOGW("glDrawElements: a vertex attribute array is enabled with no data bound\n");
-                ctx->setError(GL_INVALID_OPERATION);
-                return;
             }
         }
     }
 
     if (!has_immediate_arrays && !has_indirect_arrays) {
-        ALOGE("glDrawElements: no data bound to the command - ignoring\n");
+        ALOGW("glDrawElements: no vertex arrays / buffers bound to the command\n");
         GLenum status = ctx->m_glCheckFramebufferStatus_enc(self, GL_FRAMEBUFFER);
         SET_ERROR_IF(status != GL_FRAMEBUFFER_COMPLETE, GL_INVALID_FRAMEBUFFER_OPERATION);
-        return;
     }
 
     BufferData* buf = NULL;