Reland "GLES1: Entry points for lighting and materials"

This is a reland of 4a09c1a245c406e402b3996b7ed33798b897e60f

Entry points have been autogenerated again.

Original change's description:
> GLES1: Entry points for lighting and materials
>
> - glLight*/glMaterial and their queries
> - Use new packed enums in these entry points, except for lightmodel
> which stays GLenum to be consistent with other generic glGet's
> - State.cpp: New glGet* queries related to light model and
> light/normal rescale enablement
> - GLES1State.cpp: Functions to get/set lighting/material state
> - Validation for lighting/materials
>
> + Add a few convenience methods to random_utils for sampling
> non-negative floats and a sampler for random booleans
>
> BUG=angleproject:2306
>
> Change-Id: If7ba0c0a0dc75f88fbaa986b904f1ea96ee6512e
> Reviewed-on: https://chromium-review.googlesource.com/1065502
> Commit-Queue: Lingfeng Yang <lfy@google.com>
> Reviewed-by: Geoff Lang <geofflang@chromium.org>

Bug: angleproject:2306
Change-Id: I434273acd5200dd9f4925e239a032cc8db31a434
Reviewed-on: https://chromium-review.googlesource.com/1072849
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Lingfeng Yang <lfy@google.com>
diff --git a/src/libANGLE/validationES1.cpp b/src/libANGLE/validationES1.cpp
index 7b0a80b..10d1cbe 100644
--- a/src/libANGLE/validationES1.cpp
+++ b/src/libANGLE/validationES1.cpp
@@ -11,6 +11,8 @@
 #include "common/debug.h"
 #include "libANGLE/Context.h"
 #include "libANGLE/ErrorStrings.h"
+#include "libANGLE/GLES1State.h"
+#include "libANGLE/queryutils.h"
 #include "libANGLE/validationES.h"
 
 #define ANGLE_VALIDATE_IS_GLES1(context)                              \
@@ -147,6 +149,173 @@
     return true;
 }
 
+bool ValidateLightCaps(Context *context, GLenum light)
+{
+    if (light < GL_LIGHT0 || light >= GL_LIGHT0 + context->getCaps().maxLights)
+    {
+        ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidLight);
+        return false;
+    }
+
+    return true;
+}
+
+bool ValidateLightCommon(Context *context,
+                         GLenum light,
+                         LightParameter pname,
+                         const GLfloat *params)
+{
+
+    ANGLE_VALIDATE_IS_GLES1(context);
+
+    if (!ValidateLightCaps(context, light))
+    {
+        return false;
+    }
+
+    switch (pname)
+    {
+        case LightParameter::Ambient:
+        case LightParameter::Diffuse:
+        case LightParameter::Specular:
+        case LightParameter::Position:
+        case LightParameter::SpotDirection:
+            return true;
+        case LightParameter::SpotExponent:
+            if (params[0] < 0.0f || params[0] > 128.0f)
+            {
+                ANGLE_VALIDATION_ERR(context, InvalidValue(), LightParameterOutOfRange);
+                return false;
+            }
+            return true;
+        case LightParameter::SpotCutoff:
+            if (params[0] == 180.0f)
+            {
+                return true;
+            }
+            if (params[0] < 0.0f || params[0] > 90.0f)
+            {
+                ANGLE_VALIDATION_ERR(context, InvalidValue(), LightParameterOutOfRange);
+                return false;
+            }
+            return true;
+        case LightParameter::ConstantAttenuation:
+        case LightParameter::LinearAttenuation:
+        case LightParameter::QuadraticAttenuation:
+            if (params[0] < 0.0f)
+            {
+                ANGLE_VALIDATION_ERR(context, InvalidValue(), LightParameterOutOfRange);
+                return false;
+            }
+            return true;
+        default:
+            ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidLightParameter);
+            return false;
+    }
+}
+
+bool ValidateLightSingleComponent(Context *context,
+                                  GLenum light,
+                                  LightParameter pname,
+                                  GLfloat param)
+{
+    if (!ValidateLightCommon(context, light, pname, &param))
+    {
+        return false;
+    }
+
+    if (GetLightParameterCount(pname) > 1)
+    {
+        ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidLightParameter);
+        return false;
+    }
+
+    return true;
+}
+
+bool ValidateMaterialCommon(Context *context,
+                            GLenum face,
+                            MaterialParameter pname,
+                            const GLfloat *params)
+{
+    ANGLE_VALIDATE_IS_GLES1(context);
+
+    if (face != GL_FRONT_AND_BACK)
+    {
+        ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidMaterialFace);
+        return false;
+    }
+
+    switch (pname)
+    {
+        case MaterialParameter::Ambient:
+        case MaterialParameter::Diffuse:
+        case MaterialParameter::Specular:
+        case MaterialParameter::Emission:
+            return true;
+        case MaterialParameter::Shininess:
+            if (params[0] < 0.0f || params[0] > 128.0f)
+            {
+                ANGLE_VALIDATION_ERR(context, InvalidValue(), MaterialParameterOutOfRange);
+                return false;
+            }
+            return true;
+        default:
+            ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidMaterialParameter);
+            return false;
+    }
+}
+
+bool ValidateMaterialSingleComponent(Context *context,
+                                     GLenum face,
+                                     MaterialParameter pname,
+                                     GLfloat param)
+{
+    if (!ValidateMaterialCommon(context, face, pname, &param))
+    {
+        return false;
+    }
+
+    if (GetMaterialParameterCount(pname) > 1)
+    {
+        ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidMaterialParameter);
+        return false;
+    }
+
+    return true;
+}
+
+bool ValidateLightModelCommon(Context *context, GLenum pname)
+{
+    ANGLE_VALIDATE_IS_GLES1(context);
+    switch (pname)
+    {
+        case GL_LIGHT_MODEL_AMBIENT:
+        case GL_LIGHT_MODEL_TWO_SIDE:
+            return true;
+        default:
+            ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidLightModelParameter);
+            return false;
+    }
+}
+
+bool ValidateLightModelSingleComponent(Context *context, GLenum pname)
+{
+    if (!ValidateLightModelCommon(context, pname))
+    {
+        return false;
+    }
+
+    switch (pname)
+    {
+        case GL_LIGHT_MODEL_TWO_SIDE:
+            return true;
+        default:
+            ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidLightModelParameter);
+            return false;
+    }
+}
+
 }  // namespace gl
 
 namespace gl
@@ -324,28 +493,28 @@
     return true;
 }
 
-bool ValidateGetLightfv(Context *context, GLenum light, GLenum pname, GLfloat *params)
+bool ValidateGetLightfv(Context *context, GLenum light, LightParameter pname, GLfloat *params)
 {
-    UNIMPLEMENTED();
-    return true;
+    GLfloat dummyParams[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+    return ValidateLightCommon(context, light, pname, dummyParams);
 }
 
-bool ValidateGetLightxv(Context *context, GLenum light, GLenum pname, GLfixed *params)
+bool ValidateGetLightxv(Context *context, GLenum light, LightParameter pname, GLfixed *params)
 {
-    UNIMPLEMENTED();
-    return true;
+    GLfloat dummyParams[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+    return ValidateLightCommon(context, light, pname, dummyParams);
 }
 
-bool ValidateGetMaterialfv(Context *context, GLenum face, GLenum pname, GLfloat *params)
+bool ValidateGetMaterialfv(Context *context, GLenum face, MaterialParameter pname, GLfloat *params)
 {
-    UNIMPLEMENTED();
-    return true;
+    GLfloat dummyParams[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+    return ValidateMaterialCommon(context, face, pname, dummyParams);
 }
 
-bool ValidateGetMaterialxv(Context *context, GLenum face, GLenum pname, GLfixed *params)
+bool ValidateGetMaterialxv(Context *context, GLenum face, MaterialParameter pname, GLfixed *params)
 {
-    UNIMPLEMENTED();
-    return true;
+    GLfloat dummyParams[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+    return ValidateMaterialCommon(context, face, pname, dummyParams);
 }
 
 bool ValidateGetPointerv(Context *context, GLenum pname, void **params)
@@ -391,50 +560,48 @@
 
 bool ValidateLightModelf(Context *context, GLenum pname, GLfloat param)
 {
-    UNIMPLEMENTED();
-    return true;
+    return ValidateLightModelSingleComponent(context, pname);
 }
 
 bool ValidateLightModelfv(Context *context, GLenum pname, const GLfloat *params)
 {
-    UNIMPLEMENTED();
-    return true;
+    return ValidateLightModelCommon(context, pname);
 }
 
 bool ValidateLightModelx(Context *context, GLenum pname, GLfixed param)
 {
-    UNIMPLEMENTED();
-    return true;
+    return ValidateLightModelSingleComponent(context, pname);
 }
 
 bool ValidateLightModelxv(Context *context, GLenum pname, const GLfixed *param)
 {
-    UNIMPLEMENTED();
-    return true;
+    return ValidateLightModelCommon(context, pname);
 }
 
-bool ValidateLightf(Context *context, GLenum light, GLenum pname, GLfloat param)
+bool ValidateLightf(Context *context, GLenum light, LightParameter pname, GLfloat param)
 {
-    UNIMPLEMENTED();
-    return true;
+    return ValidateLightSingleComponent(context, light, pname, param);
 }
 
-bool ValidateLightfv(Context *context, GLenum light, GLenum pname, const GLfloat *params)
+bool ValidateLightfv(Context *context, GLenum light, LightParameter pname, const GLfloat *params)
 {
-    UNIMPLEMENTED();
-    return true;
+    return ValidateLightCommon(context, light, pname, params);
 }
 
-bool ValidateLightx(Context *context, GLenum light, GLenum pname, GLfixed param)
+bool ValidateLightx(Context *context, GLenum light, LightParameter pname, GLfixed param)
 {
-    UNIMPLEMENTED();
-    return true;
+    return ValidateLightSingleComponent(context, light, pname, FixedToFloat(param));
 }
 
-bool ValidateLightxv(Context *context, GLenum light, GLenum pname, const GLfixed *params)
+bool ValidateLightxv(Context *context, GLenum light, LightParameter pname, const GLfixed *params)
 {
-    UNIMPLEMENTED();
-    return true;
+    GLfloat paramsf[4];
+    for (unsigned int i = 0; i < GetLightParameterCount(pname); i++)
+    {
+        paramsf[i] = FixedToFloat(params[i]);
+    }
+
+    return ValidateLightCommon(context, light, pname, paramsf);
 }
 
 bool ValidateLineWidthx(Context *context, GLfixed width)
@@ -467,28 +634,37 @@
     return true;
 }
 
-bool ValidateMaterialf(Context *context, GLenum face, GLenum pname, GLfloat param)
+bool ValidateMaterialf(Context *context, GLenum face, MaterialParameter pname, GLfloat param)
 {
-    UNIMPLEMENTED();
-    return true;
+    return ValidateMaterialSingleComponent(context, face, pname, param);
 }
 
-bool ValidateMaterialfv(Context *context, GLenum face, GLenum pname, const GLfloat *params)
+bool ValidateMaterialfv(Context *context,
+                        GLenum face,
+                        MaterialParameter pname,
+                        const GLfloat *params)
 {
-    UNIMPLEMENTED();
-    return true;
+    return ValidateMaterialCommon(context, face, pname, params);
 }
 
-bool ValidateMaterialx(Context *context, GLenum face, GLenum pname, GLfixed param)
+bool ValidateMaterialx(Context *context, GLenum face, MaterialParameter pname, GLfixed param)
 {
-    UNIMPLEMENTED();
-    return true;
+    return ValidateMaterialSingleComponent(context, face, pname, FixedToFloat(param));
 }
 
-bool ValidateMaterialxv(Context *context, GLenum face, GLenum pname, const GLfixed *param)
+bool ValidateMaterialxv(Context *context,
+                        GLenum face,
+                        MaterialParameter pname,
+                        const GLfixed *params)
 {
-    UNIMPLEMENTED();
-    return true;
+    GLfloat paramsf[4];
+
+    for (unsigned int i = 0; i < GetMaterialParameterCount(pname); i++)
+    {
+        paramsf[i] = FixedToFloat(params[i]);
+    }
+
+    return ValidateMaterialCommon(context, face, pname, paramsf);
 }
 
 bool ValidateMatrixMode(Context *context, MatrixType mode)