1 //
2 // Copyright 2018 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 // MaterialsTest.cpp: Tests basic usage of glMaterial*.
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 #include <vector>
17
18 using namespace angle;
19
20 class MaterialsTest : public ANGLETest<>
21 {
22 protected:
MaterialsTest()23 MaterialsTest()
24 {
25 setWindowWidth(32);
26 setWindowHeight(32);
27 setConfigRedBits(8);
28 setConfigGreenBits(8);
29 setConfigBlueBits(8);
30 setConfigAlphaBits(8);
31 setConfigDepthBits(24);
32 }
33 };
34
35 // Check that the initial material state is correct.
TEST_P(MaterialsTest,InitialState)36 TEST_P(MaterialsTest, InitialState)
37 {
38 const GLColor32F kAmbientInitial(0.2f, 0.2f, 0.2f, 1.0f);
39 const GLColor32F kDiffuseInitial(0.8f, 0.8f, 0.8f, 1.0f);
40 const GLColor32F kSpecularInitial(0.0f, 0.0f, 0.0f, 1.0f);
41 const GLColor32F kEmissiveInitial(0.0f, 0.0f, 0.0f, 1.0f);
42 const float kShininessInitial = 0.0f;
43
44 GLColor32F actualColor;
45 float actualShininess;
46
47 std::vector<GLenum> pnames = {
48 GL_AMBIENT,
49 GL_DIFFUSE,
50 GL_SPECULAR,
51 GL_EMISSION,
52 };
53
54 std::vector<GLColor32F> colors = {
55 kAmbientInitial,
56 kDiffuseInitial,
57 kSpecularInitial,
58 kEmissiveInitial,
59 };
60
61 for (size_t i = 0; i < pnames.size(); i++)
62 {
63 glGetMaterialfv(GL_FRONT, pnames[i], &actualColor.R);
64 EXPECT_GL_NO_ERROR();
65 EXPECT_EQ(colors[i], actualColor);
66 }
67
68 glGetMaterialfv(GL_FRONT, GL_SHININESS, &actualShininess);
69 EXPECT_GL_NO_ERROR();
70 EXPECT_EQ(kShininessInitial, actualShininess);
71 }
72
73 // Check for invalid parameter names.
TEST_P(MaterialsTest,InvalidParameter)74 TEST_P(MaterialsTest, InvalidParameter)
75 {
76 glGetMaterialfv(GL_FRONT, 0, nullptr);
77 EXPECT_GL_ERROR(GL_INVALID_ENUM);
78
79 glGetMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, nullptr);
80 EXPECT_GL_ERROR(GL_INVALID_ENUM);
81
82 glMaterialf(GL_FRONT_AND_BACK, GL_AMBIENT, 0.0f);
83 EXPECT_GL_ERROR(GL_INVALID_ENUM);
84
85 glMaterialfv(GL_FRONT, GL_AMBIENT, nullptr);
86 EXPECT_GL_ERROR(GL_INVALID_ENUM);
87 }
88
89 // Check that material parameters can be set.
TEST_P(MaterialsTest,SetParameters)90 TEST_P(MaterialsTest, SetParameters)
91 {
92 const GLColor32F kAmbientTestValue(1.0f, 1.0f, 1.0f, 1.0f);
93 const GLColor32F kDiffuseTestValue(0.0f, 0.0f, 0.0f, 0.0f);
94 const GLColor32F kSpecularTestValue(0.5f, 0.5f, 0.5f, 0.5f);
95 const GLColor32F kEmissiveTestValue(0.4f, 0.4f, 0.4f, 0.4f);
96 const float kShininessTestValue = 1.0f;
97
98 std::vector<GLenum> pnames = {
99 GL_AMBIENT,
100 GL_DIFFUSE,
101 GL_SPECULAR,
102 GL_EMISSION,
103 };
104
105 std::vector<GLColor32F> colors = {
106 kAmbientTestValue,
107 kDiffuseTestValue,
108 kSpecularTestValue,
109 kEmissiveTestValue,
110 };
111
112 GLColor32F actualColor;
113 float actualShininess;
114
115 for (size_t i = 0; i < pnames.size(); i++)
116 {
117 glMaterialfv(GL_FRONT_AND_BACK, pnames[i], &colors[i].R);
118 EXPECT_GL_NO_ERROR();
119 glGetMaterialfv(GL_FRONT, pnames[i], &actualColor.R);
120 EXPECT_GL_NO_ERROR();
121 EXPECT_EQ(colors[i], actualColor);
122 }
123
124 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, kShininessTestValue);
125 EXPECT_GL_NO_ERROR();
126 glGetMaterialfv(GL_FRONT, GL_SHININESS, &actualShininess);
127 EXPECT_GL_NO_ERROR();
128 EXPECT_EQ(kShininessTestValue, actualShininess);
129 }
130
131 ANGLE_INSTANTIATE_TEST_ES1(MaterialsTest);
132