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

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

Issue 2479513002: Reland of Extend CopyTextureCHROMIUM to more ES 3.0 texture formats. (Closed)
Patch Set: full path Created 4 years, 1 month 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) 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>
12 #include <stddef.h> 13 #include <stddef.h>
13 #include <stdint.h> 14 #include <stdint.h>
14 15
15 #include "gpu/command_buffer/tests/gl_manager.h" 16 #include "gpu/command_buffer/tests/gl_manager.h"
16 #include "gpu/command_buffer/tests/gl_test_utils.h" 17 #include "gpu/command_buffer/tests/gl_test_utils.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 namespace gpu { 21 namespace gpu {
21 22
22 namespace { 23 namespace {
24
23 enum CopyType { TexImage, TexSubImage }; 25 enum CopyType { TexImage, TexSubImage };
24 const CopyType kCopyTypes[] = { 26 const CopyType kCopyTypes[] = {
25 TexImage, 27 TexImage,
26 TexSubImage, 28 TexSubImage,
27 }; 29 };
30
31 static const char* kSimpleVertexShaderES3 =
32 "#version 300 es\n"
33 "in vec2 a_position;\n"
34 "out vec2 v_texCoord;\n"
35 "void main() {\n"
36 " gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);\n"
37 " v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5;\n"
38 "}\n";
39
40 std::string GetFragmentShaderSource(GLenum format) {
41 std::string source;
42 source += std::string(
43 "#version 300 es\n"
44 "precision mediump float;\n");
45 if (gles2::GLES2Util::IsSignedIntegerFormat(format)) {
46 source += std::string("#define SamplerType isampler2D\n");
47 source += std::string("#define TextureType ivec4\n");
48 source += std::string("#define ScaleValue 255.0\n");
49 } else if (gles2::GLES2Util::IsUnsignedIntegerFormat(format)) {
50 source += std::string("#define SamplerType usampler2D\n");
51 source += std::string("#define TextureType uvec4\n");
52 source += std::string("#define ScaleValue 255.0\n");
53 } else {
54 source += std::string("#define SamplerType sampler2D\n");
55 source += std::string("#define TextureType vec4\n");
56 source += std::string("#define ScaleValue 1.0\n");
57 }
58
59 source += std::string(
60 "uniform mediump SamplerType u_texture;\n"
61 "in vec2 v_texCoord;\n"
62 "out vec4 fragData;\n"
63 "void main() {\n"
64 " TextureType color = texture(u_texture, v_texCoord);\n"
65 " fragData = vec4(color) / ScaleValue;\n"
66 "}\n");
67 return source;
28 } 68 }
29 69
70 } // namespace
71
30 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. 72 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension.
31 class GLCopyTextureCHROMIUMTest 73 class GLCopyTextureCHROMIUMTest
32 : public testing::Test, 74 : public testing::Test,
33 public ::testing::WithParamInterface<CopyType> { 75 public ::testing::WithParamInterface<CopyType> {
34 protected: 76 protected:
35 77
36 void CreateAndBindDestinationTextureAndFBO(GLenum target) { 78 void CreateAndBindDestinationTextureAndFBO(GLenum target) {
37 glGenTextures(2, textures_); 79 glGenTextures(2, textures_);
38 glBindTexture(target, textures_[1]); 80 glBindTexture(target, textures_[1]);
39 81
40 // Some drivers (NVidia/SGX) require texture settings to be a certain way or 82 // Some drivers (NVidia/SGX) require texture settings to be a certain way or
41 // they won't report FRAMEBUFFER_COMPLETE. 83 // they won't report FRAMEBUFFER_COMPLETE.
42 glTexParameterf(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 84 glTexParameterf(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
43 glTexParameterf(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 85 glTexParameterf(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
44 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 86 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
45 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 87 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
46 88
47 glGenFramebuffers(1, &framebuffer_id_); 89 glGenFramebuffers(1, &framebuffer_id_);
48 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_); 90 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_);
49 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, 91 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target,
50 textures_[1], 0); 92 textures_[1], 0);
51 } 93 }
52 94
53 void SetUp() override { 95 void SetUp() override {
54 gl_.Initialize(GLManager::Options()); 96 GLManager::Options options;
97 options.context_type = gles2::CONTEXT_TYPE_OPENGLES3;
98 options.size = gfx::Size(64, 64);
99 gl_.Initialize(options);
55 100
56 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D); 101 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D);
57 } 102 }
58 103
59 void TearDown() override { 104 void TearDown() override {
60 glDeleteTextures(2, textures_); 105 glDeleteTextures(2, textures_);
61 glDeleteFramebuffers(1, &framebuffer_id_); 106 glDeleteFramebuffers(1, &framebuffer_id_);
62 gl_.Destroy(); 107 gl_.Destroy();
63 } 108 }
64 109
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 EXPECT_EQ(framebuffer_id_, fb_id); 170 EXPECT_EQ(framebuffer_id_, fb_id);
126 171
127 // Check that FB is complete. 172 // Check that FB is complete.
128 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), 173 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
129 glCheckFramebufferStatus(GL_FRAMEBUFFER)); 174 glCheckFramebufferStatus(GL_FRAMEBUFFER));
130 175
131 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); 176 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels);
132 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 177 EXPECT_TRUE(GL_NO_ERROR == glGetError());
133 } 178 }
134 179
180 // Copy with glCopyTexImage2D
181 TEST_P(GLCopyTextureCHROMIUMTest, RGBA8ToRGB) {
182 CopyType copy_type = GetParam();
183 GLenum source_internal_format = GL_RGBA8;
184 GLenum source_format = GL_RGBA;
185 GLenum source_type = GL_UNSIGNED_BYTE;
186 GLenum dest_internal_format = GL_RGB;
187 GLenum dest_format = GL_RGB;
188 GLenum dest_type = GL_UNSIGNED_BYTE;
189
190 const GLsizei kWidth = 8, kHeight = 8;
191 uint8_t color[4] = {0, 1, 2, 3};
192 uint8_t pixels[8 * 8 * 4];
193 for (int i = 0; i < kWidth * kHeight * 4; i += 4) {
194 pixels[i + 0] = color[0];
195 pixels[i + 1] = color[1];
196 pixels[i + 2] = color[2];
197 pixels[i + 3] = color[3];
198 }
199
200 glBindTexture(GL_TEXTURE_2D, textures_[0]);
201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
203 glTexImage2D(GL_TEXTURE_2D, 0, source_internal_format, kWidth, kHeight, 0,
204 source_format, source_type, pixels);
205
206 if (copy_type == TexImage) {
207 glCopyTextureCHROMIUM(textures_[0], textures_[1], dest_internal_format,
208 dest_type, false, false, false);
209 } else {
210 glBindTexture(GL_TEXTURE_2D, textures_[1]);
211 glTexImage2D(GL_TEXTURE_2D, 0, dest_internal_format, kWidth, kHeight, 0,
212 dest_format, dest_type, nullptr);
213
214 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0, 0, kWidth,
215 kHeight, false, false, false);
216 }
217 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
218
219 // Draw destination texture to a fbo with attachment in RGBA format.
220 glBindFramebuffer(GL_FRAMEBUFFER, 0);
221 GLuint framebuffer = 0;
222 glGenFramebuffers(1, &framebuffer);
223 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
224 GLuint texture = 0;
225 glGenTextures(1, &texture);
226 glBindTexture(GL_TEXTURE_2D, texture);
227 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
228 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
229 CreateBackingForTexture(GL_TEXTURE_2D, kWidth, kHeight);
230 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
231 texture, 0);
232 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
233 glCheckFramebufferStatus(GL_FRAMEBUFFER));
234 glViewport(0, 0, kWidth, kHeight);
235
236 std::string fragment_shader_source =
237 GetFragmentShaderSource(dest_internal_format);
238 GLuint program = GLTestHelper::LoadProgram(kSimpleVertexShaderES3,
239 fragment_shader_source.c_str());
240 EXPECT_NE(program, 0u);
241 GLint position_loc = glGetAttribLocation(program, "a_position");
242 GLint texture_loc = glGetUniformLocation(program, "u_texture");
243 ASSERT_NE(position_loc, -1);
244 ASSERT_NE(texture_loc, -1);
245 glUseProgram(program);
246
247 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc);
248 ASSERT_NE(vbo, 0u);
249
250 glActiveTexture(GL_TEXTURE0);
251 glBindTexture(GL_TEXTURE_2D, textures_[1]);
252
253 glDrawArrays(GL_TRIANGLES, 0, 6);
254
255 GLTestHelper::CheckPixels(0, 0, kWidth, kHeight, 0, color, 3);
256 EXPECT_TRUE(GL_NO_ERROR == glGetError());
257 }
258
135 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { 259 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) {
136 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { 260 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) {
137 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; 261 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test...";
138 return; 262 return;
139 } 263 }
140 CopyType copy_type = GetParam(); 264 CopyType copy_type = GetParam();
141 GLenum src_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; 265 GLenum src_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}; 266 GLenum dest_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT};
143 267
144 uint8_t pixels[1 * 4] = {255u, 0u, 255u, 255u}; 268 uint8_t pixels[1 * 4] = {255u, 0u, 255u, 255u};
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 346 }
223 } 347 }
224 348
225 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) { 349 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) {
226 CopyType copy_type = GetParam(); 350 CopyType copy_type = GetParam();
227 glBindTexture(GL_TEXTURE_2D, textures_[0]); 351 glBindTexture(GL_TEXTURE_2D, textures_[0]);
228 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 352 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
229 nullptr); 353 nullptr);
230 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 354 EXPECT_TRUE(GL_NO_ERROR == glGetError());
231 355
356 struct FormatType {
357 GLenum internal_format;
358 GLenum format;
359 GLenum type;
360 };
361
232 // Check unsupported format reports error. 362 // Check unsupported format reports error.
233 GLint unsupported_dest_formats[] = {GL_ALPHA, GL_LUMINANCE, 363 // TODO(qiankun.miao@intel.com): find real unsupported formats.
234 GL_LUMINANCE_ALPHA}; 364 FormatType unsupported_format_types[] = {
235 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats); 365 {GL_RGBA32UI, GL_RGBA_INTEGER, GL_INT},
236 dest_index++) { 366 };
367 for (size_t i = 0; i < arraysize(unsupported_format_types); i++) {
237 if (copy_type == TexImage) { 368 if (copy_type == TexImage) {
238 glCopyTextureCHROMIUM(textures_[0], textures_[1], 369 glCopyTextureCHROMIUM(textures_[0], textures_[1],
239 unsupported_dest_formats[dest_index], 370 unsupported_format_types[i].internal_format,
240 GL_UNSIGNED_BYTE, false, false, false); 371 unsupported_format_types[i].type, false, false,
372 false);
241 } else { 373 } else {
242 glBindTexture(GL_TEXTURE_2D, textures_[1]); 374 glBindTexture(GL_TEXTURE_2D, textures_[1]);
243 glTexImage2D(GL_TEXTURE_2D, 0, unsupported_dest_formats[dest_index], 1, 1, 375 glTexImage2D(GL_TEXTURE_2D, 0,
244 0, unsupported_dest_formats[dest_index], GL_UNSIGNED_BYTE, 376 unsupported_format_types[i].internal_format, 1, 1, 0,
245 nullptr); 377 unsupported_format_types[i].format,
378 unsupported_format_types[i].type, nullptr);
246 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 379 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0,
247 0, 0, 1, 1, false, false, false); 380 0, 0, 1, 1, false, false, false);
248 } 381 }
249 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()) 382 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()) << "i:" << i;
250 << "dest_index:" << dest_index;
251 } 383 }
252 } 384 }
253 385
254 TEST_F(GLCopyTextureCHROMIUMTest, InternalFormatTypeCombinationNotSupported) { 386 TEST_F(GLCopyTextureCHROMIUMTest, InternalFormatTypeCombinationNotSupported) {
255 glBindTexture(GL_TEXTURE_2D, textures_[0]); 387 glBindTexture(GL_TEXTURE_2D, textures_[0]);
256 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 388 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
257 nullptr); 389 nullptr);
258 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 390 EXPECT_TRUE(GL_NO_ERROR == glGetError());
259 391
260 // Check unsupported internal_format/type combination reports error. 392 // Check unsupported internal_format/type combination reports error.
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 } 692 }
561 693
562 TEST_P(GLCopyTextureCHROMIUMTest, ProgramStatePreservation) { 694 TEST_P(GLCopyTextureCHROMIUMTest, ProgramStatePreservation) {
563 CopyType copy_type = GetParam(); 695 CopyType copy_type = GetParam();
564 // unbind the one created in setup. 696 // unbind the one created in setup.
565 glBindFramebuffer(GL_FRAMEBUFFER, 0); 697 glBindFramebuffer(GL_FRAMEBUFFER, 0);
566 glBindTexture(GL_TEXTURE_2D, 0); 698 glBindTexture(GL_TEXTURE_2D, 0);
567 699
568 GLManager gl2; 700 GLManager gl2;
569 GLManager::Options options; 701 GLManager::Options options;
702 options.context_type = gles2::CONTEXT_TYPE_OPENGLES3;
570 options.size = gfx::Size(16, 16); 703 options.size = gfx::Size(16, 16);
571 options.share_group_manager = &gl_; 704 options.share_group_manager = &gl_;
572 gl2.Initialize(options); 705 gl2.Initialize(options);
573 gl_.MakeCurrent(); 706 gl_.MakeCurrent();
574 707
575 static const char* v_shader_str = 708 static const char* v_shader_str =
576 "attribute vec4 g_Position;\n" 709 "attribute vec4 g_Position;\n"
577 "void main()\n" 710 "void main()\n"
578 "{\n" 711 "{\n"
579 " gl_Position = g_Position;\n" 712 " gl_Position = g_Position;\n"
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 expected_color = y < copy_region_y + 1 ? blue : white; 1027 expected_color = y < copy_region_y + 1 ? blue : white;
895 } 1028 }
896 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color); 1029 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color);
897 } 1030 }
898 } 1031 }
899 } 1032 }
900 } 1033 }
901 } 1034 }
902 1035
903 } // namespace gpu 1036 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698