xref: /aosp_15_r20/external/angle/src/tests/gl_tests/gles1/CurrentNormalTest.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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 // CurrentNormalTest.cpp: Tests basic usage of glNormal3(f|x).
8 
9 #include "test_utils/ANGLETest.h"
10 #include "test_utils/gl_raii.h"
11 
12 #include "util/random_utils.h"
13 
14 #include "common/vector_utils.h"
15 
16 #include <stdint.h>
17 
18 using namespace angle;
19 
20 class CurrentNormalTest : public ANGLETest<>
21 {
22   protected:
CurrentNormalTest()23     CurrentNormalTest()
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 // State query: Checks the initial state is correct.
TEST_P(CurrentNormalTest,InitialState)36 TEST_P(CurrentNormalTest, InitialState)
37 {
38     const angle::Vector3 kUp(0.0f, 0.0f, 1.0f);
39     angle::Vector3 actualNormal;
40     glGetFloatv(GL_CURRENT_NORMAL, actualNormal.data());
41     EXPECT_GL_NO_ERROR();
42     EXPECT_EQ(kUp, actualNormal);
43 }
44 
45 // Set test: Checks that the current normal is properly set and retrieved.
TEST_P(CurrentNormalTest,Set)46 TEST_P(CurrentNormalTest, Set)
47 {
48     glNormal3f(0.1f, 0.2f, 0.3f);
49     EXPECT_GL_NO_ERROR();
50 
51     angle::Vector3 actualNormal;
52 
53     glGetFloatv(GL_CURRENT_NORMAL, actualNormal.data());
54     EXPECT_GL_NO_ERROR();
55     EXPECT_EQ(angle::Vector3(0.1f, 0.2f, 0.3f), actualNormal);
56 
57     float epsilon = 0.00001f;
58 
59     glNormal3x(0x10000, 0x3333, 0x5555);
60     EXPECT_GL_NO_ERROR();
61 
62     glGetFloatv(GL_CURRENT_NORMAL, actualNormal.data());
63     EXPECT_GL_NO_ERROR();
64     EXPECT_NEAR(1.0f, actualNormal[0], epsilon);
65     EXPECT_NEAR(0.2f, actualNormal[1], epsilon);
66     EXPECT_NEAR(1.0f / 3.0f, actualNormal[2], epsilon);
67 }
68 
69 ANGLE_INSTANTIATE_TEST_ES1(CurrentNormalTest);
70