GLES1: Client vertex array pointer API

glVertexPointer
glNormalPointer
glColorPointer
glPointSizePointerOES
glTexCoordPointer

BUG=angleproject:2306

Change-Id: Id022b467ac998ea116130c5cec0c77afefb0dd4c
Reviewed-on: https://chromium-review.googlesource.com/1014381
Commit-Queue: Lingfeng Yang <lfy@google.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/validationES1.cpp b/src/libANGLE/validationES1.cpp
index 6a7730f..7b0a80b 100644
--- a/src/libANGLE/validationES1.cpp
+++ b/src/libANGLE/validationES1.cpp
@@ -23,18 +23,18 @@
 namespace gl
 {
 
-bool ValidateAlphaFuncCommon(gl::Context *context, gl::AlphaTestFunc func)
+bool ValidateAlphaFuncCommon(Context *context, AlphaTestFunc func)
 {
     switch (func)
     {
-        case gl::AlphaTestFunc::AlwaysPass:
-        case gl::AlphaTestFunc::Equal:
-        case gl::AlphaTestFunc::Gequal:
-        case gl::AlphaTestFunc::Greater:
-        case gl::AlphaTestFunc::Lequal:
-        case gl::AlphaTestFunc::Less:
-        case gl::AlphaTestFunc::Never:
-        case gl::AlphaTestFunc::NotEqual:
+        case AlphaTestFunc::AlwaysPass:
+        case AlphaTestFunc::Equal:
+        case AlphaTestFunc::Gequal:
+        case AlphaTestFunc::Greater:
+        case AlphaTestFunc::Lequal:
+        case AlphaTestFunc::Less:
+        case AlphaTestFunc::Never:
+        case AlphaTestFunc::NotEqual:
             return true;
         default:
             ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported);
@@ -42,17 +42,17 @@
     }
 }
 
-bool ValidateClientStateCommon(gl::Context *context, gl::ClientVertexArrayType arrayType)
+bool ValidateClientStateCommon(Context *context, ClientVertexArrayType arrayType)
 {
     ANGLE_VALIDATE_IS_GLES1(context);
     switch (arrayType)
     {
-        case gl::ClientVertexArrayType::Vertex:
-        case gl::ClientVertexArrayType::Normal:
-        case gl::ClientVertexArrayType::Color:
-        case gl::ClientVertexArrayType::TextureCoord:
+        case ClientVertexArrayType::Vertex:
+        case ClientVertexArrayType::Normal:
+        case ClientVertexArrayType::Color:
+        case ClientVertexArrayType::TextureCoord:
             return true;
-        case gl::ClientVertexArrayType::PointSize:
+        case ClientVertexArrayType::PointSize:
             if (!context->getExtensions().pointSizeArray)
             {
                 ANGLE_VALIDATION_ERR(context, InvalidEnum(), PointSizeArrayExtensionNotEnabled);
@@ -65,6 +65,88 @@
     }
 }
 
+bool ValidateBuiltinVertexAttributeCommon(Context *context,
+                                          ClientVertexArrayType arrayType,
+                                          GLint size,
+                                          GLenum type,
+                                          GLsizei stride,
+                                          const void *pointer)
+{
+    ANGLE_VALIDATE_IS_GLES1(context);
+
+    if (stride < 0)
+    {
+        ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidVertexPointerStride);
+        return false;
+    }
+
+    int minSize = 1;
+    int maxSize = 4;
+
+    switch (arrayType)
+    {
+        case ClientVertexArrayType::Vertex:
+        case ClientVertexArrayType::TextureCoord:
+            minSize = 2;
+            maxSize = 4;
+            break;
+        case ClientVertexArrayType::Normal:
+            minSize = 3;
+            maxSize = 3;
+            break;
+        case ClientVertexArrayType::Color:
+            minSize = 4;
+            maxSize = 4;
+            break;
+        case ClientVertexArrayType::PointSize:
+            if (!context->getExtensions().pointSizeArray)
+            {
+                ANGLE_VALIDATION_ERR(context, InvalidEnum(), PointSizeArrayExtensionNotEnabled);
+                return false;
+            }
+
+            minSize = 1;
+            maxSize = 1;
+            break;
+        default:
+            UNREACHABLE();
+            return false;
+    }
+
+    if (size < minSize || size > maxSize)
+    {
+        ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidVertexPointerSize);
+        return false;
+    }
+
+    switch (type)
+    {
+        case GL_BYTE:
+            if (arrayType == ClientVertexArrayType::PointSize)
+            {
+                ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidVertexPointerType);
+                return false;
+            }
+            break;
+        case GL_SHORT:
+            if (arrayType == ClientVertexArrayType::PointSize ||
+                arrayType == ClientVertexArrayType::Color)
+            {
+                ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidVertexPointerType);
+                return false;
+            }
+            break;
+        case GL_FIXED:
+        case GL_FLOAT:
+            break;
+        default:
+            ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidVertexPointerType);
+            return false;
+    }
+
+    return true;
+}
+
 }  // namespace gl
 
 namespace gl
@@ -136,8 +218,8 @@
                           GLsizei stride,
                           const void *pointer)
 {
-    UNIMPLEMENTED();
-    return true;
+    return ValidateBuiltinVertexAttributeCommon(context, ClientVertexArrayType::Color, size, type,
+                                                stride, pointer);
 }
 
 bool ValidateCullFace(Context *context, GLenum mode)
@@ -268,8 +350,19 @@
 
 bool ValidateGetPointerv(Context *context, GLenum pname, void **params)
 {
-    UNIMPLEMENTED();
-    return true;
+    ANGLE_VALIDATE_IS_GLES1(context);
+    switch (pname)
+    {
+        case GL_VERTEX_ARRAY_POINTER:
+        case GL_NORMAL_ARRAY_POINTER:
+        case GL_COLOR_ARRAY_POINTER:
+        case GL_TEXTURE_COORD_ARRAY_POINTER:
+        case GL_POINT_SIZE_ARRAY_POINTER_OES:
+            return true;
+        default:
+            ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPointerQuery);
+            return false;
+    }
 }
 
 bool ValidateGetTexEnvfv(Context *context, GLenum target, GLenum pname, GLfloat *params)
@@ -461,8 +554,8 @@
 
 bool ValidateNormalPointer(Context *context, GLenum type, GLsizei stride, const void *pointer)
 {
-    UNIMPLEMENTED();
-    return true;
+    return ValidateBuiltinVertexAttributeCommon(context, ClientVertexArrayType::Normal, 3, type,
+                                                stride, pointer);
 }
 
 bool ValidateOrthof(Context *context,
@@ -605,8 +698,8 @@
                              GLsizei stride,
                              const void *pointer)
 {
-    UNIMPLEMENTED();
-    return true;
+    return ValidateBuiltinVertexAttributeCommon(context, ClientVertexArrayType::TextureCoord, size,
+                                                type, stride, pointer);
 }
 
 bool ValidateTexEnvf(Context *context, GLenum target, GLenum pname, GLfloat param)
@@ -678,8 +771,8 @@
                            GLsizei stride,
                            const void *pointer)
 {
-    UNIMPLEMENTED();
-    return true;
+    return ValidateBuiltinVertexAttributeCommon(context, ClientVertexArrayType::Vertex, size, type,
+                                                stride, pointer);
 }
 
 bool ValidateDrawTexfOES(Context *context,
@@ -779,8 +872,8 @@
 
 bool ValidatePointSizePointerOES(Context *context, GLenum type, GLsizei stride, const void *pointer)
 {
-    UNIMPLEMENTED();
-    return true;
+    return ValidateBuiltinVertexAttributeCommon(context, ClientVertexArrayType::PointSize, 1, type,
+                                                stride, pointer);
 }
 
 bool ValidateQueryMatrixxOES(Context *context, GLfixed *mantissa, GLint *exponent)