Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / tests / angle_tests / IncompleteTextureTest.cpp
1 #include "ANGLETest.h"
2
3 #include <vector>
4
5 // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
6 typedef ::testing::Types<TFT<Gles::Two, Rend::D3D11>, TFT<Gles::Two, Rend::D3D9>> TestFixtureTypes;
7 TYPED_TEST_CASE(IncompleteTextureTest, TestFixtureTypes);
8
9 template<typename T>
10 class IncompleteTextureTest : public ANGLETest
11 {
12 protected:
13     IncompleteTextureTest() : ANGLETest(T::GetGlesMajorVersion(), T::GetRequestedRenderer())
14     {
15         setWindowWidth(128);
16         setWindowHeight(128);
17         setConfigRedBits(8);
18         setConfigGreenBits(8);
19         setConfigBlueBits(8);
20         setConfigAlphaBits(8);
21     }
22
23     virtual void SetUp()
24     {
25         ANGLETest::SetUp();
26
27         const std::string vertexShaderSource = SHADER_SOURCE
28         (
29             precision highp float;
30             attribute vec4 position;
31             varying vec2 texcoord;
32
33             void main()
34             {
35                 gl_Position = position;
36                 texcoord = (position.xy * 0.5) + 0.5;
37             }
38         );
39
40         const std::string fragmentShaderSource = SHADER_SOURCE
41         (
42             precision highp float;
43             uniform sampler2D tex;
44             varying vec2 texcoord;
45
46             void main()
47             {
48                 gl_FragColor = texture2D(tex, texcoord);
49             }
50         );
51
52         mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
53         if (mProgram == 0)
54         {
55             FAIL() << "shader compilation failed.";
56         }
57
58         mTextureUniformLocation = glGetUniformLocation(mProgram, "tex");
59     }
60
61     virtual void TearDown()
62     {
63         glDeleteProgram(mProgram);
64
65         ANGLETest::TearDown();
66     }
67
68     void fillTextureData(std::vector<GLubyte> &buffer, GLubyte r, GLubyte g, GLubyte b, GLubyte a)
69     {
70         size_t count = buffer.size() / 4;
71         for (size_t i = 0; i < count; i++)
72         {
73             buffer[i * 4 + 0] = r;
74             buffer[i * 4 + 1] = g;
75             buffer[i * 4 + 2] = b;
76             buffer[i * 4 + 3] = a;
77         }
78     }
79
80     GLuint mProgram;
81     GLint mTextureUniformLocation;
82 };
83
84 TYPED_TEST(IncompleteTextureTest, IncompleteTexture2D)
85 {
86     GLuint tex;
87     glGenTextures(1, &tex);
88     glActiveTexture(GL_TEXTURE0);
89     glBindTexture(GL_TEXTURE_2D, tex);
90
91     glUseProgram(mProgram);
92     glUniform1i(mTextureUniformLocation, 0);
93
94     const GLsizei textureWidth = 2;
95     const GLsizei textureHeight = 2;
96     std::vector<GLubyte> textureData(textureWidth * textureHeight * 4);
97     fillTextureData(textureData, 255, 0, 0, 255);
98
99     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, &textureData[0]);
100     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
101
102     drawQuad(mProgram, "position", 0.5f);
103     EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
104
105     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
106
107     drawQuad(mProgram, "position", 0.5f);
108     EXPECT_PIXEL_EQ(0, 0, 0, 0, 0, 255);
109
110     glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, textureWidth >> 1, textureHeight >> 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &textureData[0]);
111
112     drawQuad(mProgram, "position", 0.5f);
113     EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
114
115     glDeleteTextures(1, &tex);
116 }
117
118 TYPED_TEST(IncompleteTextureTest, UpdateTexture)
119 {
120     GLuint tex;
121     glGenTextures(1, &tex);
122     glActiveTexture(GL_TEXTURE0);
123     glBindTexture(GL_TEXTURE_2D, tex);
124
125     glUseProgram(mProgram);
126     glUniform1i(mTextureUniformLocation, 0);
127
128     const GLsizei redTextureWidth = 64;
129     const GLsizei redTextureHeight = 64;
130     std::vector<GLubyte> redTextureData(redTextureWidth * redTextureHeight * 4);
131     fillTextureData(redTextureData, 255, 0, 0, 255);
132     for (size_t i = 0; i < 7; i++)
133     {
134         glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, redTextureWidth >> i, redTextureHeight >> i, 0, GL_RGBA, GL_UNSIGNED_BYTE,
135                      &redTextureData[0]);
136     }
137
138     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
139     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
140
141     drawQuad(mProgram, "position", 0.5f);
142     EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
143
144     const GLsizei greenTextureWidth = 32;
145     const GLsizei greenTextureHeight = 32;
146     std::vector<GLubyte> greenTextureData(greenTextureWidth * greenTextureHeight * 4);
147     fillTextureData(greenTextureData, 0, 255, 0, 255);
148
149     for (size_t i = 0; i < 6; i++)
150     {
151         glTexSubImage2D(GL_TEXTURE_2D, i, greenTextureWidth >> i, greenTextureHeight >> i,
152                         greenTextureWidth >> i, greenTextureHeight >> i, GL_RGBA, GL_UNSIGNED_BYTE,
153                         &greenTextureData[0]);
154     }
155
156     drawQuad(mProgram, "position", 0.5f);
157     EXPECT_PIXEL_EQ(getWindowWidth() - greenTextureWidth, getWindowHeight() - greenTextureWidth, 0, 255, 0, 255);
158
159     glDeleteTextures(1, &tex);
160 }