1 // Copyright (C) 2018 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "GLSnapshotTesting.h"
16 #include "OpenGLTestContext.h"
17
18 #include <gtest/gtest.h>
19
20 namespace emugl {
21
22 // Line width settings to attempt
23 static const GLfloat kGLES2TestLineWidths[] = {2.0f};
24
25 // Polygon offset settings to attempt
26 static const GLfloat kGLES2TestPolygonOffset[] = {0.5f, 0.5f};
27
28 class SnapshotGlLineWidthTest : public SnapshotSetValueTest<GLfloat>,
29 public ::testing::WithParamInterface<GLfloat> {
stateCheck(GLfloat expected)30 void stateCheck(GLfloat expected) override {
31 GLfloat lineWidthRange[2];
32 gl->glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, lineWidthRange);
33
34 GLfloat lineWidth;
35 gl->glGetFloatv(GL_LINE_WIDTH, &lineWidth);
36
37 if (expected <= lineWidthRange[1]) {
38 EXPECT_EQ(expected, lineWidth);
39 }
40 }
stateChange()41 void stateChange() override { gl->glLineWidth(GetParam()); }
42 };
43
TEST_P(SnapshotGlLineWidthTest,SetLineWidth)44 TEST_P(SnapshotGlLineWidthTest, SetLineWidth) {
45 setExpectedValues(1.0f, GetParam());
46 doCheckedSnapshot();
47 }
48
49 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotRasterization,
50 SnapshotGlLineWidthTest,
51 ::testing::ValuesIn(kGLES2TestLineWidths));
52
53 class SnapshotGlCullFaceTest : public SnapshotSetValueTest<GLenum>,
54 public ::testing::WithParamInterface<GLenum> {
stateCheck(GLenum expected)55 void stateCheck(GLenum expected) override {
56 EXPECT_TRUE(compareGlobalGlInt(gl, GL_CULL_FACE_MODE, expected));
57 }
stateChange()58 void stateChange() override { gl->glCullFace(GetParam()); }
59 };
60
TEST_P(SnapshotGlCullFaceTest,SetCullFaceMode)61 TEST_P(SnapshotGlCullFaceTest, SetCullFaceMode) {
62 setExpectedValues(GL_BACK, GetParam());
63 doCheckedSnapshot();
64 }
65
66 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotRasterization,
67 SnapshotGlCullFaceTest,
68 ::testing::ValuesIn(kGLES2CullFaceModes));
69
70 class SnapshotGlFrontFaceTest : public SnapshotSetValueTest<GLenum>,
71 public ::testing::WithParamInterface<GLenum> {
stateCheck(GLenum expected)72 void stateCheck(GLenum expected) override {
73 EXPECT_TRUE(compareGlobalGlInt(gl, GL_FRONT_FACE, expected));
74 }
stateChange()75 void stateChange() override { gl->glFrontFace(GetParam()); }
76 };
77
TEST_P(SnapshotGlFrontFaceTest,SetFrontFaceMode)78 TEST_P(SnapshotGlFrontFaceTest, SetFrontFaceMode) {
79 setExpectedValues(GL_CCW, GetParam());
80 doCheckedSnapshot();
81 }
82
83 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotRasterization,
84 SnapshotGlFrontFaceTest,
85 ::testing::ValuesIn(kGLES2FrontFaceModes));
86
87 class SnapshotGlPolygonOffsetTest
88 : public SnapshotSetValueTest<GLfloat*>,
89 public ::testing::WithParamInterface<const GLfloat*> {
stateCheck(GLfloat * expected)90 void stateCheck(GLfloat* expected) override {
91 EXPECT_TRUE(compareGlobalGlFloat(gl, GL_POLYGON_OFFSET_FACTOR,
92 expected[0]));
93 EXPECT_TRUE(
94 compareGlobalGlFloat(gl, GL_POLYGON_OFFSET_UNITS, expected[1]));
95 }
stateChange()96 void stateChange() override {
97 gl->glPolygonOffset(GetParam()[0], GetParam()[1]);
98 }
99 };
100
TEST_P(SnapshotGlPolygonOffsetTest,SetPolygonOffset)101 TEST_P(SnapshotGlPolygonOffsetTest, SetPolygonOffset) {
102 GLfloat defaultOffset[2] = {0.0f, 0.0f};
103 GLfloat testOffset[2] = {GetParam()[0], GetParam()[1]};
104 setExpectedValues(defaultOffset, testOffset);
105 doCheckedSnapshot();
106 }
107
108 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotRasterization,
109 SnapshotGlPolygonOffsetTest,
110 ::testing::Values(kGLES2TestPolygonOffset));
111
112 } // namespace emugl
113