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 | 12 |
13 #include "gpu/command_buffer/tests/gl_manager.h" | 13 #include "gpu/command_buffer/tests/gl_manager.h" |
14 #include "gpu/command_buffer/tests/gl_test_utils.h" | 14 #include "gpu/command_buffer/tests/gl_test_utils.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 namespace gpu { | 18 namespace gpu { |
19 | 19 |
20 namespace { | |
21 enum CopyType { TexImage, TexSubImage }; | |
22 const CopyType kCopyTypes[] = { | |
23 TexImage, | |
24 TexSubImage, | |
25 }; | |
26 } | |
27 | |
20 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. | 28 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. |
21 class GLCopyTextureCHROMIUMTest : public testing::Test { | 29 class GLCopyTextureCHROMIUMTest |
30 : public testing::Test, | |
31 public ::testing::WithParamInterface<CopyType> { | |
22 protected: | 32 protected: |
23 void SetUp() override { | 33 void SetUp() override { |
24 gl_.Initialize(GLManager::Options()); | 34 gl_.Initialize(GLManager::Options()); |
25 | 35 |
26 glGenTextures(2, textures_); | 36 glGenTextures(2, textures_); |
27 glBindTexture(GL_TEXTURE_2D, textures_[1]); | 37 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
28 | 38 |
29 // Some drivers (NVidia/SGX) require texture settings to be a certain way or | 39 // Some drivers (NVidia/SGX) require texture settings to be a certain way or |
30 // they won't report FRAMEBUFFER_COMPLETE. | 40 // they won't report FRAMEBUFFER_COMPLETE. |
31 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 41 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
(...skipping 11 matching lines...) Expand all Loading... | |
43 glDeleteTextures(2, textures_); | 53 glDeleteTextures(2, textures_); |
44 glDeleteFramebuffers(1, &framebuffer_id_); | 54 glDeleteFramebuffers(1, &framebuffer_id_); |
45 gl_.Destroy(); | 55 gl_.Destroy(); |
46 } | 56 } |
47 | 57 |
48 GLManager gl_; | 58 GLManager gl_; |
49 GLuint textures_[2]; | 59 GLuint textures_[2]; |
50 GLuint framebuffer_id_; | 60 GLuint framebuffer_id_; |
51 }; | 61 }; |
52 | 62 |
63 INSTANTIATE_TEST_CASE_P(CopyType, | |
64 GLCopyTextureCHROMIUMTest, | |
65 ::testing::ValuesIn(kCopyTypes)); | |
66 | |
53 // Test to ensure that the basic functionality of the extension works. | 67 // Test to ensure that the basic functionality of the extension works. |
54 TEST_F(GLCopyTextureCHROMIUMTest, Basic) { | 68 TEST_P(GLCopyTextureCHROMIUMTest, Basic) { |
69 CopyType copy_type = GetParam(); | |
55 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; | 70 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; |
56 | 71 |
57 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 72 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
58 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 73 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
59 pixels); | 74 pixels); |
60 | 75 |
61 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, | 76 if (copy_type == TexImage) { |
62 GL_UNSIGNED_BYTE); | 77 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, |
78 GL_UNSIGNED_BYTE); | |
79 } else { | |
80 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
81 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
82 nullptr); | |
83 | |
84 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, | |
85 0); | |
86 } | |
63 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | 87 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
64 | 88 |
65 // Check the FB is still bound. | 89 // Check the FB is still bound. |
66 GLint value = 0; | 90 GLint value = 0; |
67 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value); | 91 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value); |
68 GLuint fb_id = value; | 92 GLuint fb_id = value; |
69 EXPECT_EQ(framebuffer_id_, fb_id); | 93 EXPECT_EQ(framebuffer_id_, fb_id); |
70 | 94 |
71 // Check that FB is complete. | 95 // Check that FB is complete. |
72 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | 96 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
73 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | 97 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
74 | 98 |
75 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); | 99 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); |
76 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 100 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
77 } | 101 } |
78 | 102 |
79 TEST_F(GLCopyTextureCHROMIUMTest, InternalFormat) { | 103 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { |
104 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { | |
105 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; | |
106 return; | |
107 } | |
108 CopyType copy_type = GetParam(); | |
109 | |
110 uint8 pixels[1 * 4] = {255u, 0u, 0u, 255u}; | |
111 | |
112 glBindTexture(GL_TEXTURE_2D, textures_[0]); | |
113 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 1, 1); | |
114 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, | |
115 pixels); | |
116 | |
117 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
118 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 1, 1); | |
119 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | |
120 textures_[1], 0); | |
121 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
122 | |
123 if (copy_type == TexImage) { | |
124 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, | |
125 GL_UNSIGNED_BYTE); | |
126 EXPECT_TRUE(glGetError() == GL_INVALID_OPERATION); | |
127 } else { | |
128 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, | |
129 0); | |
130 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
131 | |
132 // Check the FB is still bound. | |
133 GLint value = 0; | |
134 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value); | |
135 GLuint fb_id = value; | |
136 EXPECT_EQ(framebuffer_id_, fb_id); | |
137 | |
138 // Check that FB is complete. | |
139 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | |
140 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | |
141 | |
142 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); | |
143 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | |
144 } | |
145 } | |
146 | |
147 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormat) { | |
148 CopyType copy_type = GetParam(); | |
80 GLint src_formats[] = {GL_ALPHA, GL_RGB, GL_RGBA, | 149 GLint src_formats[] = {GL_ALPHA, GL_RGB, GL_RGBA, |
81 GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGRA_EXT}; | 150 GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGRA_EXT}; |
82 GLint dest_formats[] = {GL_RGB, GL_RGBA}; | 151 GLint dest_formats[] = {GL_RGB, GL_RGBA}; |
83 | 152 |
84 for (size_t src_index = 0; src_index < arraysize(src_formats); src_index++) { | 153 for (size_t src_index = 0; src_index < arraysize(src_formats); src_index++) { |
85 for (size_t dest_index = 0; dest_index < arraysize(dest_formats); | 154 for (size_t dest_index = 0; dest_index < arraysize(dest_formats); |
86 dest_index++) { | 155 dest_index++) { |
87 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 156 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
88 glTexImage2D(GL_TEXTURE_2D, | 157 glTexImage2D(GL_TEXTURE_2D, 0, src_formats[src_index], 1, 1, 0, |
89 0, | 158 src_formats[src_index], GL_UNSIGNED_BYTE, nullptr); |
90 src_formats[src_index], | |
91 1, | |
92 1, | |
93 0, | |
94 src_formats[src_index], | |
95 GL_UNSIGNED_BYTE, | |
96 NULL); | |
97 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 159 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
98 | 160 |
99 glCopyTextureCHROMIUM(GL_TEXTURE_2D, | 161 if (copy_type == TexImage) { |
100 textures_[0], | 162 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, |
101 textures_[1], | 163 dest_formats[dest_index], GL_UNSIGNED_BYTE); |
102 0, | 164 } else { |
103 dest_formats[dest_index], | 165 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
104 GL_UNSIGNED_BYTE); | 166 glTexImage2D(GL_TEXTURE_2D, 0, dest_formats[dest_index], 1, 1, 0, |
167 dest_formats[dest_index], GL_UNSIGNED_BYTE, nullptr); | |
168 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | |
169 | |
170 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, | |
171 0, 0); | |
172 } | |
173 | |
105 EXPECT_TRUE(GL_NO_ERROR == glGetError()) << "src_index:" << src_index | 174 EXPECT_TRUE(GL_NO_ERROR == glGetError()) << "src_index:" << src_index |
106 << " dest_index:" << dest_index; | 175 << " dest_index:" << dest_index; |
107 } | 176 } |
108 } | 177 } |
109 } | 178 } |
110 | 179 |
111 TEST_F(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) { | 180 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) { |
181 CopyType copy_type = GetParam(); | |
112 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 182 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
113 glTexImage2D( | 183 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
114 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 184 nullptr); |
115 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 185 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
116 | 186 |
117 // Check unsupported format reports error. | 187 // Check unsupported format reports error. |
118 GLint unsupported_dest_formats[] = {GL_ALPHA, GL_LUMINANCE, | 188 GLint unsupported_dest_formats[] = {GL_ALPHA, GL_LUMINANCE, |
119 GL_LUMINANCE_ALPHA}; | 189 GL_LUMINANCE_ALPHA}; |
120 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats); | 190 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats); |
121 dest_index++) { | 191 dest_index++) { |
122 glCopyTextureCHROMIUM(GL_TEXTURE_2D, | 192 if (copy_type == TexImage) { |
123 textures_[0], | 193 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, |
124 textures_[1], | 194 unsupported_dest_formats[dest_index], |
125 0, | 195 GL_UNSIGNED_BYTE); |
126 unsupported_dest_formats[dest_index], | 196 } else { |
127 GL_UNSIGNED_BYTE); | 197 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
198 glTexImage2D(GL_TEXTURE_2D, 0, unsupported_dest_formats[dest_index], 1, 1, | |
199 0, unsupported_dest_formats[dest_index], GL_UNSIGNED_BYTE, | |
200 nullptr); | |
201 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, | |
202 0); | |
203 } | |
128 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()) | 204 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()) |
129 << "dest_index:" << dest_index; | 205 << "dest_index:" << dest_index; |
130 } | 206 } |
131 } | 207 } |
132 | 208 |
133 // Test to ensure that the destination texture is redefined if the properties | 209 // Test to ensure that the destination texture is redefined if the properties |
134 // are different. | 210 // are different. |
135 TEST_F(GLCopyTextureCHROMIUMTest, RedefineDestinationTexture) { | 211 TEST_F(GLCopyTextureCHROMIUMTest, RedefineDestinationTexture) { |
136 uint8 pixels[4 * 4] = {255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u, | 212 uint8 pixels[4 * 4] = {255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u, |
137 255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u}; | 213 255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u}; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 | 258 |
183 // Check that FB is complete. | 259 // Check that FB is complete. |
184 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | 260 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
185 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | 261 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
186 | 262 |
187 GLTestHelper::CheckPixels(1, 1, 1, 1, 0, &pixels[12]); | 263 GLTestHelper::CheckPixels(1, 1, 1, 1, 0, &pixels[12]); |
188 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 264 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
189 } | 265 } |
190 | 266 |
191 // Test that the extension respects the flip-y pixel storage setting. | 267 // Test that the extension respects the flip-y pixel storage setting. |
192 TEST_F(GLCopyTextureCHROMIUMTest, FlipY) { | 268 TEST_P(GLCopyTextureCHROMIUMTest, FlipY) { |
269 CopyType copy_type = GetParam(); | |
193 uint8 pixels[2][2][4]; | 270 uint8 pixels[2][2][4]; |
194 for (int x = 0; x < 2; ++x) { | 271 for (int x = 0; x < 2; ++x) { |
195 for (int y = 0; y < 2; ++y) { | 272 for (int y = 0; y < 2; ++y) { |
196 pixels[y][x][0] = x + y; | 273 pixels[y][x][0] = x + y; |
197 pixels[y][x][1] = x + y; | 274 pixels[y][x][1] = x + y; |
198 pixels[y][x][2] = x + y; | 275 pixels[y][x][2] = x + y; |
199 pixels[y][x][3] = 255u; | 276 pixels[y][x][3] = 255u; |
200 } | 277 } |
201 } | 278 } |
202 | 279 |
203 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 280 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
204 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 281 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
205 pixels); | 282 pixels); |
206 | 283 |
207 glPixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, GL_TRUE); | 284 glPixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, GL_TRUE); |
208 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, | 285 |
209 GL_UNSIGNED_BYTE); | 286 if (copy_type == TexImage) { |
287 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, | |
288 GL_UNSIGNED_BYTE); | |
289 } else { | |
290 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
291 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
292 nullptr); | |
293 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, | |
294 0); | |
295 } | |
210 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 296 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
211 | 297 |
212 uint8 copied_pixels[2][2][4] = {{{0}}}; | 298 uint8 copied_pixels[2][2][4] = {{{0}}}; |
213 glReadPixels(0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels); | 299 glReadPixels(0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels); |
214 for (int x = 0; x < 2; ++x) { | 300 for (int x = 0; x < 2; ++x) { |
215 for (int y = 0; y < 2; ++y) { | 301 for (int y = 0; y < 2; ++y) { |
216 EXPECT_EQ(pixels[1-y][x][0], copied_pixels[y][x][0]); | 302 EXPECT_EQ(pixels[1-y][x][0], copied_pixels[y][x][0]); |
217 EXPECT_EQ(pixels[1-y][x][1], copied_pixels[y][x][1]); | 303 EXPECT_EQ(pixels[1-y][x][1], copied_pixels[y][x][1]); |
218 EXPECT_EQ(pixels[1-y][x][2], copied_pixels[y][x][2]); | 304 EXPECT_EQ(pixels[1-y][x][2], copied_pixels[y][x][2]); |
219 EXPECT_EQ(pixels[1-y][x][3], copied_pixels[y][x][3]); | 305 EXPECT_EQ(pixels[1-y][x][3], copied_pixels[y][x][3]); |
220 } | 306 } |
221 } | 307 } |
222 | 308 |
223 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 309 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
224 } | 310 } |
225 | 311 |
226 // Test that the extension respects the GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM | 312 // Test that the extension respects the GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM |
227 // storage setting. | 313 // storage setting. |
228 TEST_F(GLCopyTextureCHROMIUMTest, PremultiplyAlpha) { | 314 TEST_P(GLCopyTextureCHROMIUMTest, PremultiplyAlpha) { |
315 CopyType copy_type = GetParam(); | |
229 uint8 pixels[1 * 4] = { 2, 2, 2, 128 }; | 316 uint8 pixels[1 * 4] = { 2, 2, 2, 128 }; |
230 | 317 |
231 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 318 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
232 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 319 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
233 pixels); | 320 pixels); |
234 | 321 |
235 glPixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, GL_TRUE); | 322 glPixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, GL_TRUE); |
236 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, | 323 if (copy_type == TexImage) { |
237 GL_UNSIGNED_BYTE); | 324 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, |
325 GL_UNSIGNED_BYTE); | |
326 } else { | |
327 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
328 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
329 nullptr); | |
330 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, | |
331 0); | |
332 } | |
238 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 333 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
239 | 334 |
240 uint8 copied_pixels[1 * 4] = {0}; | 335 uint8 copied_pixels[1 * 4] = {0}; |
241 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels); | 336 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels); |
242 EXPECT_EQ(1u, copied_pixels[0]); | 337 EXPECT_EQ(1u, copied_pixels[0]); |
243 EXPECT_EQ(1u, copied_pixels[1]); | 338 EXPECT_EQ(1u, copied_pixels[1]); |
244 EXPECT_EQ(1u, copied_pixels[2]); | 339 EXPECT_EQ(1u, copied_pixels[2]); |
245 EXPECT_EQ(128u, copied_pixels[3]); | 340 EXPECT_EQ(128u, copied_pixels[3]); |
246 | 341 |
247 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 342 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
248 } | 343 } |
249 | 344 |
250 // Test that the extension respects the GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM | 345 // Test that the extension respects the GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM |
251 // storage setting. | 346 // storage setting. |
252 TEST_F(GLCopyTextureCHROMIUMTest, UnpremultiplyAlpha) { | 347 TEST_P(GLCopyTextureCHROMIUMTest, UnpremultiplyAlpha) { |
348 CopyType copy_type = GetParam(); | |
253 uint8 pixels[1 * 4] = { 16, 16, 16, 128 }; | 349 uint8 pixels[1 * 4] = { 16, 16, 16, 128 }; |
254 | 350 |
255 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 351 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
256 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, |
257 pixels); | 353 pixels); |
258 | 354 |
259 glPixelStorei(GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, GL_TRUE); | 355 glPixelStorei(GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, GL_TRUE); |
260 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, | 356 if (copy_type == TexImage) { |
261 GL_UNSIGNED_BYTE); | 357 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, |
358 GL_UNSIGNED_BYTE); | |
359 } else { | |
360 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
361 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
362 nullptr); | |
363 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, | |
364 0); | |
365 } | |
262 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 366 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
263 | 367 |
264 uint8 copied_pixels[1 * 4] = {0}; | 368 uint8 copied_pixels[1 * 4] = {0}; |
265 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels); | 369 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels); |
266 EXPECT_EQ(32u, copied_pixels[0]); | 370 EXPECT_EQ(32u, copied_pixels[0]); |
267 EXPECT_EQ(32u, copied_pixels[1]); | 371 EXPECT_EQ(32u, copied_pixels[1]); |
268 EXPECT_EQ(32u, copied_pixels[2]); | 372 EXPECT_EQ(32u, copied_pixels[2]); |
269 EXPECT_EQ(128u, copied_pixels[3]); | 373 EXPECT_EQ(128u, copied_pixels[3]); |
270 | 374 |
271 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 375 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
272 } | 376 } |
273 | 377 |
274 TEST_F(GLCopyTextureCHROMIUMTest, FlipYAndPremultiplyAlpha) { | 378 TEST_P(GLCopyTextureCHROMIUMTest, FlipYAndPremultiplyAlpha) { |
379 CopyType copy_type = GetParam(); | |
275 uint8 pixels[2][2][4]; | 380 uint8 pixels[2][2][4]; |
276 for (int x = 0; x < 2; ++x) { | 381 for (int x = 0; x < 2; ++x) { |
277 for (int y = 0; y < 2; ++y) { | 382 for (int y = 0; y < 2; ++y) { |
278 uint8 color = 16 * x + 16 * y; | 383 uint8 color = 16 * x + 16 * y; |
279 pixels[y][x][0] = color; | 384 pixels[y][x][0] = color; |
280 pixels[y][x][1] = color; | 385 pixels[y][x][1] = color; |
281 pixels[y][x][2] = color; | 386 pixels[y][x][2] = color; |
282 pixels[y][x][3] = 128u; | 387 pixels[y][x][3] = 128u; |
283 } | 388 } |
284 } | 389 } |
285 | 390 |
286 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 391 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
287 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 392 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
288 pixels); | 393 pixels); |
289 | 394 |
290 glPixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, GL_TRUE); | 395 glPixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, GL_TRUE); |
291 glPixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, GL_TRUE); | 396 glPixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, GL_TRUE); |
292 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, | 397 if (copy_type == TexImage) { |
293 GL_UNSIGNED_BYTE); | 398 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, |
399 GL_UNSIGNED_BYTE); | |
400 } else { | |
401 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
402 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
403 nullptr); | |
404 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, | |
405 0); | |
406 } | |
294 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 407 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
295 | 408 |
296 uint8 copied_pixels[2][2][4] = {{{0}}}; | 409 uint8 copied_pixels[2][2][4] = {{{0}}}; |
297 glReadPixels(0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels); | 410 glReadPixels(0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels); |
298 for (int x = 0; x < 2; ++x) { | 411 for (int x = 0; x < 2; ++x) { |
299 for (int y = 0; y < 2; ++y) { | 412 for (int y = 0; y < 2; ++y) { |
300 EXPECT_EQ(pixels[1-y][x][0] / 2, copied_pixels[y][x][0]); | 413 EXPECT_EQ(pixels[1-y][x][0] / 2, copied_pixels[y][x][0]); |
301 EXPECT_EQ(pixels[1-y][x][1] / 2, copied_pixels[y][x][1]); | 414 EXPECT_EQ(pixels[1-y][x][1] / 2, copied_pixels[y][x][1]); |
302 EXPECT_EQ(pixels[1-y][x][2] / 2, copied_pixels[y][x][2]); | 415 EXPECT_EQ(pixels[1-y][x][2] / 2, copied_pixels[y][x][2]); |
303 EXPECT_EQ(pixels[1-y][x][3], copied_pixels[y][x][3]); | 416 EXPECT_EQ(pixels[1-y][x][3], copied_pixels[y][x][3]); |
304 } | 417 } |
305 } | 418 } |
306 | 419 |
307 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 420 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
308 } | 421 } |
309 | 422 |
310 TEST_F(GLCopyTextureCHROMIUMTest, FlipYAndUnpremultiplyAlpha) { | 423 TEST_P(GLCopyTextureCHROMIUMTest, FlipYAndUnpremultiplyAlpha) { |
424 CopyType copy_type = GetParam(); | |
311 uint8 pixels[2][2][4]; | 425 uint8 pixels[2][2][4]; |
312 for (int x = 0; x < 2; ++x) { | 426 for (int x = 0; x < 2; ++x) { |
313 for (int y = 0; y < 2; ++y) { | 427 for (int y = 0; y < 2; ++y) { |
314 uint8 color = 16 * x + 16 * y; | 428 uint8 color = 16 * x + 16 * y; |
315 pixels[y][x][0] = color; | 429 pixels[y][x][0] = color; |
316 pixels[y][x][1] = color; | 430 pixels[y][x][1] = color; |
317 pixels[y][x][2] = color; | 431 pixels[y][x][2] = color; |
318 pixels[y][x][3] = 128u; | 432 pixels[y][x][3] = 128u; |
319 } | 433 } |
320 } | 434 } |
321 | 435 |
322 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 436 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
323 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 437 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
324 pixels); | 438 pixels); |
325 | 439 |
326 glPixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, GL_TRUE); | 440 glPixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, GL_TRUE); |
327 glPixelStorei(GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, GL_TRUE); | 441 glPixelStorei(GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, GL_TRUE); |
328 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, | 442 if (copy_type == TexImage) { |
329 GL_UNSIGNED_BYTE); | 443 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, |
444 GL_UNSIGNED_BYTE); | |
445 } else { | |
446 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
447 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
448 nullptr); | |
449 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, | |
450 0); | |
451 } | |
330 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 452 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
331 | 453 |
332 uint8 copied_pixels[2][2][4] = {{{0}}}; | 454 uint8 copied_pixels[2][2][4] = {{{0}}}; |
333 glReadPixels(0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels); | 455 glReadPixels(0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels); |
334 for (int x = 0; x < 2; ++x) { | 456 for (int x = 0; x < 2; ++x) { |
335 for (int y = 0; y < 2; ++y) { | 457 for (int y = 0; y < 2; ++y) { |
336 EXPECT_EQ(pixels[1-y][x][0] * 2, copied_pixels[y][x][0]); | 458 EXPECT_EQ(pixels[1-y][x][0] * 2, copied_pixels[y][x][0]); |
337 EXPECT_EQ(pixels[1-y][x][1] * 2, copied_pixels[y][x][1]); | 459 EXPECT_EQ(pixels[1-y][x][1] * 2, copied_pixels[y][x][1]); |
338 EXPECT_EQ(pixels[1-y][x][2] * 2, copied_pixels[y][x][2]); | 460 EXPECT_EQ(pixels[1-y][x][2] * 2, copied_pixels[y][x][2]); |
339 EXPECT_EQ(pixels[1-y][x][3], copied_pixels[y][x][3]); | 461 EXPECT_EQ(pixels[1-y][x][3], copied_pixels[y][x][3]); |
340 } | 462 } |
341 } | 463 } |
342 | 464 |
343 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 465 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
344 } | 466 } |
345 | 467 |
346 namespace { | 468 namespace { |
347 | 469 |
348 void glEnableDisable(GLint param, GLboolean value) { | 470 void glEnableDisable(GLint param, GLboolean value) { |
349 if (value) | 471 if (value) |
350 glEnable(param); | 472 glEnable(param); |
351 else | 473 else |
352 glDisable(param); | 474 glDisable(param); |
353 } | 475 } |
354 | 476 |
355 } // unnamed namespace | 477 } // unnamed namespace |
356 | 478 |
357 // Validate that some basic GL state is not touched upon execution of | 479 // Validate that some basic GL state is not touched upon execution of |
358 // the extension. | 480 // the extension. |
359 TEST_F(GLCopyTextureCHROMIUMTest, BasicStatePreservation) { | 481 TEST_P(GLCopyTextureCHROMIUMTest, BasicStatePreservation) { |
482 CopyType copy_type = GetParam(); | |
360 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; | 483 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; |
361 | 484 |
362 glBindFramebuffer(GL_FRAMEBUFFER, 0); | 485 glBindFramebuffer(GL_FRAMEBUFFER, 0); |
363 | 486 |
364 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 487 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
365 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 488 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
366 pixels); | 489 pixels); |
367 | 490 |
491 if (copy_type == TexSubImage) { | |
492 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
493 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
494 nullptr); | |
495 } | |
496 | |
368 GLboolean reference_settings[2] = { GL_TRUE, GL_FALSE }; | 497 GLboolean reference_settings[2] = { GL_TRUE, GL_FALSE }; |
369 for (int x = 0; x < 2; ++x) { | 498 for (int x = 0; x < 2; ++x) { |
370 GLboolean setting = reference_settings[x]; | 499 GLboolean setting = reference_settings[x]; |
371 glEnableDisable(GL_DEPTH_TEST, setting); | 500 glEnableDisable(GL_DEPTH_TEST, setting); |
372 glEnableDisable(GL_SCISSOR_TEST, setting); | 501 glEnableDisable(GL_SCISSOR_TEST, setting); |
373 glEnableDisable(GL_STENCIL_TEST, setting); | 502 glEnableDisable(GL_STENCIL_TEST, setting); |
374 glEnableDisable(GL_CULL_FACE, setting); | 503 glEnableDisable(GL_CULL_FACE, setting); |
375 glEnableDisable(GL_BLEND, setting); | 504 glEnableDisable(GL_BLEND, setting); |
376 glColorMask(setting, setting, setting, setting); | 505 glColorMask(setting, setting, setting, setting); |
377 glDepthMask(setting); | 506 glDepthMask(setting); |
378 | 507 |
379 glActiveTexture(GL_TEXTURE1 + x); | 508 glActiveTexture(GL_TEXTURE1 + x); |
380 | 509 |
381 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, | 510 if (copy_type == TexImage) { |
382 GL_RGBA, GL_UNSIGNED_BYTE); | 511 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, |
512 GL_RGBA, GL_UNSIGNED_BYTE); | |
513 } else { | |
514 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, | |
515 0); | |
516 } | |
383 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 517 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
384 | 518 |
385 EXPECT_EQ(setting, glIsEnabled(GL_DEPTH_TEST)); | 519 EXPECT_EQ(setting, glIsEnabled(GL_DEPTH_TEST)); |
386 EXPECT_EQ(setting, glIsEnabled(GL_SCISSOR_TEST)); | 520 EXPECT_EQ(setting, glIsEnabled(GL_SCISSOR_TEST)); |
387 EXPECT_EQ(setting, glIsEnabled(GL_STENCIL_TEST)); | 521 EXPECT_EQ(setting, glIsEnabled(GL_STENCIL_TEST)); |
388 EXPECT_EQ(setting, glIsEnabled(GL_CULL_FACE)); | 522 EXPECT_EQ(setting, glIsEnabled(GL_CULL_FACE)); |
389 EXPECT_EQ(setting, glIsEnabled(GL_BLEND)); | 523 EXPECT_EQ(setting, glIsEnabled(GL_BLEND)); |
390 | 524 |
391 GLboolean bool_array[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE }; | 525 GLboolean bool_array[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE }; |
392 glGetBooleanv(GL_DEPTH_WRITEMASK, bool_array); | 526 glGetBooleanv(GL_DEPTH_WRITEMASK, bool_array); |
393 EXPECT_EQ(setting, bool_array[0]); | 527 EXPECT_EQ(setting, bool_array[0]); |
394 | 528 |
395 bool_array[0] = GL_FALSE; | 529 bool_array[0] = GL_FALSE; |
396 glGetBooleanv(GL_COLOR_WRITEMASK, bool_array); | 530 glGetBooleanv(GL_COLOR_WRITEMASK, bool_array); |
397 EXPECT_EQ(setting, bool_array[0]); | 531 EXPECT_EQ(setting, bool_array[0]); |
398 EXPECT_EQ(setting, bool_array[1]); | 532 EXPECT_EQ(setting, bool_array[1]); |
399 EXPECT_EQ(setting, bool_array[2]); | 533 EXPECT_EQ(setting, bool_array[2]); |
400 EXPECT_EQ(setting, bool_array[3]); | 534 EXPECT_EQ(setting, bool_array[3]); |
401 | 535 |
402 GLint active_texture = 0; | 536 GLint active_texture = 0; |
403 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); | 537 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); |
404 EXPECT_EQ(GL_TEXTURE1 + x, active_texture); | 538 EXPECT_EQ(GL_TEXTURE1 + x, active_texture); |
405 } | 539 } |
406 | 540 |
407 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 541 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
408 }; | 542 }; |
409 | 543 |
410 // Verify that invocation of the extension does not modify the bound | 544 // Verify that invocation of the extension does not modify the bound |
411 // texture state. | 545 // texture state. |
412 TEST_F(GLCopyTextureCHROMIUMTest, TextureStatePreserved) { | 546 TEST_P(GLCopyTextureCHROMIUMTest, TextureStatePreserved) { |
547 CopyType copy_type = GetParam(); | |
413 // Setup the texture used for the extension invocation. | 548 // Setup the texture used for the extension invocation. |
414 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; | 549 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; |
415 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 550 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
416 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 551 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
417 pixels); | 552 pixels); |
418 | 553 |
554 if (copy_type == TexSubImage) { | |
555 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
556 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
557 nullptr); | |
558 } | |
559 | |
419 GLuint texture_ids[2]; | 560 GLuint texture_ids[2]; |
420 glGenTextures(2, texture_ids); | 561 glGenTextures(2, texture_ids); |
421 | 562 |
422 glActiveTexture(GL_TEXTURE0); | 563 glActiveTexture(GL_TEXTURE0); |
423 glBindTexture(GL_TEXTURE_2D, texture_ids[0]); | 564 glBindTexture(GL_TEXTURE_2D, texture_ids[0]); |
424 | 565 |
425 glActiveTexture(GL_TEXTURE1); | 566 glActiveTexture(GL_TEXTURE1); |
426 glBindTexture(GL_TEXTURE_2D, texture_ids[1]); | 567 glBindTexture(GL_TEXTURE_2D, texture_ids[1]); |
427 | 568 |
428 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, | 569 if (copy_type == TexImage) { |
429 GL_RGBA, GL_UNSIGNED_BYTE); | 570 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, |
571 GL_UNSIGNED_BYTE); | |
572 } else { | |
573 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, | |
574 0); | |
575 } | |
430 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 576 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
431 | 577 |
432 GLint active_texture = 0; | 578 GLint active_texture = 0; |
433 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); | 579 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); |
434 EXPECT_EQ(GL_TEXTURE1, active_texture); | 580 EXPECT_EQ(GL_TEXTURE1, active_texture); |
435 | 581 |
436 GLint bound_texture = 0; | 582 GLint bound_texture = 0; |
437 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); | 583 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); |
438 EXPECT_EQ(texture_ids[1], static_cast<GLuint>(bound_texture)); | 584 EXPECT_EQ(texture_ids[1], static_cast<GLuint>(bound_texture)); |
439 glBindTexture(GL_TEXTURE_2D, 0); | 585 glBindTexture(GL_TEXTURE_2D, 0); |
440 | 586 |
441 bound_texture = 0; | 587 bound_texture = 0; |
442 glActiveTexture(GL_TEXTURE0); | 588 glActiveTexture(GL_TEXTURE0); |
443 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); | 589 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); |
444 EXPECT_EQ(texture_ids[0], static_cast<GLuint>(bound_texture)); | 590 EXPECT_EQ(texture_ids[0], static_cast<GLuint>(bound_texture)); |
445 glBindTexture(GL_TEXTURE_2D, 0); | 591 glBindTexture(GL_TEXTURE_2D, 0); |
446 | 592 |
447 glDeleteTextures(2, texture_ids); | 593 glDeleteTextures(2, texture_ids); |
448 | 594 |
449 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 595 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
450 } | 596 } |
451 | 597 |
452 // Verify that invocation of the extension does not perturb the currently | 598 // Verify that invocation of the extension does not perturb the currently |
453 // bound FBO state. | 599 // bound FBO state. |
454 TEST_F(GLCopyTextureCHROMIUMTest, FBOStatePreserved) { | 600 TEST_P(GLCopyTextureCHROMIUMTest, FBOStatePreserved) { |
601 CopyType copy_type = GetParam(); | |
455 // Setup the texture used for the extension invocation. | 602 // Setup the texture used for the extension invocation. |
456 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; | 603 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; |
457 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 604 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
458 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 605 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
459 pixels); | 606 pixels); |
460 | 607 |
608 if (copy_type == TexSubImage) { | |
609 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
610 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
611 nullptr); | |
612 } | |
613 | |
461 GLuint texture_id; | 614 GLuint texture_id; |
462 glGenTextures(1, &texture_id); | 615 glGenTextures(1, &texture_id); |
463 glBindTexture(GL_TEXTURE_2D, texture_id); | 616 glBindTexture(GL_TEXTURE_2D, texture_id); |
464 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 617 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
465 0); | 618 0); |
466 | 619 |
467 GLuint renderbuffer_id; | 620 GLuint renderbuffer_id; |
468 glGenRenderbuffers(1, &renderbuffer_id); | 621 glGenRenderbuffers(1, &renderbuffer_id); |
469 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer_id); | 622 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer_id); |
470 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 1, 1); | 623 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 1, 1); |
471 | 624 |
472 GLuint framebuffer_id; | 625 GLuint framebuffer_id; |
473 glGenFramebuffers(1, &framebuffer_id); | 626 glGenFramebuffers(1, &framebuffer_id); |
474 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id); | 627 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id); |
475 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 628 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
476 texture_id, 0); | 629 texture_id, 0); |
477 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, | 630 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, |
478 GL_RENDERBUFFER, renderbuffer_id); | 631 GL_RENDERBUFFER, renderbuffer_id); |
479 EXPECT_TRUE( | 632 EXPECT_TRUE( |
480 GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER)); | 633 GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
481 | 634 |
482 // Test that we can write to the bound framebuffer | 635 // Test that we can write to the bound framebuffer |
483 uint8 expected_color[4] = { 255u, 255u, 0, 255u }; | 636 uint8 expected_color[4] = { 255u, 255u, 0, 255u }; |
484 glClearColor(1.0, 1.0, 0, 1.0); | 637 glClearColor(1.0, 1.0, 0, 1.0); |
485 glClear(GL_COLOR_BUFFER_BIT); | 638 glClear(GL_COLOR_BUFFER_BIT); |
486 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color); | 639 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color); |
487 | 640 |
488 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, | 641 if (copy_type == TexImage) { |
489 GL_RGBA, GL_UNSIGNED_BYTE); | 642 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, |
643 GL_UNSIGNED_BYTE); | |
644 } else { | |
645 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, | |
646 0); | |
647 } | |
490 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 648 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
491 | 649 |
492 EXPECT_TRUE(glIsFramebuffer(framebuffer_id)); | 650 EXPECT_TRUE(glIsFramebuffer(framebuffer_id)); |
493 | 651 |
494 // Ensure that reading from the framebuffer produces correct pixels. | 652 // Ensure that reading from the framebuffer produces correct pixels. |
495 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color); | 653 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color); |
496 | 654 |
497 uint8 expected_color2[4] = { 255u, 0, 255u, 255u }; | 655 uint8 expected_color2[4] = { 255u, 0, 255u, 255u }; |
498 glClearColor(1.0, 0, 1.0, 1.0); | 656 glClearColor(1.0, 0, 1.0, 1.0); |
499 glClear(GL_COLOR_BUFFER_BIT); | 657 glClear(GL_COLOR_BUFFER_BIT); |
(...skipping 27 matching lines...) Expand all Loading... | |
527 &fbo_params); | 685 &fbo_params); |
528 EXPECT_EQ(renderbuffer_id, static_cast<GLuint>(fbo_params)); | 686 EXPECT_EQ(renderbuffer_id, static_cast<GLuint>(fbo_params)); |
529 | 687 |
530 glDeleteRenderbuffers(1, &renderbuffer_id); | 688 glDeleteRenderbuffers(1, &renderbuffer_id); |
531 glDeleteTextures(1, &texture_id); | 689 glDeleteTextures(1, &texture_id); |
532 glDeleteFramebuffers(1, &framebuffer_id); | 690 glDeleteFramebuffers(1, &framebuffer_id); |
533 | 691 |
534 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 692 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
535 } | 693 } |
536 | 694 |
537 TEST_F(GLCopyTextureCHROMIUMTest, ProgramStatePreservation) { | 695 TEST_P(GLCopyTextureCHROMIUMTest, ProgramStatePreservation) { |
696 CopyType copy_type = GetParam(); | |
538 // unbind the one created in setup. | 697 // unbind the one created in setup. |
539 glBindFramebuffer(GL_FRAMEBUFFER, 0); | 698 glBindFramebuffer(GL_FRAMEBUFFER, 0); |
540 glBindTexture(GL_TEXTURE_2D, 0); | 699 glBindTexture(GL_TEXTURE_2D, 0); |
541 | 700 |
542 GLManager gl2; | 701 GLManager gl2; |
543 GLManager::Options options; | 702 GLManager::Options options; |
544 options.size = gfx::Size(16, 16); | 703 options.size = gfx::Size(16, 16); |
545 options.share_group_manager = &gl_; | 704 options.share_group_manager = &gl_; |
546 gl2.Initialize(options); | 705 gl2.Initialize(options); |
547 gl_.MakeCurrent(); | 706 gl_.MakeCurrent(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 glClear(GL_COLOR_BUFFER_BIT); | 740 glClear(GL_COLOR_BUFFER_BIT); |
582 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, zero)); | 741 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, zero)); |
583 glDrawArrays(GL_TRIANGLES, 0, 6); | 742 glDrawArrays(GL_TRIANGLES, 0, 6); |
584 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected)); | 743 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected)); |
585 | 744 |
586 // Call copyTextureCHROMIUM | 745 // Call copyTextureCHROMIUM |
587 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; | 746 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; |
588 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 747 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
589 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 748 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
590 pixels); | 749 pixels); |
591 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, | 750 if (copy_type == TexImage) { |
592 GL_UNSIGNED_BYTE); | 751 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, |
752 GL_UNSIGNED_BYTE); | |
753 } else { | |
754 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
755 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
756 nullptr); | |
757 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, | |
758 0); | |
759 } | |
593 | 760 |
594 // test using program after | 761 // test using program after |
595 glClear(GL_COLOR_BUFFER_BIT); | 762 glClear(GL_COLOR_BUFFER_BIT); |
596 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, zero)); | 763 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, zero)); |
597 glDrawArrays(GL_TRIANGLES, 0, 6); | 764 glDrawArrays(GL_TRIANGLES, 0, 6); |
598 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected)); | 765 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected)); |
599 | 766 |
600 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 767 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
601 | 768 |
602 gl2.MakeCurrent(); | 769 gl2.MakeCurrent(); |
603 gl2.Destroy(); | 770 gl2.Destroy(); |
604 gl_.MakeCurrent(); | 771 gl_.MakeCurrent(); |
605 } | 772 } |
606 | 773 |
607 // Test that glCopyTextureCHROMIUM doesn't leak uninitialized textures. | 774 // Test that glCopyTextureCHROMIUM doesn't leak uninitialized textures. |
608 TEST_F(GLCopyTextureCHROMIUMTest, UninitializedSource) { | 775 TEST_P(GLCopyTextureCHROMIUMTest, UninitializedSource) { |
776 CopyType copy_type = GetParam(); | |
609 const GLsizei kWidth = 64, kHeight = 64; | 777 const GLsizei kWidth = 64, kHeight = 64; |
610 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 778 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
611 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, | 779 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, 0, GL_RGBA, |
612 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 780 GL_UNSIGNED_BYTE, nullptr); |
613 | 781 |
614 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, | 782 if (copy_type == TexImage) { |
615 GL_UNSIGNED_BYTE); | 783 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, |
784 GL_UNSIGNED_BYTE); | |
785 } else { | |
786 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
787 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, 0, GL_RGBA, | |
788 GL_UNSIGNED_BYTE, nullptr); | |
789 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, | |
790 0); | |
791 } | |
616 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 792 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
617 | 793 |
618 uint8 pixels[kHeight][kWidth][4] = {{{1}}}; | 794 uint8 pixels[kHeight][kWidth][4] = {{{1}}}; |
619 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixels); | 795 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
620 for (int x = 0; x < kWidth; ++x) { | 796 for (int x = 0; x < kWidth; ++x) { |
621 for (int y = 0; y < kHeight; ++y) { | 797 for (int y = 0; y < kHeight; ++y) { |
622 EXPECT_EQ(0, pixels[y][x][0]); | 798 EXPECT_EQ(0, pixels[y][x][0]); |
623 EXPECT_EQ(0, pixels[y][x][1]); | 799 EXPECT_EQ(0, pixels[y][x][1]); |
624 EXPECT_EQ(0, pixels[y][x][2]); | 800 EXPECT_EQ(0, pixels[y][x][2]); |
625 EXPECT_EQ(0, pixels[y][x][3]); | 801 EXPECT_EQ(0, pixels[y][x][3]); |
626 } | 802 } |
627 } | 803 } |
628 | 804 |
629 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 805 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
630 } | 806 } |
631 | 807 |
808 TEST_F(GLCopyTextureCHROMIUMTest, CopySubTextureDimension) { | |
809 glBindTexture(GL_TEXTURE_2D, textures_[0]); | |
810 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
811 nullptr); | |
812 | |
813 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
814 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
815 nullptr); | |
816 | |
817 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 1, 1); | |
818 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | |
819 | |
820 // xoffset < 0 | |
821 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, -1, 1); | |
822 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); | |
823 | |
824 // xoffset + source_width > dest_width | |
825 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 2, 2); | |
826 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); | |
827 } | |
828 | |
829 TEST_F(GLCopyTextureCHROMIUMTest, CopySubTextureOffset) { | |
Ken Russell (switch to Gerrit)
2015/01/24 01:33:24
Need another new test for level > 0 if that is sup
dshwang
2015/02/10 18:11:55
I add test for level. the test checks if non-zero
| |
830 uint8 red[1 * 4] = {255u, 0u, 0u, 255u}; | |
831 glBindTexture(GL_TEXTURE_2D, textures_[0]); | |
832 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
833 red); | |
834 | |
835 unsigned int pixel[4] = {0, 0, 0, 0}; | |
Ken Russell (switch to Gerrit)
2015/01/24 01:33:24
It would be more clear to define this as uint8 pix
dshwang
2015/02/10 18:11:55
Done.
| |
836 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
837 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
838 pixel); | |
839 | |
840 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 1, 1); | |
841 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
842 | |
843 // Check the FB is still bound. | |
844 GLint value = 0; | |
845 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value); | |
846 GLuint fb_id = value; | |
847 EXPECT_EQ(framebuffer_id_, fb_id); | |
848 | |
849 // Check that FB is complete. | |
850 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | |
851 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | |
852 | |
853 uint8 transparent[1 * 4] = {0, 0u, 0u, 0}; | |
854 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, transparent); | |
855 GLTestHelper::CheckPixels(1, 1, 1, 1, 0, red); | |
856 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | |
857 } | |
858 | |
632 } // namespace gpu | 859 } // namespace gpu |
OLD | NEW |