• 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 // DrawTextureTest.cpp: Tests basic usage of glDrawTex*.
8 
9 #include "test_utils/ANGLETest.h"
10 #include "test_utils/gl_raii.h"
11 
12 #include <memory>
13 #include <vector>
14 
15 using namespace angle;
16 
17 class DrawTextureTest : public ANGLETest
18 {
19   protected:
DrawTextureTest()20     DrawTextureTest()
21     {
22         setWindowWidth(32);
23         setWindowHeight(32);
24         setConfigRedBits(8);
25         setConfigGreenBits(8);
26         setConfigBlueBits(8);
27         setConfigAlphaBits(8);
28         setConfigDepthBits(24);
29     }
30 
testSetUp()31     void testSetUp() override
32     {
33         mTexture.reset(new GLTexture());
34         glEnable(GL_TEXTURE_2D);
35         glBindTexture(GL_TEXTURE_2D, mTexture->get());
36     }
37 
testTearDown()38     void testTearDown() override { mTexture.reset(); }
39 
40     std::unique_ptr<GLTexture> mTexture;
41 };
42 
43 // Negative test for invalid width/height values.
TEST_P(DrawTextureTest,NegativeValue)44 TEST_P(DrawTextureTest, NegativeValue)
45 {
46     glDrawTexiOES(0, 0, 0, 0, 0);
47     EXPECT_GL_ERROR(GL_INVALID_VALUE);
48     glDrawTexiOES(0, 0, 0, -1, 0);
49     EXPECT_GL_ERROR(GL_INVALID_VALUE);
50     glDrawTexiOES(0, 0, 0, 0, -1);
51     EXPECT_GL_ERROR(GL_INVALID_VALUE);
52     glDrawTexiOES(0, 0, 0, -1, -1);
53     EXPECT_GL_ERROR(GL_INVALID_VALUE);
54 }
55 
56 // Basic draw.
TEST_P(DrawTextureTest,Basic)57 TEST_P(DrawTextureTest, Basic)
58 {
59     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
60     glDrawTexiOES(0, 0, 0, 1, 1);
61     EXPECT_GL_NO_ERROR();
62     EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
63 }
64 
65 // Tests that odd viewport dimensions are handled correctly.
66 // If the viewport dimension is even, then the incorrect way
67 // of getting the center screen coordinate by dividing by 2 and
68 // converting to integer will work in that case, but not if
69 // the viewport dimension is odd.
TEST_P(DrawTextureTest,CorrectNdcForOddViewportDimensions)70 TEST_P(DrawTextureTest, CorrectNdcForOddViewportDimensions)
71 {
72     glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
73     glClear(GL_COLOR_BUFFER_BIT);
74 
75     // clang-format off
76     std::array<GLColor, 2> textureData = {
77         GLColor::green, GLColor::green
78     };
79     // clang-format on
80 
81     glViewport(0, 0, 3, 3);
82     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData.data());
83 
84     GLint cropRect[] = {0, 0, 2, 1};
85     glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect);
86     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
87     EXPECT_GL_NO_ERROR();
88 
89     GLint x = 1;
90     GLint y = 1;
91     glDrawTexiOES(x, y, 0, 2, 1);
92     EXPECT_GL_NO_ERROR();
93 
94     EXPECT_PIXEL_COLOR_EQ(x, y, GLColor::green);
95     EXPECT_PIXEL_COLOR_EQ(x + 1, y, GLColor::green);
96 
97     EXPECT_PIXEL_COLOR_EQ(x, y + 1, GLColor::black);
98     EXPECT_PIXEL_COLOR_EQ(x + 1, y + 1, GLColor::black);
99     EXPECT_PIXEL_COLOR_EQ(x + 2, y, GLColor::black);
100     EXPECT_PIXEL_COLOR_EQ(x + 3, y, GLColor::black);
101 }
102 
103 // Tests that vertex attributes enabled with fewer than 6 verts do not cause a crash.
TEST_P(DrawTextureTest,VertexAttributesNoCrash)104 TEST_P(DrawTextureTest, VertexAttributesNoCrash)
105 {
106     glEnableClientState(GL_COLOR_ARRAY);
107     glColorPointer(4, GL_FLOAT, 0, &GLColor::white);
108 
109     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
110     EXPECT_GL_NO_ERROR();
111 
112     glDrawTexiOES(0, 0, 0, 1, 1);
113     EXPECT_GL_NO_ERROR();
114     EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
115 }
116 
117 // Tests that the color array, if enabled, is not used as the vertex color.
TEST_P(DrawTextureTest,ColorArrayNotUsed)118 TEST_P(DrawTextureTest, ColorArrayNotUsed)
119 {
120     glEnableClientState(GL_COLOR_ARRAY);
121 
122     // This color is set to black on purpose to ensure that the color in the upcoming vertex array
123     // is not used in the texture draw. If it is used, then the texture we want to read will be
124     // modulated with the color in the vertex array instead of GL_CURRENT_COLOR (which at the moment
125     // is white (1.0, 1.0, 1.0, 1.0).
126     glColorPointer(4, GL_FLOAT, 0, &GLColor::black);
127 
128     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
129     EXPECT_GL_NO_ERROR();
130 
131     glDrawTexiOES(0, 0, 0, 1, 1);
132     EXPECT_GL_NO_ERROR();
133     EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
134 }
135 
136 ANGLE_INSTANTIATE_TEST_ES1(DrawTextureTest);
137