• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // BasicDrawTest.cpp: Tests basic fullscreen quad draw with and without
8 // GL_TEXTURE_2D enabled.
9 
10 #include "test_utils/ANGLETest.h"
11 #include "test_utils/gl_raii.h"
12 
13 #include <vector>
14 
15 using namespace angle;
16 
17 class BasicDrawTest : public ANGLETest
18 {
19   protected:
BasicDrawTest()20     BasicDrawTest()
21     {
22         setWindowWidth(32);
23         setWindowHeight(32);
24         setConfigRedBits(8);
25         setConfigGreenBits(8);
26         setConfigBlueBits(8);
27         setConfigAlphaBits(8);
28         setConfigDepthBits(24);
29     }
30 
31     std::vector<float> mPositions = {
32         -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f,
33     };
34 
drawRedQuad()35     void drawRedQuad()
36     {
37         glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
38         EXPECT_GL_NO_ERROR();
39         glEnableClientState(GL_VERTEX_ARRAY);
40         EXPECT_GL_NO_ERROR();
41         glVertexPointer(2, GL_FLOAT, 0, mPositions.data());
42         EXPECT_GL_NO_ERROR();
43         glDrawArrays(GL_TRIANGLES, 0, 6);
44         EXPECT_GL_NO_ERROR();
45         EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
46     }
47 };
48 
49 // Draws a fullscreen quad with a certain color.
TEST_P(BasicDrawTest,DrawColor)50 TEST_P(BasicDrawTest, DrawColor)
51 {
52     drawRedQuad();
53 }
54 
55 // Checks that textures can be enabled or disabled.
TEST_P(BasicDrawTest,EnableDisableTexture)56 TEST_P(BasicDrawTest, EnableDisableTexture)
57 {
58     GLuint tex;
59     glGenTextures(1, &tex);
60     glBindTexture(GL_TEXTURE_2D, tex);
61 
62     // Green
63     GLubyte texture[] = {
64         0x00,
65         0xff,
66         0x00,
67     };
68 
69     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, texture);
70 
71     // Texturing is disabled; still red;
72     drawRedQuad();
73 
74     glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
75 
76     // Texturing enabled; is green (provided modulate w/ white)
77     glEnable(GL_TEXTURE_2D);
78     EXPECT_GL_NO_ERROR();
79     glDrawArrays(GL_TRIANGLES, 0, 6);
80     EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
81 }
82 
83 // Check that glClearColorx, glClearDepthx, glLineWidthx, glPolygonOffsetx can work.
TEST_P(BasicDrawTest,DepthTest)84 TEST_P(BasicDrawTest, DepthTest)
85 {
86     glClearColorx(0x4000, 0x8000, 0x8000, 0x8000);
87     EXPECT_GL_NO_ERROR();
88     glClearDepthx(0x8000);
89     EXPECT_GL_NO_ERROR();
90 
91     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
92     EXPECT_PIXEL_NEAR(0, 0, 64, 128, 128, 128, 1.0);
93 
94     // Fail Depth Test and can't draw the red triangle
95     std::vector<float> Positions = {-1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f};
96     glEnable(GL_DEPTH_TEST);
97 
98     glLineWidthx(0x10000);
99     EXPECT_GL_NO_ERROR();
100     glPolygonOffsetx(0, 0);
101     EXPECT_GL_NO_ERROR();
102 
103     glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
104     glEnableClientState(GL_VERTEX_ARRAY);
105     EXPECT_GL_NO_ERROR();
106     glVertexPointer(3, GL_FLOAT, 0, Positions.data());
107     EXPECT_GL_NO_ERROR();
108     glDrawArrays(GL_TRIANGLES, 0, 3);
109     EXPECT_GL_NO_ERROR();
110     EXPECT_PIXEL_NEAR(0, 0, 64, 128, 128, 128, 1.0);
111 
112     glDisable(GL_DEPTH_TEST);
113     EXPECT_GL_NO_ERROR();
114     glDrawArrays(GL_TRIANGLES, 0, 3);
115     EXPECT_GL_NO_ERROR();
116     EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
117 }
118 
119 // Check that depth range can be set by glDepthRangex.
TEST_P(BasicDrawTest,SetDepthRangex)120 TEST_P(BasicDrawTest, SetDepthRangex)
121 {
122     glDepthRangex(0x8000, 0x10000);
123     EXPECT_GL_NO_ERROR();
124 
125     GLfixed depth_range[2];
126     glGetFixedv(GL_DEPTH_RANGE, depth_range);
127     EXPECT_GL_NO_ERROR();
128     EXPECT_EQ(0x8000, depth_range[0]);
129     EXPECT_EQ(0x10000, depth_range[1]);
130 }
131 
132 // Check that sample coverage parameters can be set by glSampleCoveragex.
TEST_P(BasicDrawTest,SetSampleCoveragex)133 TEST_P(BasicDrawTest, SetSampleCoveragex)
134 {
135     GLfixed isSampleCoverage;
136     GLfixed samplecoveragevalue;
137     GLfixed samplecoverageinvert;
138 
139     glEnable(GL_SAMPLE_COVERAGE);
140     EXPECT_GL_NO_ERROR();
141 
142     glGetFixedv(GL_SAMPLE_COVERAGE, &isSampleCoverage);
143     EXPECT_GL_NO_ERROR();
144     EXPECT_EQ(0x10000, isSampleCoverage);
145 
146     glSampleCoveragex(0x8000, true);
147     EXPECT_GL_NO_ERROR();
148 
149     glGetFixedv(GL_SAMPLE_COVERAGE_VALUE, &samplecoveragevalue);
150     EXPECT_GL_NO_ERROR();
151     EXPECT_EQ(0x8000, samplecoveragevalue);
152 
153     glGetFixedv(GL_SAMPLE_COVERAGE_INVERT, &samplecoverageinvert);
154     EXPECT_GL_NO_ERROR();
155     EXPECT_EQ(0x10000, samplecoverageinvert);
156 }
157 
158 ANGLE_INSTANTIATE_TEST_ES1(BasicDrawTest);
159