• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 gfxstream {
21 namespace gl {
22 namespace {
23 
24 // Line width settings to attempt
25 static const GLfloat kGLES2TestLineWidths[] = {2.0f};
26 
27 class SnapshotGlLineWidthTest : public SnapshotSetValueTest<GLfloat>,
28                                 public ::testing::WithParamInterface<GLfloat> {
stateCheck(GLfloat expected)29     void stateCheck(GLfloat expected) override {
30         GLfloat lineWidthRange[2];
31         gl->glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, lineWidthRange);
32 
33         GLfloat lineWidth;
34         gl->glGetFloatv(GL_LINE_WIDTH, &lineWidth);
35 
36         if (expected <= lineWidthRange[1]) {
37             EXPECT_EQ(expected, lineWidth);
38         }
39     }
stateChange()40     void stateChange() override { gl->glLineWidth(GetParam()); }
41 };
42 
TEST_P(SnapshotGlLineWidthTest,SetLineWidth)43 TEST_P(SnapshotGlLineWidthTest, SetLineWidth) {
44     setExpectedValues(1.0f, GetParam());
45     doCheckedSnapshot();
46 }
47 
48 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotRasterization,
49                          SnapshotGlLineWidthTest,
50                          ::testing::ValuesIn(kGLES2TestLineWidths));
51 
52 class SnapshotGlCullFaceTest : public SnapshotSetValueTest<GLenum>,
53                                public ::testing::WithParamInterface<GLenum> {
stateCheck(GLenum expected)54     void stateCheck(GLenum expected) override {
55         EXPECT_TRUE(compareGlobalGlInt(gl, GL_CULL_FACE_MODE, expected));
56     }
stateChange()57     void stateChange() override { gl->glCullFace(GetParam()); }
58 };
59 
TEST_P(SnapshotGlCullFaceTest,SetCullFaceMode)60 TEST_P(SnapshotGlCullFaceTest, SetCullFaceMode) {
61     setExpectedValues(GL_BACK, GetParam());
62     doCheckedSnapshot();
63 }
64 
65 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotRasterization,
66                          SnapshotGlCullFaceTest,
67                          ::testing::ValuesIn(kGLES2CullFaceModes));
68 
69 class SnapshotGlFrontFaceTest : public SnapshotSetValueTest<GLenum>,
70                                 public ::testing::WithParamInterface<GLenum> {
stateCheck(GLenum expected)71     void stateCheck(GLenum expected) override {
72         EXPECT_TRUE(compareGlobalGlInt(gl, GL_FRONT_FACE, expected));
73     }
stateChange()74     void stateChange() override { gl->glFrontFace(GetParam()); }
75 };
76 
TEST_P(SnapshotGlFrontFaceTest,SetFrontFaceMode)77 TEST_P(SnapshotGlFrontFaceTest, SetFrontFaceMode) {
78     setExpectedValues(GL_CCW, GetParam());
79     doCheckedSnapshot();
80 }
81 
82 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotRasterization,
83                          SnapshotGlFrontFaceTest,
84                          ::testing::ValuesIn(kGLES2FrontFaceModes));
85 
86 class SnapshotGlPolygonOffsetTest
87     : public SnapshotSetValueTest<GLfloat*> {
stateCheck(GLfloat * expected)88     void stateCheck(GLfloat* expected) override {
89         EXPECT_TRUE(compareGlobalGlFloat(gl, GL_POLYGON_OFFSET_FACTOR,
90                                          expected[0]));
91         EXPECT_TRUE(
92                 compareGlobalGlFloat(gl, GL_POLYGON_OFFSET_UNITS, expected[1]));
93     }
stateChange()94     void stateChange() override {
95         gl->glPolygonOffset(0.5f, 0.5f);
96     }
97 };
98 
TEST_F(SnapshotGlPolygonOffsetTest,SetPolygonOffset)99 TEST_F(SnapshotGlPolygonOffsetTest, SetPolygonOffset) {
100     GLfloat defaultOffset[2] = {0.0f, 0.0f};
101     GLfloat testOffset[2] = {0.5f, 0.5f};
102     setExpectedValues(defaultOffset, testOffset);
103     doCheckedSnapshot();
104 }
105 
106 }  // namespace
107 }  // namespace gl
108 }  // namespace gfxstream
109