xref: /aosp_15_r20/external/angle/src/tests/gl_tests/gles1/ColorMaterialTest.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2022 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // ColorMaterialTest.cpp: Tests basic usage of texture environments.
8 
9 #include "test_utils/ANGLETest.h"
10 #include "test_utils/gl_raii.h"
11 
12 #include "util/random_utils.h"
13 
14 #include <stdint.h>
15 
16 using namespace angle;
17 
18 class ColorMaterialTest : public ANGLETest<>
19 {
20   protected:
ColorMaterialTest()21     ColorMaterialTest()
22     {
23         setWindowWidth(32);
24         setWindowHeight(32);
25         setConfigRedBits(8);
26         setConfigGreenBits(8);
27         setConfigBlueBits(8);
28         setConfigAlphaBits(8);
29         setConfigDepthBits(24);
30     }
31 };
32 
33 // Ensure that when GL_COLOR_MATERIAL is enabled, material properties are
34 // inherited from glColor4f
TEST_P(ColorMaterialTest,ColorMaterialOn)35 TEST_P(ColorMaterialTest, ColorMaterialOn)
36 {
37     std::array<GLfloat, 4> expected = {0.1f, 0.2f, 0.3f, 0.4f};
38 
39     glColor4f(0.1f, 0.2f, 0.3f, 0.4f);
40 
41     std::array<GLfloat, 4> ambientAndDiffuse = {0.3f, 0.2f, 0.1f, 1.0f};
42     glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, ambientAndDiffuse.data());
43 
44     glEnable(GL_COLOR_MATERIAL);
45 
46     std::array<GLfloat, 4> ambient = {};
47     glGetMaterialfv(GL_FRONT, GL_AMBIENT, ambient.data());
48 
49     std::array<GLfloat, 4> diffuse = {};
50     glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse.data());
51 
52     EXPECT_EQ(ambient, expected);
53     EXPECT_EQ(diffuse, expected);
54 }
55 
56 // Ensure that when GL_COLOR_MATERIAL is disabled, material properties are
57 // inherited from glMaterialfv
TEST_P(ColorMaterialTest,ColorMaterialOff)58 TEST_P(ColorMaterialTest, ColorMaterialOff)
59 {
60     std::array<GLfloat, 4> expectedAmbientAndDiffuse = {0.3f, 0.2f, 0.1f, 1.0f};
61     glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, expectedAmbientAndDiffuse.data());
62 
63     glColor4f(0.1f, 0.2f, 0.3f, 0.4f);
64 
65     std::array<GLfloat, 4> ambient = {};
66     glGetMaterialfv(GL_FRONT, GL_AMBIENT, ambient.data());
67 
68     std::array<GLfloat, 4> diffuse = {};
69     glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse.data());
70 
71     EXPECT_EQ(ambient, expectedAmbientAndDiffuse);
72 }
73 
74 ANGLE_INSTANTIATE_TEST_ES1(ColorMaterialTest);
75