GLES1: Fix material color update when COLOR_MATERIAL

According to the spec, when COLOR_MATERIAL is enabled, the material
ambient and diffuse colors are updated on every glClear* call.
Additionally, setting these values individually is ineffective when
COLOR_MATERIAL is enabled.

Bug: angleproject:6201
Change-Id: I846513c983254a043ea83101c0f83025c12b4364
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3906392
Reviewed-by: Cody Northrop <cnorthrop@google.com>
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
diff --git a/src/libANGLE/GLES1State.cpp b/src/libANGLE/GLES1State.cpp
index 5fa0883e..17ad0de 100644
--- a/src/libANGLE/GLES1State.cpp
+++ b/src/libANGLE/GLES1State.cpp
@@ -201,6 +201,19 @@
 {
     setDirty(DIRTY_GLES1_CURRENT_VECTOR);
     mCurrentColor = color;
+
+    // > When enabled, both the ambient (acm) and diffuse (dcm) properties of both the front and
+    // > back material are immediately set to the value of the current color, and will track changes
+    // > to the current color resulting from either the Color commands or drawing vertex arrays with
+    // > the color array enabled.
+    // > The replacements made to material properties are permanent; the replaced values remain
+    // > until changed by either sending a new color or by setting a new material value when
+    // > COLOR_MATERIAL is not currently enabled, to override that particular value.
+    if (isColorMaterialEnabled())
+    {
+        mMaterial.ambient = color;
+        mMaterial.diffuse = color;
+    }
 }
 
 const ColorF &GLES1State::getCurrentColor() const
diff --git a/src/libANGLE/queryutils.cpp b/src/libANGLE/queryutils.cpp
index d6b5f29..94fafc1 100644
--- a/src/libANGLE/queryutils.cpp
+++ b/src/libANGLE/queryutils.cpp
@@ -2442,18 +2442,34 @@
                            MaterialParameter pname,
                            const GLfloat *params)
 {
+    // Note: Ambient and diffuse colors are inherited from glColor when COLOR_MATERIAL is enabled,
+    // and can only be modified by this function if that is disabled:
+    //
+    // > the replaced values remain until changed by either sending a new color or by setting a
+    // > new material value when COLOR_MATERIAL is not currently enabled, to override that
+    // particular value.
+
     MaterialParameters &material = state->materialParameters();
     switch (pname)
     {
         case MaterialParameter::Ambient:
-            material.ambient = ColorF::fromData(params);
+            if (!state->isColorMaterialEnabled())
+            {
+                material.ambient = ColorF::fromData(params);
+            }
             break;
         case MaterialParameter::Diffuse:
-            material.diffuse = ColorF::fromData(params);
+            if (!state->isColorMaterialEnabled())
+            {
+                material.diffuse = ColorF::fromData(params);
+            }
             break;
         case MaterialParameter::AmbientAndDiffuse:
-            material.ambient = ColorF::fromData(params);
-            material.diffuse = ColorF::fromData(params);
+            if (!state->isColorMaterialEnabled())
+            {
+                material.ambient = ColorF::fromData(params);
+                material.diffuse = ColorF::fromData(params);
+            }
             break;
         case MaterialParameter::Specular:
             material.specular = ColorF::fromData(params);