xref: /aosp_15_r20/external/angle/src/tests/gl_tests/gles1/ClipPlaneTest.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 // ClipPlaneTest.cpp: Tests basic usage of user clip planes.
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 ClipPlaneTest : public ANGLETest<>
19 {
20   protected:
ClipPlaneTest()21     ClipPlaneTest()
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 // Checks that disable / enable works as expected.
TEST_P(ClipPlaneTest,InitialState)34 TEST_P(ClipPlaneTest, InitialState)
35 {
36     GLint planeCount = 0;
37     glGetIntegerv(GL_MAX_CLIP_PLANES, &planeCount);
38     EXPECT_GL_NO_ERROR();
39 
40     EXPECT_GE(planeCount, 1);  // spec minimum
41 
42     GLfloat clipPlane[4] = {};
43 
44     for (int i = 0; i < planeCount; i++)
45     {
46         GLenum plane = GL_CLIP_PLANE0 + i;
47 
48         EXPECT_GL_FALSE(glIsEnabled(plane));
49         EXPECT_GL_NO_ERROR();
50 
51         glGetClipPlanef(plane, clipPlane);
52         EXPECT_GL_NO_ERROR();
53 
54         EXPECT_EQ(0.0f, clipPlane[0]);
55         EXPECT_EQ(0.0f, clipPlane[1]);
56         EXPECT_EQ(0.0f, clipPlane[2]);
57         EXPECT_EQ(0.0f, clipPlane[3]);
58     }
59 }
60 
61 // Negative test for invalid clip planes.
TEST_P(ClipPlaneTest,Negative)62 TEST_P(ClipPlaneTest, Negative)
63 {
64     GLint planeCount = 0;
65     glGetIntegerv(GL_MAX_CLIP_PLANES, &planeCount);
66     EXPECT_GL_NO_ERROR();
67 
68     glClipPlanef(GL_CLIP_PLANE0 + planeCount, nullptr);
69     EXPECT_GL_ERROR(GL_INVALID_ENUM);
70 
71     glClipPlanef(GL_CLIP_PLANE0 - 1, nullptr);
72     EXPECT_GL_ERROR(GL_INVALID_ENUM);
73 
74     glGetClipPlanef(GL_CLIP_PLANE0 + planeCount, nullptr);
75     EXPECT_GL_ERROR(GL_INVALID_ENUM);
76 
77     glGetClipPlanef(GL_CLIP_PLANE0 - 1, nullptr);
78     EXPECT_GL_ERROR(GL_INVALID_ENUM);
79 }
80 
81 // Test for setting clip plane values.
TEST_P(ClipPlaneTest,Set)82 TEST_P(ClipPlaneTest, Set)
83 {
84     GLint planeCount = 0;
85     glGetIntegerv(GL_MAX_CLIP_PLANES, &planeCount);
86     EXPECT_GL_NO_ERROR();
87 
88     for (int i = 0; i < planeCount; i++)
89     {
90         GLenum plane = GL_CLIP_PLANE0 + i;
91 
92         EXPECT_GL_FALSE(glIsEnabled(plane));
93         EXPECT_GL_NO_ERROR();
94 
95         GLfloat clipPlane[4] = {
96             i + 0.0f,
97             i + 1.0f,
98             i + 2.0f,
99             i + 3.0f,
100         };
101 
102         glClipPlanef(plane, clipPlane);
103         EXPECT_GL_NO_ERROR();
104 
105         GLfloat actualClipPlane[4] = {};
106 
107         glGetClipPlanef(plane, actualClipPlane);
108         EXPECT_EQ(clipPlane[0], actualClipPlane[0]);
109         EXPECT_EQ(clipPlane[1], actualClipPlane[1]);
110         EXPECT_EQ(clipPlane[2], actualClipPlane[2]);
111         EXPECT_EQ(clipPlane[3], actualClipPlane[3]);
112 
113         glEnable(plane);
114         EXPECT_GL_NO_ERROR();
115         EXPECT_GL_TRUE(glIsEnabled(plane));
116     }
117 }
118 
119 ANGLE_INSTANTIATE_TEST_ES1(ClipPlaneTest);
120