blob: 18125a002ead3f219b4aeb5ffd396f22906061a6 [file] [log] [blame]
Geoff Lang066230a2013-10-30 12:59:30 -04001#include "ANGLETest.h"
Geoff Langd701ea12014-01-10 15:53:35 -05002#include "media/pixel.inl"
Geoff Lang066230a2013-10-30 12:59:30 -04003
Austin Kinross18b931d2014-09-29 12:58:31 -07004// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
Geoff Langa8091652015-04-27 10:53:55 -04005ANGLE_TYPED_TEST_CASE(CompressedTextureTest, ES2_D3D9, ES2_D3D11, ES2_D3D11_FL9_3, ES2_OPENGL, ES3_OPENGL);
Austin Kinross18b931d2014-09-29 12:58:31 -07006
7template<typename T>
Geoff Lang066230a2013-10-30 12:59:30 -04008class CompressedTextureTest : public ANGLETest
9{
10protected:
Geoff Lang0d3683c2014-10-23 11:08:16 -040011 CompressedTextureTest() : ANGLETest(T::GetGlesMajorVersion(), T::GetPlatform())
Geoff Lang066230a2013-10-30 12:59:30 -040012 {
13 setWindowWidth(512);
14 setWindowHeight(512);
15 setConfigRedBits(8);
16 setConfigGreenBits(8);
17 setConfigBlueBits(8);
18 setConfigAlphaBits(8);
19 }
20
21 virtual void SetUp()
22 {
23 ANGLETest::SetUp();
24
25 const std::string vsSource = SHADER_SOURCE
26 (
27 precision highp float;
28 attribute vec4 position;
29 varying vec2 texcoord;
30
31 void main()
32 {
33 gl_Position = position;
34 texcoord = (position.xy * 0.5) + 0.5;
35 texcoord.y = 1.0 - texcoord.y;
36 }
37 );
38
39 const std::string textureFSSource = SHADER_SOURCE
40 (
41 precision highp float;
42 uniform sampler2D tex;
43 varying vec2 texcoord;
44
45 void main()
46 {
47 gl_FragColor = texture2D(tex, texcoord);
48 }
49 );
50
Jamie Madill5599c8f2014-08-26 13:16:39 -040051 mTextureProgram = CompileProgram(vsSource, textureFSSource);
Geoff Lang066230a2013-10-30 12:59:30 -040052 if (mTextureProgram == 0)
53 {
54 FAIL() << "shader compilation failed.";
55 }
56
57 mTextureUniformLocation = glGetUniformLocation(mTextureProgram, "tex");
58
59 ASSERT_GL_NO_ERROR();
60 }
61
62 virtual void TearDown()
63 {
64 glDeleteProgram(mTextureProgram);
65
66 ANGLETest::TearDown();
67 }
68
69 GLuint mTextureProgram;
70 GLint mTextureUniformLocation;
71};
72
Austin Kinross18b931d2014-09-29 12:58:31 -070073TYPED_TEST(CompressedTextureTest, CompressedTexImage)
Geoff Lang066230a2013-10-30 12:59:30 -040074{
Geoff Langa8091652015-04-27 10:53:55 -040075 if (!extensionEnabled("GL_EXT_texture_compression_dxt1"))
Geoff Lang066230a2013-10-30 12:59:30 -040076 {
Geoff Langa8091652015-04-27 10:53:55 -040077 std::cout << "Test skipped because GL_EXT_texture_compression_dxt1 is not available." << std::endl;
Geoff Lang066230a2013-10-30 12:59:30 -040078 return;
79 }
80
81 GLuint texture;
82 glGenTextures(1, &texture);
83 glBindTexture(GL_TEXTURE_2D, texture);
84 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
85 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
86 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
87 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
88
Geoff Langd701ea12014-01-10 15:53:35 -050089 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_0_width, pixel_0_height, 0, pixel_0_size, pixel_0_data);
90 glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_1_width, pixel_1_height, 0, pixel_1_size, pixel_1_data);
91 glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_2_width, pixel_2_height, 0, pixel_2_size, pixel_2_data);
92 glCompressedTexImage2D(GL_TEXTURE_2D, 3, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_3_width, pixel_3_height, 0, pixel_3_size, pixel_3_data);
93 glCompressedTexImage2D(GL_TEXTURE_2D, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_4_width, pixel_4_height, 0, pixel_4_size, pixel_4_data);
94 glCompressedTexImage2D(GL_TEXTURE_2D, 5, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_5_width, pixel_5_height, 0, pixel_5_size, pixel_5_data);
95 glCompressedTexImage2D(GL_TEXTURE_2D, 6, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_6_width, pixel_6_height, 0, pixel_6_size, pixel_6_data);
96 glCompressedTexImage2D(GL_TEXTURE_2D, 7, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_7_width, pixel_7_height, 0, pixel_7_size, pixel_7_data);
97 glCompressedTexImage2D(GL_TEXTURE_2D, 8, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_8_width, pixel_8_height, 0, pixel_8_size, pixel_8_data);
98 glCompressedTexImage2D(GL_TEXTURE_2D, 9, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_9_width, pixel_9_height, 0, pixel_9_size, pixel_9_data);
Geoff Lang066230a2013-10-30 12:59:30 -040099
100 EXPECT_GL_NO_ERROR();
101
102 glUseProgram(mTextureProgram);
103 glUniform1i(mTextureUniformLocation, 0);
104
105 drawQuad(mTextureProgram, "position", 0.5f);
106
107 EXPECT_GL_NO_ERROR();
108
109 glDeleteTextures(1, &texture);
110
111 EXPECT_GL_NO_ERROR();
112}
113
Austin Kinross18b931d2014-09-29 12:58:31 -0700114TYPED_TEST(CompressedTextureTest, CompressedTexStorage)
Geoff Lang066230a2013-10-30 12:59:30 -0400115{
Geoff Langa8091652015-04-27 10:53:55 -0400116 if (!extensionEnabled("GL_EXT_texture_compression_dxt1"))
Geoff Lang066230a2013-10-30 12:59:30 -0400117 {
Geoff Langa8091652015-04-27 10:53:55 -0400118 std::cout << "Test skipped due to missing GL_EXT_texture_compression_dxt1" << std::endl;
Geoff Lang066230a2013-10-30 12:59:30 -0400119 return;
120 }
121
122 if (getClientVersion() < 3 && (!extensionEnabled("GL_EXT_texture_storage") || !extensionEnabled("GL_OES_rgb8_rgba8")))
123 {
Geoff Langa8091652015-04-27 10:53:55 -0400124 std::cout << "Test skipped due to missing ES3 or GL_EXT_texture_storage or GL_OES_rgb8_rgba8" << std::endl;
Geoff Lang066230a2013-10-30 12:59:30 -0400125 return;
126 }
127
128 GLuint texture;
129 glGenTextures(1, &texture);
130 glBindTexture(GL_TEXTURE_2D, texture);
131 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
132 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
133 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
134 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
135
136 if (getClientVersion() < 3)
137 {
Geoff Langa836e482014-04-28 10:08:27 -0400138 glTexStorage2DEXT(GL_TEXTURE_2D, pixel_levels, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_0_width, pixel_0_height);
Geoff Lang066230a2013-10-30 12:59:30 -0400139 }
140 else
141 {
Geoff Langa836e482014-04-28 10:08:27 -0400142 glTexStorage2D(GL_TEXTURE_2D, pixel_levels, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_0_width, pixel_0_height);
Geoff Lang066230a2013-10-30 12:59:30 -0400143 }
144 EXPECT_GL_NO_ERROR();
145
Geoff Langd701ea12014-01-10 15:53:35 -0500146 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, pixel_0_width, pixel_0_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_0_size, pixel_0_data);
Geoff Langa836e482014-04-28 10:08:27 -0400147 glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, pixel_1_width, pixel_1_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_1_size, pixel_1_data);
148 glCompressedTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, pixel_2_width, pixel_2_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_2_size, pixel_2_data);
149 glCompressedTexSubImage2D(GL_TEXTURE_2D, 3, 0, 0, pixel_3_width, pixel_3_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_3_size, pixel_3_data);
150 glCompressedTexSubImage2D(GL_TEXTURE_2D, 4, 0, 0, pixel_4_width, pixel_4_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_4_size, pixel_4_data);
151 glCompressedTexSubImage2D(GL_TEXTURE_2D, 5, 0, 0, pixel_5_width, pixel_5_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_5_size, pixel_5_data);
152 glCompressedTexSubImage2D(GL_TEXTURE_2D, 6, 0, 0, pixel_6_width, pixel_6_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_6_size, pixel_6_data);
153 glCompressedTexSubImage2D(GL_TEXTURE_2D, 7, 0, 0, pixel_7_width, pixel_7_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_7_size, pixel_7_data);
154 glCompressedTexSubImage2D(GL_TEXTURE_2D, 8, 0, 0, pixel_8_width, pixel_8_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_8_size, pixel_8_data);
155 glCompressedTexSubImage2D(GL_TEXTURE_2D, 9, 0, 0, pixel_9_width, pixel_9_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_9_size, pixel_9_data);
Geoff Lang066230a2013-10-30 12:59:30 -0400156
157 EXPECT_GL_NO_ERROR();
158
159 glUseProgram(mTextureProgram);
160 glUniform1i(mTextureUniformLocation, 0);
161
162 drawQuad(mTextureProgram, "position", 0.5f);
163
164 EXPECT_GL_NO_ERROR();
165
166 glDeleteTextures(1, &texture);
167
168 EXPECT_GL_NO_ERROR();
169}
Jamie Madillc751d1e2014-10-21 17:46:29 -0400170
171// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
Geoff Lang0d3683c2014-10-23 11:08:16 -0400172ANGLE_TYPED_TEST_CASE(CompressedTextureTestES3, ES3_D3D11);
Jamie Madillc751d1e2014-10-21 17:46:29 -0400173
174template<typename T>
175class CompressedTextureTestES3 : public CompressedTextureTest<T> { };
176
Cooper Partind28f6112015-02-12 16:11:00 -0800177ANGLE_TYPED_TEST_CASE(CompressedTextureTestD3D11, ES2_D3D11, ES3_D3D11, ES2_D3D11_FL9_3);
Jamie Madillc751d1e2014-10-21 17:46:29 -0400178
179template<typename T>
180class CompressedTextureTestD3D11 : public CompressedTextureTest<T> { };
181
182TYPED_TEST(CompressedTextureTestES3, PBOCompressedTexImage)
183{
184 GLuint texture;
185 glGenTextures(1, &texture);
186 glBindTexture(GL_TEXTURE_2D, texture);
187 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
188 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
189 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
190 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
191
192 GLuint buffer;
193 glGenBuffers(1, &buffer);
194 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer);
195 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixel_0_size, NULL, GL_STREAM_DRAW);
196 EXPECT_GL_NO_ERROR();
197
198 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_0_size, pixel_0_data);
199 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_0_width, pixel_0_height, 0, pixel_0_size, NULL);
200 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_1_size, pixel_1_data);
201 glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_1_width, pixel_1_height, 0, pixel_1_size, NULL);
202 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_2_size, pixel_2_data);
203 glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_2_width, pixel_2_height, 0, pixel_2_size, NULL);
204 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_3_size, pixel_3_data);
205 glCompressedTexImage2D(GL_TEXTURE_2D, 3, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_3_width, pixel_3_height, 0, pixel_3_size, NULL);
206 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_4_size, pixel_4_data);
207 glCompressedTexImage2D(GL_TEXTURE_2D, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_4_width, pixel_4_height, 0, pixel_4_size, NULL);
208 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_5_size, pixel_5_data);
209 glCompressedTexImage2D(GL_TEXTURE_2D, 5, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_5_width, pixel_5_height, 0, pixel_5_size, NULL);
210 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_6_size, pixel_6_data);
211 glCompressedTexImage2D(GL_TEXTURE_2D, 6, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_6_width, pixel_6_height, 0, pixel_6_size, NULL);
212 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_7_size, pixel_7_data);
213 glCompressedTexImage2D(GL_TEXTURE_2D, 7, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_7_width, pixel_7_height, 0, pixel_7_size, NULL);
214 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_8_size, pixel_8_data);
215 glCompressedTexImage2D(GL_TEXTURE_2D, 8, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_8_width, pixel_8_height, 0, pixel_8_size, NULL);
216 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_9_size, pixel_9_data);
217 glCompressedTexImage2D(GL_TEXTURE_2D, 9, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_9_width, pixel_9_height, 0, pixel_9_size, NULL);
218
219 EXPECT_GL_NO_ERROR();
220
221 glUseProgram(mTextureProgram);
222 glUniform1i(mTextureUniformLocation, 0);
223
224 drawQuad(mTextureProgram, "position", 0.5f);
225
226 EXPECT_GL_NO_ERROR();
227
228 glDeleteTextures(1, &buffer);
229 glDeleteTextures(1, &texture);
230
231 EXPECT_GL_NO_ERROR();
232}
233
234
235TYPED_TEST(CompressedTextureTestD3D11, PBOCompressedTexStorage)
236{
237 if (getClientVersion() < 3 && !extensionEnabled("GL_EXT_texture_compression_dxt1"))
238 {
239 return;
240 }
241
242 if (getClientVersion() < 3 && (!extensionEnabled("GL_EXT_texture_storage") || !extensionEnabled("GL_OES_rgb8_rgba8")))
243 {
244 return;
245 }
246
247 GLuint texture;
248 glGenTextures(1, &texture);
249 glBindTexture(GL_TEXTURE_2D, texture);
250 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
251 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
252 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
253 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
254
255 if (getClientVersion() < 3)
256 {
257 glTexStorage2DEXT(GL_TEXTURE_2D, pixel_levels, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_0_width, pixel_0_height);
258 }
259 else
260 {
261 glTexStorage2D(GL_TEXTURE_2D, pixel_levels, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_0_width, pixel_0_height);
262 }
263 EXPECT_GL_NO_ERROR();
264
265 GLuint buffer;
266 glGenBuffers(1, &buffer);
267 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer);
268 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixel_0_size, NULL, GL_STREAM_DRAW);
269 EXPECT_GL_NO_ERROR();
270
271 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_0_size, pixel_0_data);
272 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, pixel_0_width, pixel_0_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_0_size, NULL);
273 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_1_size, pixel_1_data);
274 glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, pixel_1_width, pixel_1_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_1_size, NULL);
275 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_2_size, pixel_2_data);
276 glCompressedTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, pixel_2_width, pixel_2_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_2_size, NULL);
277 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_3_size, pixel_3_data);
278 glCompressedTexSubImage2D(GL_TEXTURE_2D, 3, 0, 0, pixel_3_width, pixel_3_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_3_size, NULL);
279 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_4_size, pixel_4_data);
280 glCompressedTexSubImage2D(GL_TEXTURE_2D, 4, 0, 0, pixel_4_width, pixel_4_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_4_size, NULL);
281 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_5_size, pixel_5_data);
282 glCompressedTexSubImage2D(GL_TEXTURE_2D, 5, 0, 0, pixel_5_width, pixel_5_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_5_size, NULL);
283 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_6_size, pixel_6_data);
284 glCompressedTexSubImage2D(GL_TEXTURE_2D, 6, 0, 0, pixel_6_width, pixel_6_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_6_size, NULL);
285 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_7_size, pixel_7_data);
286 glCompressedTexSubImage2D(GL_TEXTURE_2D, 7, 0, 0, pixel_7_width, pixel_7_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_7_size, NULL);
287 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_8_size, pixel_8_data);
288 glCompressedTexSubImage2D(GL_TEXTURE_2D, 8, 0, 0, pixel_8_width, pixel_8_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_8_size, NULL);
289 glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pixel_9_size, pixel_9_data);
290 glCompressedTexSubImage2D(GL_TEXTURE_2D, 9, 0, 0, pixel_9_width, pixel_9_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_9_size, NULL);
291
292 EXPECT_GL_NO_ERROR();
293
294 glUseProgram(mTextureProgram);
295 glUniform1i(mTextureUniformLocation, 0);
296
297 drawQuad(mTextureProgram, "position", 0.5f);
298
299 EXPECT_GL_NO_ERROR();
300
301 glDeleteTextures(1, &texture);
302
303 EXPECT_GL_NO_ERROR();
304}