• 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 
17 #include <gtest/gtest.h>
18 
19 namespace emugl {
20 
21 class SnapshotGlColorMaskTest
22     : public SnapshotSetValueTest<std::vector<GLboolean>> {
stateCheck(std::vector<GLboolean> expected)23     void stateCheck(std::vector<GLboolean> expected) override {
24         EXPECT_TRUE(compareGlobalGlBooleanv(gl, GL_COLOR_WRITEMASK, expected));
25     }
stateChange()26     void stateChange() override {
27         std::vector<GLboolean> mask = *m_changed_value;
28         gl->glColorMask(mask[0], mask[1], mask[2], mask[3]);
29     }
30 };
31 
TEST_F(SnapshotGlColorMaskTest,SetColorMask)32 TEST_F(SnapshotGlColorMaskTest, SetColorMask) {
33     setExpectedValues({true, true, true, true}, {false, false, false, false});
34     doCheckedSnapshot();
35 }
36 
37 class SnapshotGlDepthMaskTest : public SnapshotSetValueTest<GLboolean> {
stateCheck(GLboolean expected)38     void stateCheck(GLboolean expected) override {
39         EXPECT_TRUE(compareGlobalGlBoolean(gl, GL_DEPTH_WRITEMASK, expected));
40     }
stateChange()41     void stateChange() override { gl->glDepthMask(*m_changed_value); }
42 };
43 
TEST_F(SnapshotGlDepthMaskTest,SetDepthMask)44 TEST_F(SnapshotGlDepthMaskTest, SetDepthMask) {
45     setExpectedValues(true, false);
46     doCheckedSnapshot();
47 }
48 
49 // not to be confused with GL_STENCIL_VALUE_MASK
50 class SnapshotGlStencilWriteMaskTest : public SnapshotSetValueTest<GLuint> {
stateCheck(GLuint expected)51     void stateCheck(GLuint expected) override {
52         EXPECT_TRUE(compareGlobalGlInt(gl, GL_STENCIL_WRITEMASK, expected));
53         EXPECT_TRUE(
54                 compareGlobalGlInt(gl, GL_STENCIL_BACK_WRITEMASK, expected));
55     }
stateChange()56     void stateChange() override { gl->glStencilMask(*m_changed_value); }
57 };
58 
TEST_F(SnapshotGlStencilWriteMaskTest,SetStencilMask)59 TEST_F(SnapshotGlStencilWriteMaskTest, SetStencilMask) {
60     // different drivers act differently; get the default mask
61     GLint defaultWriteMask;
62     gl->glGetIntegerv(GL_STENCIL_WRITEMASK, &defaultWriteMask);
63     EXPECT_EQ(GL_NO_ERROR, gl->glGetError());
64 
65     setExpectedValues(defaultWriteMask, 0);
66     doCheckedSnapshot();
67 }
68 
69 class SnapshotGlColorClearValueTest
70     : public SnapshotSetValueTest<std::vector<GLclampf>> {
stateCheck(std::vector<GLclampf> expected)71     void stateCheck(std::vector<GLclampf> expected) override {
72         EXPECT_TRUE(compareGlobalGlFloatv(gl, GL_COLOR_CLEAR_VALUE, expected));
73     }
stateChange()74     void stateChange() override {
75         std::vector<GLclampf> color = *m_changed_value;
76         gl->glClearColor(color[0], color[1], color[2], color[3]);
77     }
78 };
79 
TEST_F(SnapshotGlColorClearValueTest,SetClearColor)80 TEST_F(SnapshotGlColorClearValueTest, SetClearColor) {
81     setExpectedValues({0, 0, 0, 0}, {1.0f, 0.2f, 0.7f, 0.8f});
82     doCheckedSnapshot();
83 }
84 
85 class SnapshotGlDepthClearValueTest : public SnapshotSetValueTest<GLclampf> {
stateCheck(GLclampf expected)86     void stateCheck(GLclampf expected) override {
87         EXPECT_TRUE(compareGlobalGlFloat(gl, GL_DEPTH_CLEAR_VALUE, expected));
88     }
stateChange()89     void stateChange() override { gl->glClearDepthf(*m_changed_value); }
90 };
91 
TEST_F(SnapshotGlDepthClearValueTest,SetClearDepth)92 TEST_F(SnapshotGlDepthClearValueTest, SetClearDepth) {
93     setExpectedValues(1.0f, 0.4f);
94     doCheckedSnapshot();
95 }
96 
97 class SnapshotGlStencilClearValueTest : public SnapshotSetValueTest<GLint> {
stateCheck(GLint expected)98     void stateCheck(GLint expected) override {
99         EXPECT_TRUE(compareGlobalGlInt(gl, GL_STENCIL_CLEAR_VALUE, expected));
100     }
stateChange()101     void stateChange() override { gl->glClearStencil(*m_changed_value); }
102 };
103 
TEST_F(SnapshotGlStencilClearValueTest,SetClearStencil)104 TEST_F(SnapshotGlStencilClearValueTest, SetClearStencil) {
105     setExpectedValues(0, 3);
106     doCheckedSnapshot();
107 }
108 
109 }  // namespace emugl
110