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

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

Issue 2609393002: Add CopyTexture gl_tests for level == 0 (Closed)
Patch Set: Add TODO to support level > 0 Created 3 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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>
(...skipping 11 matching lines...) Expand all
22 namespace gpu { 22 namespace gpu {
23 23
24 namespace { 24 namespace {
25 25
26 enum CopyType { TexImage, TexSubImage }; 26 enum CopyType { TexImage, TexSubImage };
27 const CopyType kCopyTypes[] = { 27 const CopyType kCopyTypes[] = {
28 TexImage, 28 TexImage,
29 TexSubImage, 29 TexSubImage,
30 }; 30 };
31 31
32 struct FormatType {
33 GLenum internal_format;
34 GLenum format;
35 GLenum type;
36 };
37
38 static const char* kSimpleVertexShaderES2 =
39 "attribute vec2 a_position;\n"
40 "varying vec2 v_texCoord;\n"
41 "void main() {\n"
42 " gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);\n"
43 " v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5;\n"
44 "}\n";
45
32 static const char* kSimpleVertexShaderES3 = 46 static const char* kSimpleVertexShaderES3 =
33 "#version 300 es\n" 47 "#version 300 es\n"
34 "in vec2 a_position;\n" 48 "in vec2 a_position;\n"
35 "out vec2 v_texCoord;\n" 49 "out vec2 v_texCoord;\n"
36 "void main() {\n" 50 "void main() {\n"
37 " gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);\n" 51 " gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);\n"
38 " v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5;\n" 52 " v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5;\n"
39 "}\n"; 53 "}\n";
40 54
41 std::string GetFragmentShaderSource(GLenum format) { 55 std::string GetFragmentShaderSource(GLenum format, bool is_es3) {
42 std::string source; 56 std::string source;
43 source += std::string( 57 if (is_es3) {
44 "#version 300 es\n" 58 source +=
45 "precision mediump float;\n"); 59 "#version 300 es\n"
60 "#define VARYING in\n"
61 "#define FRAGCOLOR frag_color\n"
62 "#define TextureLookup texture\n";
63 } else {
64 source +=
65 "#define VARYING varying\n"
66 "#define FRAGCOLOR gl_FragColor\n"
67 "#define TextureLookup texture2D\n";
68 }
69 source += "precision mediump float;\n";
70
46 if (gles2::GLES2Util::IsSignedIntegerFormat(format)) { 71 if (gles2::GLES2Util::IsSignedIntegerFormat(format)) {
47 source += std::string("#define SamplerType isampler2D\n"); 72 source += std::string("#define SamplerType isampler2D\n");
48 source += std::string("#define TextureType ivec4\n"); 73 source += std::string("#define TextureType ivec4\n");
49 source += std::string("#define ScaleValue 255.0\n"); 74 source += std::string("#define ScaleValue 255.0\n");
50 } else if (gles2::GLES2Util::IsUnsignedIntegerFormat(format)) { 75 } else if (gles2::GLES2Util::IsUnsignedIntegerFormat(format)) {
51 source += std::string("#define SamplerType usampler2D\n"); 76 source += std::string("#define SamplerType usampler2D\n");
52 source += std::string("#define TextureType uvec4\n"); 77 source += std::string("#define TextureType uvec4\n");
53 source += std::string("#define ScaleValue 255.0\n"); 78 source += std::string("#define ScaleValue 255.0\n");
54 } else { 79 } else {
55 source += std::string("#define SamplerType sampler2D\n"); 80 source += std::string("#define SamplerType sampler2D\n");
56 source += std::string("#define TextureType vec4\n"); 81 source += std::string("#define TextureType vec4\n");
57 source += std::string("#define ScaleValue 1.0\n"); 82 source += std::string("#define ScaleValue 1.0\n");
58 } 83 }
59 84
85 if (is_es3)
86 source += "out vec4 frag_color;\n";
87
60 source += std::string( 88 source += std::string(
61 "uniform mediump SamplerType u_texture;\n" 89 "uniform mediump SamplerType u_texture;\n"
62 "in vec2 v_texCoord;\n" 90 "VARYING vec2 v_texCoord;\n"
63 "out vec4 fragData;\n"
64 "void main() {\n" 91 "void main() {\n"
65 " TextureType color = texture(u_texture, v_texCoord);\n" 92 " TextureType color = TextureLookup(u_texture, v_texCoord);\n"
66 " fragData = vec4(color) / ScaleValue;\n" 93 " FRAGCOLOR = vec4(color) / ScaleValue;\n"
67 "}\n"); 94 "}\n");
68 return source; 95 return source;
69 } 96 }
70 97
71 void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t* color) { 98 void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t* color) {
72 color[0] = r; 99 color[0] = r;
73 color[1] = g; 100 color[1] = g;
74 color[2] = b; 101 color[2] = b;
75 color[3] = a; 102 color[3] = a;
76 } 103 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 210 }
184 } 211 }
185 212
186 } // namespace 213 } // namespace
187 214
188 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. 215 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension.
189 class GLCopyTextureCHROMIUMTest 216 class GLCopyTextureCHROMIUMTest
190 : public testing::Test, 217 : public testing::Test,
191 public ::testing::WithParamInterface<CopyType> { 218 public ::testing::WithParamInterface<CopyType> {
192 protected: 219 protected:
193
194 void CreateAndBindDestinationTextureAndFBO(GLenum target) { 220 void CreateAndBindDestinationTextureAndFBO(GLenum target) {
195 glGenTextures(2, textures_); 221 glGenTextures(2, textures_);
196 glBindTexture(target, textures_[1]); 222 glBindTexture(target, textures_[1]);
197 223
198 // Some drivers (NVidia/SGX) require texture settings to be a certain way or 224 // Some drivers (NVidia/SGX) require texture settings to be a certain way or
199 // they won't report FRAMEBUFFER_COMPLETE. 225 // they won't report FRAMEBUFFER_COMPLETE.
200 glTexParameterf(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 226 glTexParameterf(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
201 glTexParameterf(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 227 glTexParameterf(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
202 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 228 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
203 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 229 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
204 230
205 glGenFramebuffers(1, &framebuffer_id_); 231 glGenFramebuffers(1, &framebuffer_id_);
206 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_); 232 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_);
207 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, 233 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target,
208 textures_[1], 0); 234 textures_[1], 0);
209 } 235 }
210 236
211 void SetUp() override { 237 void SetUp() override {
212 gl_.Initialize(GLManager::Options()); 238 GLManager::Options options;
239 options.size = gfx::Size(64, 64);
240 gl_.Initialize(options);
241
242 width_ = 8;
243 height_ = 8;
213 } 244 }
214 245
215 void TearDown() override { gl_.Destroy(); } 246 void TearDown() override { gl_.Destroy(); }
216 247
217 void CreateBackingForTexture(GLenum target, GLsizei width, GLsizei height) { 248 void CreateBackingForTexture(GLenum target, GLsizei width, GLsizei height) {
218 if (target == GL_TEXTURE_RECTANGLE_ARB) { 249 if (target == GL_TEXTURE_RECTANGLE_ARB) {
219 GLuint image_id = glCreateGpuMemoryBufferImageCHROMIUM( 250 GLuint image_id = glCreateGpuMemoryBufferImageCHROMIUM(
220 width, height, GL_RGBA, GL_READ_WRITE_CHROMIUM); 251 width, height, GL_RGBA, GL_READ_WRITE_CHROMIUM);
221 glBindTexImage2DCHROMIUM(target, image_id); 252 glBindTexImage2DCHROMIUM(target, image_id);
222 } else { 253 } else {
223 glTexImage2D(target, 0, GL_RGBA, width, height, 0, GL_RGBA, 254 glTexImage2D(target, 0, GL_RGBA, width, height, 0, GL_RGBA,
224 GL_UNSIGNED_BYTE, nullptr); 255 GL_UNSIGNED_BYTE, nullptr);
225 } 256 }
226 } 257 }
227 258
259 GLuint CreateDrawingTexture(GLenum target, GLsizei width, GLsizei height) {
260 GLuint texture = 0;
261 glGenTextures(1, &texture);
262 glBindTexture(target, texture);
263 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
264 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
265 CreateBackingForTexture(GL_TEXTURE_2D, width, height);
266 return texture;
267 }
268
269 GLuint CreateDrawingFBO(GLenum target, GLuint texture) {
270 GLuint framebuffer = 0;
271 glGenFramebuffers(1, &framebuffer);
272 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
273 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target,
274 texture, 0);
275 return framebuffer;
276 }
277
228 GLenum ExtractFormatFrom(GLenum internalformat) { 278 GLenum ExtractFormatFrom(GLenum internalformat) {
229 switch (internalformat) { 279 switch (internalformat) {
230 case GL_RGBA8_OES: 280 case GL_RGBA8_OES:
231 return GL_RGBA; 281 return GL_RGBA;
232 case GL_RGB8_OES: 282 case GL_RGB8_OES:
233 return GL_RGB; 283 return GL_RGB;
234 case GL_BGRA8_EXT: 284 case GL_BGRA8_EXT:
235 return GL_BGRA_EXT; 285 return GL_BGRA_EXT;
236 default: 286 default:
237 NOTREACHED(); 287 NOTREACHED();
238 return GL_NONE; 288 return GL_NONE;
239 } 289 }
240 } 290 }
241 291
292 void RunCopyTexture(GLenum target,
293 CopyType copy_type,
294 FormatType src_format_type,
295 GLint source_level,
296 FormatType dest_format_type,
297 GLint dest_level,
298 bool is_es3) {
299 const int src_channel_count = gles2::GLES2Util::ElementsPerGroup(
300 src_format_type.format, src_format_type.type);
301 uint8_t color[4] = {1u, 63u, 127u, 255u};
302 std::unique_ptr<uint8_t[]> pixels(new uint8_t[width_ * height_ * 4]);
303 for (int i = 0; i < width_ * height_ * src_channel_count;
304 i += src_channel_count)
305 for (int j = 0; j < src_channel_count; ++j)
306 pixels[i + j] = color[j];
307 uint8_t expected_color[4];
308 uint8_t mask[4];
309 getExpectedColor(src_format_type.internal_format,
310 dest_format_type.internal_format, color, expected_color,
311 mask);
312
313 glGenTextures(2, textures_);
314 glBindTexture(target, textures_[0]);
315 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
316 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
317 glTexImage2D(target, source_level, src_format_type.internal_format, width_,
318 height_, 0, src_format_type.format, src_format_type.type,
319 pixels.get());
320 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
321 glBindTexture(target, textures_[1]);
322 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
323 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
324 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
325 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
326
327 // TODO(qiankun.miao@intel.com): Upgrade glCopyTextureCHROMIUM and
328 // glCopySubTextureCHROMIUM to support copying from level > 0 of source
329 // texture to level > 0 of dest texture.
330 if (copy_type == TexImage) {
331 glCopyTextureCHROMIUM(textures_[0], textures_[1],
332 dest_format_type.internal_format,
333 dest_format_type.type, false, false, false);
334 } else {
335 glBindTexture(target, textures_[1]);
336 glTexImage2D(target, dest_level, dest_format_type.internal_format, width_,
337 height_, 0, dest_format_type.format, dest_format_type.type,
338 nullptr);
339
340 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0, 0, width_,
341 height_, false, false, false);
342 }
343 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
344
345 // Draw destination texture to a fbo with a texture attachment in RGBA
346 // format.
347 GLuint texture = CreateDrawingTexture(target, width_, height_);
348 GLuint framebuffer = CreateDrawingFBO(target, texture);
349 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
350 glCheckFramebufferStatus(GL_FRAMEBUFFER));
351 glViewport(0, 0, width_, height_);
352
353 glBindTexture(target, textures_[1]);
354 std::string fragment_shader_source =
355 GetFragmentShaderSource(dest_format_type.internal_format, is_es3);
356 // TODO(qiankun.miao@intel.com): Support drawing from level > 0 of a
357 // texture.
358 GLTestHelper::DrawTextureQuad(
359 is_es3 ? kSimpleVertexShaderES3 : kSimpleVertexShaderES2,
360 fragment_shader_source.c_str(), "a_position", "u_texture");
361 EXPECT_TRUE(GL_NO_ERROR == glGetError());
362
363 uint8_t tolerance = dest_format_type.internal_format == GL_RGBA4 ? 20 : 7;
364 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, width_, height_, tolerance,
365 expected_color, mask))
366 << " src_internal_format: "
367 << gles2::GLES2Util::GetStringEnum(src_format_type.internal_format)
368 << " source_level: " << source_level
369 << " dest_internal_format: "
370 << gles2::GLES2Util::GetStringEnum(dest_format_type.internal_format)
371 << " dest_level: " << dest_level;
372
373 glDeleteTextures(1, &texture);
374 glDeleteFramebuffers(1, &framebuffer);
375 glDeleteTextures(2, textures_);
376 }
377
242 GLManager gl_; 378 GLManager gl_;
243 GLuint textures_[2]; 379 GLuint textures_[2];
380 GLsizei width_;
381 GLsizei height_;
244 GLuint framebuffer_id_; 382 GLuint framebuffer_id_;
245 }; 383 };
246 384
247 class GLCopyTextureCHROMIUMES3Test : public GLCopyTextureCHROMIUMTest { 385 class GLCopyTextureCHROMIUMES3Test : public GLCopyTextureCHROMIUMTest {
248 protected: 386 protected:
249 void SetUp() override { 387 void SetUp() override {
250 GLManager::Options options; 388 GLManager::Options options;
251 options.context_type = gles2::CONTEXT_TYPE_OPENGLES3; 389 options.context_type = gles2::CONTEXT_TYPE_OPENGLES3;
252 options.size = gfx::Size(64, 64); 390 options.size = gfx::Size(64, 64);
253 gl_.Initialize(options); 391 gl_.Initialize(options);
392
393 width_ = 8;
394 height_ = 8;
254 } 395 }
255 396
256 // If a driver isn't capable of supporting ES3 context, creating 397 // If a driver isn't capable of supporting ES3 context, creating
257 // ContextGroup will fail. Just skip the test. 398 // ContextGroup will fail. Just skip the test.
258 bool ShouldSkipTest() const { 399 bool ShouldSkipTest() const {
259 return (!gl_.decoder() || !gl_.decoder()->GetContextGroup()); 400 return (!gl_.decoder() || !gl_.decoder()->GetContextGroup());
260 } 401 }
261 402
262 // RGB9_E5 isn't accepted by glCopyTexImage2D if underlying context is ES. 403 // RGB9_E5 isn't accepted by glCopyTexImage2D if underlying context is ES.
263 // TODO(qiankun.miao@intel.com): we should support RGB9_E5 in ES context. 404 // TODO(qiankun.miao@intel.com): we should support RGB9_E5 in ES context.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 479
339 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels, nullptr); 480 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels, nullptr);
340 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 481 EXPECT_TRUE(GL_NO_ERROR == glGetError());
341 } 482 }
342 483
343 TEST_P(GLCopyTextureCHROMIUMES3Test, FormatCombinations) { 484 TEST_P(GLCopyTextureCHROMIUMES3Test, FormatCombinations) {
344 if (ShouldSkipTest()) 485 if (ShouldSkipTest())
345 return; 486 return;
346 CopyType copy_type = GetParam(); 487 CopyType copy_type = GetParam();
347 488
348 struct FormatType {
349 GLenum internal_format;
350 GLenum format;
351 GLenum type;
352 };
353
354 FormatType src_format_types[] = { 489 FormatType src_format_types[] = {
355 {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE}, 490 {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE},
356 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE}, 491 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE},
357 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}, 492 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE},
358 {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}, 493 {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE},
359 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, 494 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE},
360 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, 495 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE},
361 {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, 496 {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE},
362 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, 497 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE},
363 }; 498 };
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 if (gles2::GLES2Util::IsFloatFormat(dest_format_type.internal_format) && 555 if (gles2::GLES2Util::IsFloatFormat(dest_format_type.internal_format) &&
421 ShouldSkipFloatFormat()) 556 ShouldSkipFloatFormat())
422 continue; 557 continue;
423 if ((dest_format_type.internal_format == GL_SRGB_EXT || 558 if ((dest_format_type.internal_format == GL_SRGB_EXT ||
424 dest_format_type.internal_format == GL_SRGB_ALPHA_EXT) && 559 dest_format_type.internal_format == GL_SRGB_ALPHA_EXT) &&
425 ShouldSkipSRGBEXT()) 560 ShouldSkipSRGBEXT())
426 continue; 561 continue;
427 if (dest_format_type.internal_format == GL_RGB5_A1 && ShouldSkipRGB5_A1()) 562 if (dest_format_type.internal_format == GL_RGB5_A1 && ShouldSkipRGB5_A1())
428 continue; 563 continue;
429 564
430 const GLsizei kWidth = 8, kHeight = 8; 565 RunCopyTexture(GL_TEXTURE_2D, copy_type, src_format_type, 0,
431 const int src_channel_count = gles2::GLES2Util::ElementsPerGroup( 566 dest_format_type, 0, true);
432 src_format_type.format, src_format_type.type);
433 uint8_t color[4] = {1, 63, 127, 255};
434 uint8_t pixels[8 * 8 * 4];
435 for (int i = 0; i < kWidth * kHeight * src_channel_count;
436 i += src_channel_count)
437 for (int j = 0; j < src_channel_count; ++j)
438 pixels[i + j] = color[j];
439 uint8_t expected_color[4];
440 uint8_t mask[4];
441 getExpectedColor(src_format_type.internal_format,
442 dest_format_type.internal_format, color, expected_color,
443 mask);
444
445 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D);
446 glBindTexture(GL_TEXTURE_2D, textures_[0]);
447 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
448 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
449 glTexImage2D(GL_TEXTURE_2D, 0, src_format_type.internal_format, kWidth,
450 kHeight, 0, src_format_type.format, src_format_type.type,
451 pixels);
452
453 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
454 if (copy_type == TexImage) {
455 glCopyTextureCHROMIUM(textures_[0], textures_[1],
456 dest_format_type.internal_format,
457 dest_format_type.type, false, false, false);
458 } else {
459 glBindTexture(GL_TEXTURE_2D, textures_[1]);
460 glTexImage2D(GL_TEXTURE_2D, 0, dest_format_type.internal_format, kWidth,
461 kHeight, 0, dest_format_type.format, dest_format_type.type,
462 nullptr);
463
464 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0, 0, kWidth,
465 kHeight, false, false, false);
466 }
467 EXPECT_TRUE(glGetError() == GL_NO_ERROR)
468 << " src_internal_format: "
469 << gles2::GLES2Util::GetStringEnum(src_format_type.internal_format)
470 << " dest_internal_format: "
471 << gles2::GLES2Util::GetStringEnum(dest_format_type.internal_format);
472
473 // Draw destination texture to a fbo with attachment in RGBA format.
474 glBindFramebuffer(GL_FRAMEBUFFER, 0);
475 GLuint framebuffer = 0;
476 glGenFramebuffers(1, &framebuffer);
477 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
478 GLuint texture = 0;
479 glGenTextures(1, &texture);
480 glBindTexture(GL_TEXTURE_2D, texture);
481 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
482 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
483 CreateBackingForTexture(GL_TEXTURE_2D, kWidth, kHeight);
484 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
485 GL_TEXTURE_2D, texture, 0);
486 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
487 glCheckFramebufferStatus(GL_FRAMEBUFFER));
488 glViewport(0, 0, kWidth, kHeight);
489
490 glBindTexture(GL_TEXTURE_2D, textures_[1]);
491 std::string fragment_shader_source =
492 GetFragmentShaderSource(dest_format_type.internal_format);
493 GLTestHelper::DrawTextureQuad(kSimpleVertexShaderES3,
494 fragment_shader_source.c_str(),
495 "a_position", "u_texture");
496
497 uint8_t tolerance = dest_format_type.internal_format == GL_RGBA4 ? 20 : 7;
498 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kWidth, kHeight, tolerance,
499 expected_color, mask))
500 << " src_internal_format: "
501 << gles2::GLES2Util::GetStringEnum(src_format_type.internal_format)
502 << " dest_internal_format: "
503 << gles2::GLES2Util::GetStringEnum(dest_format_type.internal_format);
504 EXPECT_TRUE(GL_NO_ERROR == glGetError());
505
506 glDeleteTextures(1, &texture);
507 glDeleteFramebuffers(1, &framebuffer);
508 glDeleteTextures(2, textures_);
509 glDeleteFramebuffers(1, &framebuffer_id_);
510 } 567 }
511 } 568 }
512 } 569 }
513 570
514 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { 571 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) {
515 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { 572 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) {
516 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; 573 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test...";
517 return; 574 return;
518 } 575 }
519 CopyType copy_type = GetParam(); 576 CopyType copy_type = GetParam();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 glCopyTextureCHROMIUM( 710 glCopyTextureCHROMIUM(
654 textures_[0], textures_[1], unsupported_format_types[dest_index].format, 711 textures_[0], textures_[1], unsupported_format_types[dest_index].format,
655 unsupported_format_types[dest_index].type, false, false, false); 712 unsupported_format_types[dest_index].type, false, false, false);
656 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()) 713 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError())
657 << "dest_index:" << dest_index; 714 << "dest_index:" << dest_index;
658 } 715 }
659 glDeleteTextures(2, textures_); 716 glDeleteTextures(2, textures_);
660 glDeleteFramebuffers(1, &framebuffer_id_); 717 glDeleteFramebuffers(1, &framebuffer_id_);
661 } 718 }
662 719
720 TEST_P(GLCopyTextureCHROMIUMTest, CopyTextureLevel) {
721 CopyType copy_type = GetParam();
722
723 // Copy from RGB source texture to dest texture.
724 FormatType src_format_type = {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE};
725 FormatType dest_format_types[] = {
726 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE},
727 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE},
728 };
729 // Source level must be 0 in ES2 context.
730 GLint source_level = 0;
731
732 // TODO(qiankun.miao@intel.com): Support level > 0.
733 for (GLint dest_level = 0; dest_level < 1; dest_level++) {
734 for (auto dest_format_type : dest_format_types) {
735 RunCopyTexture(GL_TEXTURE_2D, copy_type, src_format_type, source_level,
736 dest_format_type, dest_level, false);
737 }
738 }
739 }
740
741 TEST_P(GLCopyTextureCHROMIUMES3Test, CopyTextureLevel) {
742 if (ShouldSkipTest())
743 return;
744 CopyType copy_type = GetParam();
745
746 // Copy from RGBA source texture to dest texture.
747 FormatType src_format_type = {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE};
748 FormatType dest_format_types[] = {
749 {GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE},
750 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE},
751 {GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE},
752 };
753
754 // TODO(qiankun.miao@intel.com): Support level > 0.
755 for (GLint source_level = 0; source_level < 1; source_level++) {
756 for (GLint dest_level = 0; dest_level < 1; dest_level++) {
757 for (auto dest_format_type : dest_format_types) {
758 RunCopyTexture(GL_TEXTURE_2D, copy_type, src_format_type, source_level,
759 dest_format_type, dest_level, true);
760 }
761 }
762 }
763 }
764
663 // Test to ensure that the destination texture is redefined if the properties 765 // Test to ensure that the destination texture is redefined if the properties
664 // are different. 766 // are different.
665 TEST_F(GLCopyTextureCHROMIUMTest, RedefineDestinationTexture) { 767 TEST_F(GLCopyTextureCHROMIUMTest, RedefineDestinationTexture) {
666 uint8_t pixels[4 * 4] = {255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u, 768 uint8_t pixels[4 * 4] = {255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u,
667 255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u}; 769 255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u};
668 770
669 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D); 771 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D);
670 glBindTexture(GL_TEXTURE_2D, textures_[0]); 772 glBindTexture(GL_TEXTURE_2D, textures_[0]);
671 glTexImage2D( 773 glTexImage2D(
672 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 774 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 } 1418 }
1317 } 1419 }
1318 1420
1319 glDeleteTextures(2, textures_); 1421 glDeleteTextures(2, textures_);
1320 glDeleteFramebuffers(1, &framebuffer_id_); 1422 glDeleteFramebuffers(1, &framebuffer_id_);
1321 } 1423 }
1322 } 1424 }
1323 } 1425 }
1324 1426
1325 } // namespace gpu 1427 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698