Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(919)

Side by Side Diff: gpu/command_buffer/tests/gl_compressed_copy_texture_CHROMIUM_unittest.cc

Issue 1272153004: Add glCompressedCopySubTextureCHROMIUM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: xoffset and yoffset should be validated against destination texture Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef GL_GLEXT_PROTOTYPES 5 #ifndef GL_GLEXT_PROTOTYPES
6 #define GL_GLEXT_PROTOTYPES 6 #define GL_GLEXT_PROTOTYPES
7 #endif 7 #endif
8 8
9 #include <GLES2/gl2.h> 9 #include <GLES2/gl2.h>
10 #include <GLES2/gl2ext.h> 10 #include <GLES2/gl2ext.h>
11 #include <GLES2/gl2extchromium.h> 11 #include <GLES2/gl2extchromium.h>
12 12
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "gpu/command_buffer/tests/gl_manager.h" 14 #include "gpu/command_buffer/tests/gl_manager.h"
15 #include "gpu/command_buffer/tests/gl_test_utils.h" 15 #include "gpu/command_buffer/tests/gl_test_utils.h"
16 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 #define SHADER(src) #src 19 #define SHADER(src) #src
20 20
21 namespace gpu { 21 namespace gpu {
22 22
23 namespace { 23 namespace {
24 24
25 enum CopyType { TexImage, TexSubImage };
26 const CopyType kCopyTypes[] = {
27 TexImage,
28 TexSubImage,
29 };
30
25 const uint8 kCompressedImageColor[4] = { 255u, 0u, 0u, 255u }; 31 const uint8 kCompressedImageColor[4] = { 255u, 0u, 0u, 255u };
26 32
27 // Single compressed ATC block of source pixels all set to: 33 // Single compressed ATC block of source pixels all set to:
28 // kCompressedImageColor. 34 // kCompressedImageColor.
29 const uint8 kCompressedImageATC[8] = { 35 const uint8 kCompressedImageATC[8] = {
30 0x0, 0x7c, 0x0, 0xf8, 0x55, 0x55, 0x55, 0x55 }; 36 0x0, 0x7c, 0x0, 0xf8, 0x55, 0x55, 0x55, 0x55 };
31 37
32 // Single compressed ATCIA block of source pixels all set to: 38 // Single compressed ATCIA block of source pixels all set to:
33 // kCompressedImageColor. 39 // kCompressedImageColor.
34 const uint8 kCompressedImageATCIA[16] = { 40 const uint8 kCompressedImageATCIA[16] = {
35 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 41 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
36 0x7c, 0x0, 0xf8, 0x55, 0x55, 0x55, 0x55 }; 42 0x7c, 0x0, 0xf8, 0x55, 0x55, 0x55, 0x55 };
37 43
38 // Single compressed DXT1 block of source pixels all set to: 44 // Single compressed DXT1 block of source pixels all set to:
39 // kCompressedImageColor. 45 // kCompressedImageColor.
40 const uint8 kCompressedImageDXT1[8] = { 46 const uint8 kCompressedImageDXT1[8] = {
41 0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa }; 47 0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa };
42 48
49 // Four compressed DXT1 blocks solidly colored in red, green, blue and black:
50 // [R][G]
51 // [B][b]
52 const uint8 kCompressedImageDXT1RGB[32] = {
53 0x0, 0xf8, 0x0, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa,
54 0xe0, 0x7, 0xe0, 0x7, 0xaa, 0xaa, 0xaa, 0xaa,
55 0x1f, 0x0, 0x1f, 0x0, 0xaa, 0xaa, 0xaa, 0xaa,
56 0x0, 0x0, 0x0, 0x0, 0xaa, 0xaa, 0xaa, 0xaa };
57
43 // Single compressed DXT5 block of source pixels all set to: 58 // Single compressed DXT5 block of source pixels all set to:
44 // kCompressedImageColor. 59 // kCompressedImageColor.
45 const uint8 kCompressedImageDXT5[16] = { 60 const uint8 kCompressedImageDXT5[16] = {
46 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 61 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
47 0xf8, 0x0, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa }; 62 0xf8, 0x0, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa };
48 63
49 // Single compressed DXT1 block of source pixels all set to: 64 // Single compressed DXT1 block of source pixels all set to:
50 // kCompressedImageColor. 65 // kCompressedImageColor.
51 const uint8 kCompressedImageETC1[8] = { 66 const uint8 kCompressedImageETC1[8] = {
52 0x0, 0x0, 0xf8, 0x2, 0xff, 0xff, 0x0, 0x0 }; 67 0x0, 0x0, 0xf8, 0x2, 0xff, 0xff, 0x0, 0x0 };
53 68
69 // Single block of zeroes, used for texture pre-allocation.
70 const uint8 kInvalidCompressedImage[8] = {
71 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
72
73 // Four blocks of zeroes, used for texture pre-allocation.
74 const uint8 kInvalidCompressedImageLarge[32] = {
75 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
76 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
77 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
78 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
79
54 void glEnableDisable(GLint param, GLboolean value) { 80 void glEnableDisable(GLint param, GLboolean value) {
55 if (value) 81 if (value)
56 glEnable(param); 82 glEnable(param);
57 else 83 else
58 glDisable(param); 84 glDisable(param);
59 } 85 }
60 86
61 } // unnamed namespace 87 } // unnamed namespace
62 88
63 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. 89 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension.
64 class GLCompressedCopyTextureCHROMIUMTest 90 class GLCompressedCopyTextureCHROMIUMTest
65 : public testing::Test { 91 : public testing::Test,
92 public ::testing::WithParamInterface<CopyType> {
66 protected: 93 protected:
67 void SetUp() override { 94 void SetUp() override {
68 gl_.Initialize(GLManager::Options()); 95 gl_.Initialize(GLManager::Options());
69 96
70 glGenTextures(2, textures_); 97 glGenTextures(2, textures_);
71 } 98 }
72 99
73 void TearDown() override { 100 void TearDown() override {
74 glDeleteTextures(2, textures_); 101 glDeleteTextures(2, textures_);
75 gl_.Destroy(); 102 gl_.Destroy();
(...skipping 17 matching lines...) Expand all
93 } 120 }
94 ); 121 );
95 return GLTestHelper::LoadProgram(v_shader_src, f_shader_src); 122 return GLTestHelper::LoadProgram(v_shader_src, f_shader_src);
96 } 123 }
97 124
98 GLManager gl_; 125 GLManager gl_;
99 GLuint textures_[2]; 126 GLuint textures_[2];
100 GLuint framebuffer_id_; 127 GLuint framebuffer_id_;
101 }; 128 };
102 129
130 INSTANTIATE_TEST_CASE_P(CopyType,
131 GLCompressedCopyTextureCHROMIUMTest,
132 ::testing::ValuesIn(kCopyTypes));
133
103 // Test to ensure that the basic functionality of the extension works. 134 // Test to ensure that the basic functionality of the extension works.
104 TEST_F(GLCompressedCopyTextureCHROMIUMTest, Basic) { 135 TEST_P(GLCompressedCopyTextureCHROMIUMTest, Basic) {
105 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { 136 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
106 LOG(INFO) << 137 LOG(INFO) <<
107 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; 138 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
108 return; 139 return;
109 } 140 }
110 141
142 CopyType copy_type = GetParam();
143
111 glBindTexture(GL_TEXTURE_2D, textures_[0]); 144 glBindTexture(GL_TEXTURE_2D, textures_[0]);
112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 145 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
113 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 146 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
114 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 147 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
115 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 148 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
116 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 149 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
117 4, 4, 0, 150 4, 4, 0,
118 sizeof(kCompressedImageDXT1), kCompressedImageDXT1); 151 sizeof(kCompressedImageDXT1), kCompressedImageDXT1);
119 EXPECT_TRUE(glGetError() == GL_NO_ERROR); 152 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
120 153
121 glBindTexture(GL_TEXTURE_2D, textures_[1]); 154 glBindTexture(GL_TEXTURE_2D, textures_[1]);
122 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 155 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
123 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 156 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
124 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 157 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
125 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 158 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
126 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]); 159 if (copy_type == TexImage) {
160 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]);
161 } else {
162 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
163 4, 4, 0,
164 sizeof(kInvalidCompressedImage),
165 kInvalidCompressedImage);
166
167 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0],
168 textures_[1], 0, 0, 0, 0, 4, 4);
169 }
127 EXPECT_TRUE(glGetError() == GL_NO_ERROR); 170 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
128 171
129 // Load shader program. 172 // Load shader program.
130 GLuint program = LoadProgram(); 173 GLuint program = LoadProgram();
131 ASSERT_NE(program, 0u); 174 ASSERT_NE(program, 0u);
132 GLint position_loc = glGetAttribLocation(program, "a_position"); 175 GLint position_loc = glGetAttribLocation(program, "a_position");
133 GLint texture_loc = glGetUniformLocation(program, "u_texture"); 176 GLint texture_loc = glGetUniformLocation(program, "u_texture");
134 ASSERT_NE(position_loc, -1); 177 ASSERT_NE(position_loc, -1);
135 ASSERT_NE(texture_loc, -1); 178 ASSERT_NE(texture_loc, -1);
136 glUseProgram(program); 179 glUseProgram(program);
137 180
138 // Load geometry. 181 // Load geometry.
139 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc); 182 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc);
140 ASSERT_NE(vbo, 0u); 183 ASSERT_NE(vbo, 0u);
141 184
142 // Load texture. 185 // Load texture.
143 glActiveTexture(GL_TEXTURE0); 186 glActiveTexture(GL_TEXTURE0);
144 glBindTexture(GL_TEXTURE_2D, textures_[1]); 187 glBindTexture(GL_TEXTURE_2D, textures_[1]);
145 glUniform1i(texture_loc, 0); 188 glUniform1i(texture_loc, 0);
146 189
147 // Draw. 190 // Draw.
148 glDrawArrays(GL_TRIANGLES, 0, 6); 191 glDrawArrays(GL_TRIANGLES, 0, 6);
149 glFlush(); 192 glFlush();
150 193
151 GLTestHelper::CheckPixels(0, 0, 4, 4, 0, kCompressedImageColor); 194 GLTestHelper::CheckPixels(0, 0, 4, 4, 0, kCompressedImageColor);
152 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 195 EXPECT_TRUE(GL_NO_ERROR == glGetError());
153 } 196 }
154 197
155 TEST_F(GLCompressedCopyTextureCHROMIUMTest, InternalFormat) { 198 TEST_P(GLCompressedCopyTextureCHROMIUMTest, InternalFormat) {
199 CopyType copy_type = GetParam();
200
156 struct Image { 201 struct Image {
157 const GLint format; 202 const GLint format;
158 const uint8* data; 203 const uint8* data;
159 const GLsizei data_size; 204 const GLsizei data_size;
160 205
161 Image(const GLint format, const uint8* data, const GLsizei data_size) : 206 Image(const GLint format, const uint8* data, const GLsizei data_size) :
162 format(format), data(data), data_size(data_size) {} 207 format(format), data(data), data_size(data_size) {}
163 }; 208 };
164 ScopedVector<Image> supported_formats; 209 ScopedVector<Image> supported_formats;
165 210
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 247 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
203 glCompressedTexImage2D(GL_TEXTURE_2D, 0, image->format, 248 glCompressedTexImage2D(GL_TEXTURE_2D, 0, image->format,
204 4, 4, 0, image->data_size, image->data); 249 4, 4, 0, image->data_size, image->data);
205 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 250 EXPECT_TRUE(GL_NO_ERROR == glGetError());
206 251
207 glBindTexture(GL_TEXTURE_2D, textures_[1]); 252 glBindTexture(GL_TEXTURE_2D, textures_[1]);
208 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 253 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
209 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 254 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
210 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 255 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
211 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 256 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
212 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]); 257 if (copy_type == TexImage) {
258 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0],
259 textures_[1]);
260 } else {
261 glCompressedTexImage2D(GL_TEXTURE_2D, 0, image->format, 4, 4, 0,
262 sizeof(kInvalidCompressedImage),
263 kInvalidCompressedImage);
264
265 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0],
266 textures_[1], 0, 0, 0, 0, 4, 4);
267 }
213 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 268 EXPECT_TRUE(GL_NO_ERROR == glGetError());
214 } 269 }
215 } 270 }
216 271
217 TEST_F(GLCompressedCopyTextureCHROMIUMTest, InternalFormatNotSupported) { 272 TEST_P(GLCompressedCopyTextureCHROMIUMTest, InternalFormatNotSupported) {
218 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { 273 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
219 LOG(INFO) << 274 LOG(INFO) <<
220 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; 275 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
221 return; 276 return;
222 } 277 }
223 278
279 CopyType copy_type = GetParam();
280
224 const uint8 kUncompressedPixels[1 * 4] = { 255u, 0u, 0u, 255u }; 281 const uint8 kUncompressedPixels[1 * 4] = { 255u, 0u, 0u, 255u };
225 282
226 glBindTexture(GL_TEXTURE_2D, textures_[0]); 283 glBindTexture(GL_TEXTURE_2D, textures_[0]);
227 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 284 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
228 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 285 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
229 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 286 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
230 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 287 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
231 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 288 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
232 kUncompressedPixels); 289 kUncompressedPixels);
233 EXPECT_TRUE(glGetError() == GL_NO_ERROR); 290 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
234 291
235 glBindTexture(GL_TEXTURE_2D, textures_[1]); 292 glBindTexture(GL_TEXTURE_2D, textures_[1]);
236 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 293 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
237 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 294 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
238 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 295 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
239 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 296 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
240 297
241 // Check that the GL_RGBA format reports an error. 298 // Check that the GL_RGBA format reports an error.
242 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]); 299 if (copy_type == TexImage) {
300 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]);
301 } else {
302 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
303 kUncompressedPixels);
304
305 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0],
306 textures_[1], 0, 0, 0, 0, 1, 1);
307 }
243 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()); 308 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError());
244 } 309 }
245 310
246 // Validate that some basic GL state is not touched upon execution of 311 // Validate that some basic GL state is not touched upon execution of
247 // the extension. 312 // the extension.
248 TEST_F(GLCompressedCopyTextureCHROMIUMTest, BasicStatePreservation) { 313 TEST_P(GLCompressedCopyTextureCHROMIUMTest, BasicStatePreservation) {
249 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { 314 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
250 LOG(INFO) << 315 LOG(INFO) <<
251 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; 316 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
252 return; 317 return;
253 } 318 }
254 319
320 CopyType copy_type = GetParam();
321
255 glBindTexture(GL_TEXTURE_2D, textures_[0]); 322 glBindTexture(GL_TEXTURE_2D, textures_[0]);
256 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 323 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
257 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 324 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
258 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 325 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
259 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 326 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
260 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 327 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
261 4, 4, 0, 328 4, 4, 0,
262 sizeof(kCompressedImageDXT1), kCompressedImageDXT1); 329 sizeof(kCompressedImageDXT1), kCompressedImageDXT1);
263 EXPECT_TRUE(glGetError() == GL_NO_ERROR); 330 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
264 331
265 glBindTexture(GL_TEXTURE_2D, textures_[1]); 332 glBindTexture(GL_TEXTURE_2D, textures_[1]);
266 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 333 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
267 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 334 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
268 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 335 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
269 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 336 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
270 337
338 if (copy_type == TexSubImage) {
339 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
340 4, 4, 0,
341 sizeof(kInvalidCompressedImage),
342 kInvalidCompressedImage);
343 }
344
271 GLboolean reference_settings[2] = { GL_TRUE, GL_FALSE }; 345 GLboolean reference_settings[2] = { GL_TRUE, GL_FALSE };
272 for (int x = 0; x < 2; ++x) { 346 for (int x = 0; x < 2; ++x) {
273 GLboolean setting = reference_settings[x]; 347 GLboolean setting = reference_settings[x];
274 glEnableDisable(GL_DEPTH_TEST, setting); 348 glEnableDisable(GL_DEPTH_TEST, setting);
275 glEnableDisable(GL_SCISSOR_TEST, setting); 349 glEnableDisable(GL_SCISSOR_TEST, setting);
276 glEnableDisable(GL_STENCIL_TEST, setting); 350 glEnableDisable(GL_STENCIL_TEST, setting);
277 glEnableDisable(GL_CULL_FACE, setting); 351 glEnableDisable(GL_CULL_FACE, setting);
278 glEnableDisable(GL_BLEND, setting); 352 glEnableDisable(GL_BLEND, setting);
279 glColorMask(setting, setting, setting, setting); 353 glColorMask(setting, setting, setting, setting);
280 glDepthMask(setting); 354 glDepthMask(setting);
281 355
282 glActiveTexture(GL_TEXTURE1 + x); 356 glActiveTexture(GL_TEXTURE1 + x);
283 357
284 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]); 358 if (copy_type == TexImage) {
359 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0],
360 textures_[1]);
361 } else {
362 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0],
363 textures_[1], 0, 0, 0, 0, 4, 4);
364 }
285 EXPECT_TRUE(glGetError() == GL_NO_ERROR); 365 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
286 366
287 EXPECT_EQ(setting, glIsEnabled(GL_DEPTH_TEST)); 367 EXPECT_EQ(setting, glIsEnabled(GL_DEPTH_TEST));
288 EXPECT_EQ(setting, glIsEnabled(GL_SCISSOR_TEST)); 368 EXPECT_EQ(setting, glIsEnabled(GL_SCISSOR_TEST));
289 EXPECT_EQ(setting, glIsEnabled(GL_STENCIL_TEST)); 369 EXPECT_EQ(setting, glIsEnabled(GL_STENCIL_TEST));
290 EXPECT_EQ(setting, glIsEnabled(GL_CULL_FACE)); 370 EXPECT_EQ(setting, glIsEnabled(GL_CULL_FACE));
291 EXPECT_EQ(setting, glIsEnabled(GL_BLEND)); 371 EXPECT_EQ(setting, glIsEnabled(GL_BLEND));
292 372
293 GLboolean bool_array[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE }; 373 GLboolean bool_array[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE };
294 glGetBooleanv(GL_DEPTH_WRITEMASK, bool_array); 374 glGetBooleanv(GL_DEPTH_WRITEMASK, bool_array);
295 EXPECT_EQ(setting, bool_array[0]); 375 EXPECT_EQ(setting, bool_array[0]);
296 376
297 bool_array[0] = GL_FALSE; 377 bool_array[0] = GL_FALSE;
298 glGetBooleanv(GL_COLOR_WRITEMASK, bool_array); 378 glGetBooleanv(GL_COLOR_WRITEMASK, bool_array);
299 EXPECT_EQ(setting, bool_array[0]); 379 EXPECT_EQ(setting, bool_array[0]);
300 EXPECT_EQ(setting, bool_array[1]); 380 EXPECT_EQ(setting, bool_array[1]);
301 EXPECT_EQ(setting, bool_array[2]); 381 EXPECT_EQ(setting, bool_array[2]);
302 EXPECT_EQ(setting, bool_array[3]); 382 EXPECT_EQ(setting, bool_array[3]);
303 383
304 GLint active_texture = 0; 384 GLint active_texture = 0;
305 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); 385 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
306 EXPECT_EQ(GL_TEXTURE1 + x, active_texture); 386 EXPECT_EQ(GL_TEXTURE1 + x, active_texture);
307 } 387 }
308 388
309 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 389 EXPECT_TRUE(GL_NO_ERROR == glGetError());
310 }; 390 };
311 391
312 // Verify that invocation of the extension does not modify the bound 392 // Verify that invocation of the extension does not modify the bound
313 // texture state. 393 // texture state.
314 TEST_F(GLCompressedCopyTextureCHROMIUMTest, TextureStatePreserved) { 394 TEST_P(GLCompressedCopyTextureCHROMIUMTest, TextureStatePreserved) {
315 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { 395 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
316 LOG(INFO) << 396 LOG(INFO) <<
317 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; 397 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
318 return; 398 return;
319 } 399 }
320 400
401 CopyType copy_type = GetParam();
402
321 glBindTexture(GL_TEXTURE_2D, textures_[0]); 403 glBindTexture(GL_TEXTURE_2D, textures_[0]);
322 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 404 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
323 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 405 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
324 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 406 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
325 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 407 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
326 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 408 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
327 4, 4, 0, 409 4, 4, 0,
328 sizeof(kCompressedImageDXT1), kCompressedImageDXT1); 410 sizeof(kCompressedImageDXT1), kCompressedImageDXT1);
329 EXPECT_TRUE(glGetError() == GL_NO_ERROR); 411 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
330 412
331 glBindTexture(GL_TEXTURE_2D, textures_[1]); 413 glBindTexture(GL_TEXTURE_2D, textures_[1]);
332 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 414 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
333 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 415 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
334 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 416 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
335 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 417 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
336 418
419 if (copy_type == TexSubImage) {
420 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
421 4, 4, 0,
422 sizeof(kInvalidCompressedImage),
423 kInvalidCompressedImage);
424 }
425
337 GLuint texture_ids[2]; 426 GLuint texture_ids[2];
338 glGenTextures(2, texture_ids); 427 glGenTextures(2, texture_ids);
339 428
340 glActiveTexture(GL_TEXTURE0); 429 glActiveTexture(GL_TEXTURE0);
341 glBindTexture(GL_TEXTURE_2D, texture_ids[0]); 430 glBindTexture(GL_TEXTURE_2D, texture_ids[0]);
342 431
343 glActiveTexture(GL_TEXTURE1); 432 glActiveTexture(GL_TEXTURE1);
344 glBindTexture(GL_TEXTURE_2D, texture_ids[1]); 433 glBindTexture(GL_TEXTURE_2D, texture_ids[1]);
345 434
346 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]); 435 if (copy_type == TexImage) {
436 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]);
437 } else {
438 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0],
439 textures_[1], 0, 0, 0, 0, 4, 4);
440 }
347 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 441 EXPECT_TRUE(GL_NO_ERROR == glGetError());
348 442
349 GLint active_texture = 0; 443 GLint active_texture = 0;
350 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); 444 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
351 EXPECT_EQ(GL_TEXTURE1, active_texture); 445 EXPECT_EQ(GL_TEXTURE1, active_texture);
352 446
353 GLint bound_texture = 0; 447 GLint bound_texture = 0;
354 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); 448 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture);
355 EXPECT_EQ(texture_ids[1], static_cast<GLuint>(bound_texture)); 449 EXPECT_EQ(texture_ids[1], static_cast<GLuint>(bound_texture));
356 glBindTexture(GL_TEXTURE_2D, 0); 450 glBindTexture(GL_TEXTURE_2D, 0);
357 451
358 bound_texture = 0; 452 bound_texture = 0;
359 glActiveTexture(GL_TEXTURE0); 453 glActiveTexture(GL_TEXTURE0);
360 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); 454 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture);
361 EXPECT_EQ(texture_ids[0], static_cast<GLuint>(bound_texture)); 455 EXPECT_EQ(texture_ids[0], static_cast<GLuint>(bound_texture));
362 glBindTexture(GL_TEXTURE_2D, 0); 456 glBindTexture(GL_TEXTURE_2D, 0);
363 457
364 glDeleteTextures(2, texture_ids); 458 glDeleteTextures(2, texture_ids);
365 459
366 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 460 EXPECT_TRUE(GL_NO_ERROR == glGetError());
367 } 461 }
368 462
463 TEST_F(GLCompressedCopyTextureCHROMIUMTest, CopySubTextureDimension) {
464 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
465 LOG(INFO) <<
466 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
467 return;
468 }
469
470 glBindTexture(GL_TEXTURE_2D, textures_[0]);
471 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
472 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
473 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
474 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
475 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
476 8, 8, 0,
477 sizeof(kCompressedImageDXT1RGB),
478 kCompressedImageDXT1RGB);
479 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
480
481 glBindTexture(GL_TEXTURE_2D, textures_[1]);
482 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
483 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
484 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
485 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
486 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
487 8, 8, 0,
488 sizeof(kInvalidCompressedImageLarge),
489 kInvalidCompressedImageLarge);
490
491 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0],
492 textures_[1], 4, 4, 0, 0, 4, 4);
493 EXPECT_TRUE(GL_NO_ERROR == glGetError());
494
495 // Reset the destination texture as it might have been converted to RGBA.
496 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
497 8, 8, 0,
498 sizeof(kInvalidCompressedImageLarge),
499 kInvalidCompressedImageLarge);
500
501 // xoffset < 0
502 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1],
503 -4, 4, 0, 0, 4, 4);
504 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE);
505
506 // x < 0
507 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1],
508 4, 4, -4, 0, 4, 4);
509 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE);
510
511 // xoffset + width > dest_width
512 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1],
513 8, 8, 0, 0, 4, 4);
514 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE);
515
516 // x + width > source_width
517 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1],
518 0, 0, 8, 8, 4, 4);
519 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE);
520
521 // xoffset not within block-boundary
522 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1],
523 3, 0, 0, 0, 4, 4);
524 EXPECT_TRUE(glGetError() == GL_INVALID_OPERATION);
525
526 // x not within block-boundary
527 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1],
528 0, 0, 3, 0, 4, 4);
529 EXPECT_TRUE(glGetError() == GL_INVALID_OPERATION);
530 }
531
532 TEST_F(GLCompressedCopyTextureCHROMIUMTest, CopySubTextureOffset) {
533 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
534 LOG(INFO) <<
535 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
536 return;
537 }
538
539 glBindTexture(GL_TEXTURE_2D, textures_[0]);
540 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
541 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
542 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
543 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
544 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
545 8, 8, 0,
546 sizeof(kCompressedImageDXT1RGB),
547 kCompressedImageDXT1RGB);
548 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
549
550 glBindTexture(GL_TEXTURE_2D, textures_[1]);
551 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
552 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
553 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
554 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
555 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
556 8, 8, 0,
557 sizeof(kInvalidCompressedImageLarge),
558 kInvalidCompressedImageLarge);
559
560 // Load shader program.
561 GLuint program = LoadProgram();
562 ASSERT_NE(program, 0u);
563 GLint position_loc = glGetAttribLocation(program, "a_position");
564 GLint texture_loc = glGetUniformLocation(program, "u_texture");
565 ASSERT_NE(position_loc, -1);
566 ASSERT_NE(texture_loc, -1);
567 glUseProgram(program);
568
569 // Load geometry.
570 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc);
571 ASSERT_NE(vbo, 0u);
572
573 // Load texture.
574 glActiveTexture(GL_TEXTURE0);
575 glBindTexture(GL_TEXTURE_2D, textures_[1]);
576 glUniform1i(texture_loc, 0);
577
578 const uint8 kBlack[1 * 4] = {0u, 0u, 0u, 255u};
579 const uint8 kRed[1 * 4] = {255u, 0u, 0u, 255u};
580 const uint8 kGreen[1 * 4] = {0u, 255u, 0u, 255u};
581 const uint8 kBlue[1 * 4] = {0u, 0u, 255u, 255u};
582
583 // Copy each block one by one in a clockwise fashion. Note that we reset the
584 // destination texture after each copy operation. That's because on some
585 // platforms we might fallback into replacing the compressed destination
586 // texture with an uncompressed one.
587
588 // Move blue block up.
589 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0],
590 textures_[1], 0, 0, 0, 4, 4, 4);
591 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
592
593 glDrawArrays(GL_TRIANGLES, 0, 6);
594 glFlush();
595 GLTestHelper::CheckPixels(0, 0, 2, 2, 0, kBlue);
596
597 glBindTexture(GL_TEXTURE_2D, textures_[1]);
598 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
599 8, 8, 0,
600 sizeof(kInvalidCompressedImageLarge),
601 kInvalidCompressedImageLarge);
602
603 // Move red block right.
604 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0],
605 textures_[1], 4, 0, 0, 0, 4, 4);
606 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
607
608 glDrawArrays(GL_TRIANGLES, 0, 6);
609 glFlush();
610 GLTestHelper::CheckPixels(2, 0, 2, 2, 0, kRed);
611
612 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
613 8, 8, 0,
614 sizeof(kInvalidCompressedImageLarge),
615 kInvalidCompressedImageLarge);
616
617 // Move green block down.
618 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0],
619 textures_[1], 4, 4, 4, 0, 4, 4);
620 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
621
622 glDrawArrays(GL_TRIANGLES, 0, 6);
623 glFlush();
624 GLTestHelper::CheckPixels(2, 2, 2, 2, 0, kGreen);
625
626 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
627 8, 8, 0,
628 sizeof(kInvalidCompressedImageLarge),
629 kInvalidCompressedImageLarge);
630
631 // Move black block left.
632 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0],
633 textures_[1], 0, 4, 4, 4, 4, 4);
634 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
635
636 glDrawArrays(GL_TRIANGLES, 0, 6);
637 glFlush();
638 GLTestHelper::CheckPixels(0, 2, 2, 2, 0, kBlack);
639
640 EXPECT_TRUE(GL_NO_ERROR == glGetError());
641 }
642
643 TEST_F(GLCompressedCopyTextureCHROMIUMTest, CopySubTexturePreservation) {
644 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
645 LOG(INFO) <<
646 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
647 return;
648 }
649
650 glBindTexture(GL_TEXTURE_2D, textures_[0]);
651 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
652 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
653 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
654 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
655 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
656 4, 4, 0,
657 sizeof(kCompressedImageDXT1),
658 kCompressedImageDXT1);
659 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
660
661 glBindTexture(GL_TEXTURE_2D, textures_[1]);
662 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
663 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
664 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
665 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
666 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
667 8, 8, 0,
668 sizeof(kCompressedImageDXT1RGB),
669 kCompressedImageDXT1RGB);
670
671 // Copy entire first texture into the second, replacing the green block:
672 // [R][R]
673 // [B][b]
674 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0],
675 textures_[1], 4, 0, 0, 0, 4, 4);
676 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
677
678 // Load shader program.
679 GLuint program = LoadProgram();
680 ASSERT_NE(program, 0u);
681 GLint position_loc = glGetAttribLocation(program, "a_position");
682 GLint texture_loc = glGetUniformLocation(program, "u_texture");
683 ASSERT_NE(position_loc, -1);
684 ASSERT_NE(texture_loc, -1);
685 glUseProgram(program);
686
687 // Load geometry.
688 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc);
689 ASSERT_NE(vbo, 0u);
690
691 // Load texture.
692 glActiveTexture(GL_TEXTURE0);
693 glBindTexture(GL_TEXTURE_2D, textures_[1]);
694 glUniform1i(texture_loc, 0);
695
696 // Draw.
697 glDrawArrays(GL_TRIANGLES, 0, 6);
698 glFlush();
699
700 const uint8 kBlack[1 * 4] = {0u, 0u, 0u, 255u};
701 const uint8 kRed[1 * 4] = {255u, 0u, 0u, 255u};
702 const uint8 kBlue[1 * 4] = {0u, 0u, 255u, 255u};
703
704 // Note that while destination texture is 8 x 8 pixels the viewport is only
705 // 4 x 4.
706 GLTestHelper::CheckPixels(0, 0, 4, 2, 0, kRed);
707 GLTestHelper::CheckPixels(0, 2, 2, 2, 0, kBlue);
708 GLTestHelper::CheckPixels(2, 2, 2, 2, 0, kBlack);
709 EXPECT_TRUE(GL_NO_ERROR == glGetError());
710 }
711
369 } // namespace gpu 712 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698