OLD | NEW |
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> |
11 #include <GLES2/gl2extchromium.h> | 11 #include <GLES2/gl2extchromium.h> |
12 #include <GLES3/gl3.h> | |
13 #include <stddef.h> | 12 #include <stddef.h> |
14 #include <stdint.h> | 13 #include <stdint.h> |
15 | 14 |
16 #include "gpu/command_buffer/tests/gl_manager.h" | 15 #include "gpu/command_buffer/tests/gl_manager.h" |
17 #include "gpu/command_buffer/tests/gl_test_utils.h" | 16 #include "gpu/command_buffer/tests/gl_test_utils.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "ui/gl/gl_version_info.h" | |
21 | 19 |
22 namespace gpu { | 20 namespace gpu { |
23 | 21 |
24 namespace { | 22 namespace { |
25 | |
26 enum CopyType { TexImage, TexSubImage }; | 23 enum CopyType { TexImage, TexSubImage }; |
27 const CopyType kCopyTypes[] = { | 24 const CopyType kCopyTypes[] = { |
28 TexImage, | 25 TexImage, |
29 TexSubImage, | 26 TexSubImage, |
30 }; | 27 }; |
31 | |
32 static const char* kSimpleVertexShaderES3 = | |
33 "#version 300 es\n" | |
34 "in vec2 a_position;\n" | |
35 "out vec2 v_texCoord;\n" | |
36 "void main() {\n" | |
37 " 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" | |
39 "}\n"; | |
40 | |
41 std::string GetFragmentShaderSource(GLenum format) { | |
42 std::string source; | |
43 source += std::string( | |
44 "#version 300 es\n" | |
45 "precision mediump float;\n"); | |
46 if (gles2::GLES2Util::IsSignedIntegerFormat(format)) { | |
47 source += std::string("#define SamplerType isampler2D\n"); | |
48 source += std::string("#define TextureType ivec4\n"); | |
49 source += std::string("#define ScaleValue 255.0\n"); | |
50 } else if (gles2::GLES2Util::IsUnsignedIntegerFormat(format)) { | |
51 source += std::string("#define SamplerType usampler2D\n"); | |
52 source += std::string("#define TextureType uvec4\n"); | |
53 source += std::string("#define ScaleValue 255.0\n"); | |
54 } else { | |
55 source += std::string("#define SamplerType sampler2D\n"); | |
56 source += std::string("#define TextureType vec4\n"); | |
57 source += std::string("#define ScaleValue 1.0\n"); | |
58 } | |
59 | |
60 source += std::string( | |
61 "uniform mediump SamplerType u_texture;\n" | |
62 "in vec2 v_texCoord;\n" | |
63 "out vec4 fragData;\n" | |
64 "void main() {\n" | |
65 " TextureType color = texture(u_texture, v_texCoord);\n" | |
66 " fragData = vec4(color) / ScaleValue;\n" | |
67 "}\n"); | |
68 return source; | |
69 } | 28 } |
70 | 29 |
71 void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t* color) { | |
72 color[0] = r; | |
73 color[1] = g; | |
74 color[2] = b; | |
75 color[3] = a; | |
76 } | |
77 | |
78 void getExpectedColor(GLenum src_internal_format, | |
79 GLenum dest_internal_format, | |
80 uint8_t* color, | |
81 uint8_t* expected_color, | |
82 uint8_t* mask) { | |
83 uint8_t adjusted_color[4]; | |
84 switch (src_internal_format) { | |
85 case GL_ALPHA: | |
86 setColor(0, 0, 0, color[0], adjusted_color); | |
87 break; | |
88 case GL_R8: | |
89 setColor(color[0], 0, 0, 255, adjusted_color); | |
90 break; | |
91 case GL_LUMINANCE: | |
92 setColor(color[0], color[0], color[0], 255, adjusted_color); | |
93 break; | |
94 case GL_LUMINANCE_ALPHA: | |
95 setColor(color[0], color[0], color[0], color[1], adjusted_color); | |
96 break; | |
97 case GL_RGB: | |
98 case GL_RGB8: | |
99 case GL_RGB_YCBCR_420V_CHROMIUM: | |
100 case GL_RGB_YCBCR_422_CHROMIUM: | |
101 setColor(color[0], color[1], color[2], 255, adjusted_color); | |
102 break; | |
103 case GL_RGBA: | |
104 case GL_RGBA8: | |
105 setColor(color[0], color[1], color[2], color[3], adjusted_color); | |
106 break; | |
107 case GL_BGRA_EXT: | |
108 case GL_BGRA8_EXT: | |
109 setColor(color[2], color[1], color[0], color[3], adjusted_color); | |
110 break; | |
111 default: | |
112 NOTREACHED(); | |
113 break; | |
114 } | |
115 | |
116 switch (dest_internal_format) { | |
117 case GL_ALPHA: | |
118 setColor(0, 0, 0, adjusted_color[3], expected_color); | |
119 setColor(0, 0, 0, 1, mask); | |
120 break; | |
121 case GL_R8: | |
122 case GL_R16F: | |
123 case GL_R32F: | |
124 case GL_R8UI: | |
125 setColor(adjusted_color[0], 0, 0, 0, expected_color); | |
126 setColor(1, 0, 0, 0, mask); | |
127 break; | |
128 case GL_LUMINANCE: | |
129 setColor(adjusted_color[0], 0, 0, 0, expected_color); | |
130 setColor(1, 0, 0, 0, mask); | |
131 break; | |
132 case GL_LUMINANCE_ALPHA: | |
133 setColor(adjusted_color[0], 0, 0, adjusted_color[3], expected_color); | |
134 setColor(1, 0, 0, 1, mask); | |
135 break; | |
136 case GL_RG8: | |
137 case GL_RG16F: | |
138 case GL_RG32F: | |
139 case GL_RG8UI: | |
140 setColor(adjusted_color[0], adjusted_color[1], 0, 0, expected_color); | |
141 setColor(1, 1, 0, 0, mask); | |
142 break; | |
143 case GL_RGB: | |
144 case GL_RGB8: | |
145 case GL_SRGB_EXT: | |
146 case GL_SRGB8: | |
147 case GL_RGB565: | |
148 case GL_R11F_G11F_B10F: | |
149 case GL_RGB9_E5: | |
150 case GL_RGB16F: | |
151 case GL_RGB32F: | |
152 case GL_RGB8UI: | |
153 setColor(adjusted_color[0], adjusted_color[1], adjusted_color[2], 0, | |
154 expected_color); | |
155 setColor(1, 1, 1, 0, mask); | |
156 break; | |
157 case GL_RGBA: | |
158 case GL_RGBA8: | |
159 case GL_BGRA_EXT: | |
160 case GL_BGRA8_EXT: | |
161 case GL_SRGB_ALPHA_EXT: | |
162 case GL_SRGB8_ALPHA8: | |
163 case GL_RGBA4: | |
164 case GL_RGBA16F: | |
165 case GL_RGBA32F: | |
166 case GL_RGBA8UI: | |
167 setColor(adjusted_color[0], adjusted_color[1], adjusted_color[2], | |
168 adjusted_color[3], expected_color); | |
169 setColor(1, 1, 1, 1, mask); | |
170 break; | |
171 case GL_RGB5_A1: | |
172 setColor(adjusted_color[0], adjusted_color[1], adjusted_color[2], | |
173 (adjusted_color[3] >> 7) ? 0xFF : 0x0, expected_color); | |
174 // TODO(qiankun.miao@intel.com): On some Windows platforms, the alpha | |
175 // channel of expected color is the source alpha value other than 255. | |
176 // This should be wrong. Skip the alpha channel check and revisit this in | |
177 // future. | |
178 setColor(1, 1, 1, 0, mask); | |
179 break; | |
180 default: | |
181 NOTREACHED(); | |
182 break; | |
183 } | |
184 } | |
185 | |
186 } // namespace | |
187 | |
188 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. | 30 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. |
189 class GLCopyTextureCHROMIUMTest | 31 class GLCopyTextureCHROMIUMTest |
190 : public testing::Test, | 32 : public testing::Test, |
191 public ::testing::WithParamInterface<CopyType> { | 33 public ::testing::WithParamInterface<CopyType> { |
192 protected: | 34 protected: |
193 | 35 |
194 void CreateAndBindDestinationTextureAndFBO(GLenum target) { | 36 void CreateAndBindDestinationTextureAndFBO(GLenum target) { |
195 glGenTextures(2, textures_); | 37 glGenTextures(2, textures_); |
196 glBindTexture(target, textures_[1]); | 38 glBindTexture(target, textures_[1]); |
197 | 39 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 NOTREACHED(); | 85 NOTREACHED(); |
244 return GL_NONE; | 86 return GL_NONE; |
245 } | 87 } |
246 } | 88 } |
247 | 89 |
248 GLManager gl_; | 90 GLManager gl_; |
249 GLuint textures_[2]; | 91 GLuint textures_[2]; |
250 GLuint framebuffer_id_; | 92 GLuint framebuffer_id_; |
251 }; | 93 }; |
252 | 94 |
253 class GLCopyTextureCHROMIUMES3Test : public GLCopyTextureCHROMIUMTest { | |
254 protected: | |
255 void SetUp() override { | |
256 GLManager::Options options; | |
257 options.context_type = gles2::CONTEXT_TYPE_OPENGLES3; | |
258 options.size = gfx::Size(64, 64); | |
259 gl_.Initialize(options); | |
260 } | |
261 | |
262 void TearDown() override { gl_.Destroy(); } | |
263 | |
264 // If a driver isn't capable of supporting ES3 context, creating | |
265 // ContextGroup will fail. Just skip the test. | |
266 bool ShouldSkipTest() const { | |
267 return (!gl_.decoder() || !gl_.decoder()->GetContextGroup()); | |
268 } | |
269 | |
270 // RGB9_E5 isn't accepted by glCopyTexImage2D if underlying context is ES. | |
271 // TODO(qiankun.miao@intel.com): we should support RGB9_E5 in ES context. | |
272 // Maybe, we can add a readback path for RGB9_E5 format in ES context. | |
273 bool ShouldSkipRGB9_E5() const { | |
274 DCHECK(!ShouldSkipTest()); | |
275 const gl::GLVersionInfo& gl_version_info = | |
276 gl_.decoder()->GetFeatureInfo()->gl_version_info(); | |
277 return gl_version_info.is_es; | |
278 } | |
279 | |
280 // If EXT_color_buffer_float isn't available, float format isn't supported. | |
281 bool ShouldSkipFloatFormat() const { | |
282 DCHECK(!ShouldSkipTest()); | |
283 return !gl_.decoder()->GetFeatureInfo()->ext_color_buffer_float_available(); | |
284 } | |
285 | |
286 bool ShouldSkipBGRA() const { | |
287 DCHECK(!ShouldSkipTest()); | |
288 return !gl_.decoder() | |
289 ->GetFeatureInfo() | |
290 ->feature_flags() | |
291 .ext_texture_format_bgra8888; | |
292 } | |
293 | |
294 bool ShouldSkipSRGBEXT() const { | |
295 DCHECK(!ShouldSkipTest()); | |
296 return !gl_.decoder()->GetFeatureInfo()->feature_flags().ext_srgb; | |
297 } | |
298 }; | |
299 | |
300 INSTANTIATE_TEST_CASE_P(CopyType, | 95 INSTANTIATE_TEST_CASE_P(CopyType, |
301 GLCopyTextureCHROMIUMTest, | 96 GLCopyTextureCHROMIUMTest, |
302 ::testing::ValuesIn(kCopyTypes)); | 97 ::testing::ValuesIn(kCopyTypes)); |
303 | 98 |
304 INSTANTIATE_TEST_CASE_P(CopyType, | |
305 GLCopyTextureCHROMIUMES3Test, | |
306 ::testing::ValuesIn(kCopyTypes)); | |
307 | |
308 // Test to ensure that the basic functionality of the extension works. | 99 // Test to ensure that the basic functionality of the extension works. |
309 TEST_P(GLCopyTextureCHROMIUMTest, Basic) { | 100 TEST_P(GLCopyTextureCHROMIUMTest, Basic) { |
310 CopyType copy_type = GetParam(); | 101 CopyType copy_type = GetParam(); |
311 uint8_t pixels[1 * 4] = {255u, 0u, 0u, 255u}; | 102 uint8_t pixels[1 * 4] = {255u, 0u, 0u, 255u}; |
312 | 103 |
313 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 104 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
314 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 105 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
315 pixels); | 106 pixels); |
316 | 107 |
317 if (copy_type == TexImage) { | 108 if (copy_type == TexImage) { |
(...skipping 16 matching lines...) Expand all Loading... |
334 EXPECT_EQ(framebuffer_id_, fb_id); | 125 EXPECT_EQ(framebuffer_id_, fb_id); |
335 | 126 |
336 // Check that FB is complete. | 127 // Check that FB is complete. |
337 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | 128 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
338 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | 129 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
339 | 130 |
340 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); | 131 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); |
341 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 132 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
342 } | 133 } |
343 | 134 |
344 TEST_P(GLCopyTextureCHROMIUMES3Test, FormatCombinations) { | |
345 if (ShouldSkipTest()) | |
346 return; | |
347 CopyType copy_type = GetParam(); | |
348 | |
349 struct FormatType { | |
350 GLenum internal_format; | |
351 GLenum format; | |
352 GLenum type; | |
353 }; | |
354 | |
355 FormatType src_format_types[] = { | |
356 {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE}, | |
357 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE}, | |
358 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}, | |
359 {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}, | |
360 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, | |
361 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, | |
362 {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, | |
363 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, | |
364 }; | |
365 | |
366 FormatType dest_format_types[] = { | |
367 // TODO(qiankun.miao@intel.com): ALPHA and LUMINANCE formats have bug on | |
368 // GL core profile. See crbug.com/577144. Enable these formats after | |
369 // using workaround in gles2_cmd_copy_tex_image.cc. | |
370 // {GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE}, | |
371 // {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE}, | |
372 // {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE}, | |
373 | |
374 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}, | |
375 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, | |
376 {GL_SRGB_EXT, GL_SRGB_EXT, GL_UNSIGNED_BYTE}, | |
377 {GL_SRGB_ALPHA_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE}, | |
378 {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, | |
379 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, | |
380 {GL_R8, GL_RED, GL_UNSIGNED_BYTE}, | |
381 {GL_R16F, GL_RED, GL_HALF_FLOAT}, | |
382 {GL_R16F, GL_RED, GL_FLOAT}, | |
383 {GL_R32F, GL_RED, GL_FLOAT}, | |
384 {GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE}, | |
385 {GL_RG8, GL_RG, GL_UNSIGNED_BYTE}, | |
386 {GL_RG16F, GL_RG, GL_HALF_FLOAT}, | |
387 {GL_RG16F, GL_RG, GL_FLOAT}, | |
388 {GL_RG32F, GL_RG, GL_FLOAT}, | |
389 {GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE}, | |
390 {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}, | |
391 {GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE}, | |
392 {GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE}, | |
393 {GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT}, | |
394 {GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT}, | |
395 {GL_RGB9_E5, GL_RGB, GL_FLOAT}, | |
396 {GL_RGB16F, GL_RGB, GL_HALF_FLOAT}, | |
397 {GL_RGB16F, GL_RGB, GL_FLOAT}, | |
398 {GL_RGB32F, GL_RGB, GL_FLOAT}, | |
399 {GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE}, | |
400 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, | |
401 {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE}, | |
402 {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE}, | |
403 {GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE}, | |
404 {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT}, | |
405 {GL_RGBA16F, GL_RGBA, GL_FLOAT}, | |
406 {GL_RGBA32F, GL_RGBA, GL_FLOAT}, | |
407 {GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE}, | |
408 }; | |
409 | |
410 for (auto src_format_type : src_format_types) { | |
411 for (auto dest_format_type : dest_format_types) { | |
412 if (dest_format_type.internal_format == GL_RGB9_E5 && ShouldSkipRGB9_E5()) | |
413 continue; | |
414 if ((src_format_type.internal_format == GL_BGRA_EXT || | |
415 src_format_type.internal_format == GL_BGRA8_EXT || | |
416 dest_format_type.internal_format == GL_BGRA_EXT || | |
417 dest_format_type.internal_format == GL_BGRA8_EXT) && | |
418 ShouldSkipBGRA()) { | |
419 continue; | |
420 } | |
421 if (gles2::GLES2Util::IsFloatFormat(dest_format_type.internal_format) && | |
422 ShouldSkipFloatFormat()) | |
423 continue; | |
424 if ((dest_format_type.internal_format == GL_SRGB_EXT || | |
425 dest_format_type.internal_format == GL_SRGB_ALPHA_EXT) && | |
426 ShouldSkipSRGBEXT()) | |
427 continue; | |
428 | |
429 const GLsizei kWidth = 8, kHeight = 8; | |
430 const int src_channel_count = gles2::GLES2Util::ElementsPerGroup( | |
431 src_format_type.format, src_format_type.type); | |
432 uint8_t color[4] = {1, 63, 127, 255}; | |
433 uint8_t pixels[8 * 8 * 4]; | |
434 for (int i = 0; i < kWidth * kHeight * src_channel_count; | |
435 i += src_channel_count) | |
436 for (int j = 0; j < src_channel_count; ++j) | |
437 pixels[i + j] = color[j]; | |
438 uint8_t expected_color[4]; | |
439 uint8_t mask[4]; | |
440 getExpectedColor(src_format_type.internal_format, | |
441 dest_format_type.internal_format, color, expected_color, | |
442 mask); | |
443 | |
444 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D); | |
445 glBindTexture(GL_TEXTURE_2D, textures_[0]); | |
446 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
447 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
448 glTexImage2D(GL_TEXTURE_2D, 0, src_format_type.internal_format, kWidth, | |
449 kHeight, 0, src_format_type.format, src_format_type.type, | |
450 pixels); | |
451 | |
452 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
453 if (copy_type == TexImage) { | |
454 glCopyTextureCHROMIUM(textures_[0], textures_[1], | |
455 dest_format_type.internal_format, | |
456 dest_format_type.type, false, false, false); | |
457 } else { | |
458 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
459 glTexImage2D(GL_TEXTURE_2D, 0, dest_format_type.internal_format, kWidth, | |
460 kHeight, 0, dest_format_type.format, dest_format_type.type, | |
461 nullptr); | |
462 | |
463 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0, 0, kWidth, | |
464 kHeight, false, false, false); | |
465 } | |
466 EXPECT_TRUE(glGetError() == GL_NO_ERROR) | |
467 << " src_internal_format: " | |
468 << gles2::GLES2Util::GetStringEnum(src_format_type.internal_format) | |
469 << " dest_internal_format: " | |
470 << gles2::GLES2Util::GetStringEnum(dest_format_type.internal_format); | |
471 | |
472 // Draw destination texture to a fbo with attachment in RGBA format. | |
473 glBindFramebuffer(GL_FRAMEBUFFER, 0); | |
474 GLuint framebuffer = 0; | |
475 glGenFramebuffers(1, &framebuffer); | |
476 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); | |
477 GLuint texture = 0; | |
478 glGenTextures(1, &texture); | |
479 glBindTexture(GL_TEXTURE_2D, texture); | |
480 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
481 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
482 CreateBackingForTexture(GL_TEXTURE_2D, kWidth, kHeight); | |
483 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | |
484 GL_TEXTURE_2D, texture, 0); | |
485 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | |
486 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | |
487 glViewport(0, 0, kWidth, kHeight); | |
488 | |
489 std::string fragment_shader_source = | |
490 GetFragmentShaderSource(dest_format_type.internal_format); | |
491 GLuint program = GLTestHelper::LoadProgram( | |
492 kSimpleVertexShaderES3, fragment_shader_source.c_str()); | |
493 EXPECT_NE(program, 0u); | |
494 GLint position_loc = glGetAttribLocation(program, "a_position"); | |
495 GLint texture_loc = glGetUniformLocation(program, "u_texture"); | |
496 ASSERT_NE(position_loc, -1); | |
497 ASSERT_NE(texture_loc, -1); | |
498 glUseProgram(program); | |
499 | |
500 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc); | |
501 ASSERT_NE(vbo, 0u); | |
502 | |
503 glActiveTexture(GL_TEXTURE0); | |
504 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
505 | |
506 glDrawArrays(GL_TRIANGLES, 0, 6); | |
507 | |
508 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | |
509 | |
510 GLsizei size = kWidth * kHeight * 4; | |
511 std::unique_ptr<uint8_t[]> result(new uint8_t[size]); | |
512 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, | |
513 result.get()); | |
514 uint8_t tolerance = dest_format_type.internal_format == GL_RGBA4 ? 20 : 7; | |
515 for (GLint yy = 0; yy < kHeight; ++yy) { | |
516 for (GLint xx = 0; xx < kWidth; ++xx) { | |
517 int offset = yy * kWidth * 4 + xx * 4; | |
518 for (int jj = 0; jj < 4; ++jj) { | |
519 uint8_t actual = result[offset + jj]; | |
520 uint8_t expected = expected_color[jj]; | |
521 int diff = actual - expected; | |
522 diff = diff < 0 ? -diff : diff; | |
523 if (mask[jj] && diff > tolerance) { | |
524 EXPECT_EQ(expected, actual) | |
525 << " at " << xx << ", " << yy << " channel " << jj | |
526 << " src_internal_format: " | |
527 << gles2::GLES2Util::GetStringEnum( | |
528 src_format_type.internal_format) | |
529 << " dest_internal_format: " | |
530 << gles2::GLES2Util::GetStringEnum( | |
531 dest_format_type.internal_format); | |
532 } | |
533 } | |
534 } | |
535 } | |
536 | |
537 glDeleteTextures(1, &texture); | |
538 glDeleteFramebuffers(1, &framebuffer); | |
539 glDeleteTextures(2, textures_); | |
540 glDeleteFramebuffers(1, &framebuffer_id_); | |
541 } | |
542 } | |
543 } | |
544 | |
545 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { | 135 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { |
546 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { | 136 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { |
547 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; | 137 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; |
548 return; | 138 return; |
549 } | 139 } |
550 CopyType copy_type = GetParam(); | 140 CopyType copy_type = GetParam(); |
551 GLenum src_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; | 141 GLenum src_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; |
552 GLenum dest_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; | 142 GLenum dest_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; |
553 | 143 |
554 uint8_t pixels[1 * 4] = {255u, 0u, 255u, 255u}; | 144 uint8_t pixels[1 * 4] = {255u, 0u, 255u, 255u}; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 } | 223 } |
634 | 224 |
635 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) { | 225 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) { |
636 CopyType copy_type = GetParam(); | 226 CopyType copy_type = GetParam(); |
637 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 227 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
638 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 228 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
639 nullptr); | 229 nullptr); |
640 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 230 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
641 | 231 |
642 // Check unsupported format reports error. | 232 // Check unsupported format reports error. |
643 GLint unsupported_dest_formats[] = {GL_RED, GL_RG}; | 233 GLint unsupported_dest_formats[] = {GL_ALPHA, GL_LUMINANCE, |
| 234 GL_LUMINANCE_ALPHA}; |
644 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats); | 235 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats); |
645 dest_index++) { | 236 dest_index++) { |
646 if (copy_type == TexImage) { | 237 if (copy_type == TexImage) { |
647 glCopyTextureCHROMIUM(textures_[0], textures_[1], | 238 glCopyTextureCHROMIUM(textures_[0], textures_[1], |
648 unsupported_dest_formats[dest_index], | 239 unsupported_dest_formats[dest_index], |
649 GL_UNSIGNED_BYTE, false, false, false); | 240 GL_UNSIGNED_BYTE, false, false, false); |
650 } else { | 241 } else { |
651 glBindTexture(GL_TEXTURE_2D, textures_[1]); | 242 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
652 glTexImage2D(GL_TEXTURE_2D, 0, unsupported_dest_formats[dest_index], 1, 1, | 243 glTexImage2D(GL_TEXTURE_2D, 0, unsupported_dest_formats[dest_index], 1, 1, |
653 0, unsupported_dest_formats[dest_index], GL_UNSIGNED_BYTE, | 244 0, unsupported_dest_formats[dest_index], GL_UNSIGNED_BYTE, |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1303 expected_color = y < copy_region_y + 1 ? blue : white; | 894 expected_color = y < copy_region_y + 1 ? blue : white; |
1304 } | 895 } |
1305 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color); | 896 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color); |
1306 } | 897 } |
1307 } | 898 } |
1308 } | 899 } |
1309 } | 900 } |
1310 } | 901 } |
1311 | 902 |
1312 } // namespace gpu | 903 } // namespace gpu |
OLD | NEW |