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

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

Issue 1275773003: gpu: support GL_TEXTURE_CUBE_MAP destination target to Copy(Sub)TextureCHROMIUM. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handle nvidia Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 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 "base/command_line.h"
14 #include "base/strings/string_number_conversions.h"
13 #include "gpu/command_buffer/tests/gl_manager.h" 15 #include "gpu/command_buffer/tests/gl_manager.h"
14 #include "gpu/command_buffer/tests/gl_test_utils.h" 16 #include "gpu/command_buffer/tests/gl_test_utils.h"
17 #include "gpu/config/gpu_switches.h"
15 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
17 20
18 namespace gpu { 21 namespace gpu {
19 22
20 namespace { 23 namespace {
21 enum CopyType { TexImage, TexSubImage }; 24 enum CopyType { TexImage, TexSubImage };
22 const CopyType kCopyTypes[] = { 25 const CopyType kCopyTypes[] = {
23 TexImage, 26 TexImage,
24 TexSubImage, 27 TexSubImage,
25 }; 28 };
26 } 29
30 const GLenum kDestinationFaces[] = {
31 GL_TEXTURE_2D,
32 GL_TEXTURE_CUBE_MAP_POSITIVE_X,
33 #if !defined(OS_ANDROID)
dshwang 2015/09/02 11:01:19 As kbr was worry, glReadPixels from FBO binding cu
34 // linux_android_rel_ng crashs on glReadPixels()
35 // TODO(dshwang): exclude them for only Nvidia. crbug.com/527126
36 GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
37 GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
38 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
39 GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
40 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
41 #endif
42 };
43 } // namespace
27 44
28 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. 45 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension.
29 class GLCopyTextureCHROMIUMTest 46 class GLCopyTextureCHROMIUMTest
30 : public testing::Test, 47 : public testing::TestWithParam<::testing::tuple<CopyType, GLenum>> {
31 public ::testing::WithParamInterface<CopyType> {
32 protected: 48 protected:
33 void SetUp() override { 49 void SetUp() override {
34 gl_.Initialize(GLManager::Options()); 50 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
51 // ANGLE and Nvidia fails without this workaround. crbug.com/518889
52 command_line.AppendSwitchASCII(switches::kGpuDriverBugWorkarounds,
53 base::IntToString(gpu::FORCE_CUBE_COMPLETE));
dshwang 2015/09/02 11:01:19 Only ANGLE and Nvidia needs this workaround, which
54 gl_.InitializeWithCommandLine(GLManager::Options(), &command_line);
55 DCHECK(gl_.workarounds().force_cube_complete);
35 56
57 // textures_[0] is source texture and textures_[1] is destination texture.
36 glGenTextures(2, textures_); 58 glGenTextures(2, textures_);
37 glBindTexture(GL_TEXTURE_2D, textures_[1]); 59
60 GLenum dest_target = ::testing::get<1>(GetParam());
61 GLenum binding_target =
62 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target);
63
64 glBindTexture(binding_target, textures_[1]);
38 65
39 // Some drivers (NVidia/SGX) require texture settings to be a certain way or 66 // Some drivers (NVidia/SGX) require texture settings to be a certain way or
40 // they won't report FRAMEBUFFER_COMPLETE. 67 // they won't report FRAMEBUFFER_COMPLETE.
41 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 68 glTexParameterf(binding_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
42 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 69 glTexParameterf(binding_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
43 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 70 glTexParameteri(binding_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
44 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 71 glTexParameteri(binding_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
45 72
46 glGenFramebuffers(1, &framebuffer_id_); 73 glGenFramebuffers(1, &framebuffer_id_);
47 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_); 74 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_);
48 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 75 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, dest_target,
49 textures_[1], 0); 76 textures_[1], 0);
77 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
50 } 78 }
51 79
52 void TearDown() override { 80 void TearDown() override {
53 glDeleteTextures(2, textures_); 81 glDeleteTextures(2, textures_);
54 glDeleteFramebuffers(1, &framebuffer_id_); 82 glDeleteFramebuffers(1, &framebuffer_id_);
55 gl_.Destroy(); 83 gl_.Destroy();
56 } 84 }
57 85
86 // Some drivers(Nvidia) require cube complete to do glReadPixels from the FBO.
87 void MakeCubeComplete(GLenum target,
dshwang 2015/09/02 11:01:19 It's for mac, linux, win with Nvidia.
88 GLint internalformat,
89 GLenum type,
90 GLsizei width,
91 GLsizei height) {
92 // Make the textures cube complete to bind it to FBO
93 GLenum binding_target =
94 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(target);
95 if (binding_target == GL_TEXTURE_CUBE_MAP) {
96 glBindTexture(binding_target, textures_[1]);
97 for (unsigned i = 0; i < 6; i++) {
98 if (target == GL_TEXTURE_CUBE_MAP_POSITIVE_X + i)
99 continue;
100 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalformat,
101 width, height, 0, internalformat, type, nullptr);
102 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
103 }
104 }
105 }
106
58 GLManager gl_; 107 GLManager gl_;
59 GLuint textures_[2]; 108 GLuint textures_[2];
60 GLuint framebuffer_id_; 109 GLuint framebuffer_id_;
61 }; 110 };
62 111
63 INSTANTIATE_TEST_CASE_P(CopyType, 112 INSTANTIATE_TEST_CASE_P(
64 GLCopyTextureCHROMIUMTest, 113 GLCopyTextureCHROMIUMTests,
65 ::testing::ValuesIn(kCopyTypes)); 114 GLCopyTextureCHROMIUMTest,
115 ::testing::Combine(::testing::ValuesIn(kCopyTypes),
116 ::testing::ValuesIn(kDestinationFaces)));
66 117
67 // Test to ensure that the basic functionality of the extension works. 118 // Test to ensure that the basic functionality of the extension works.
68 TEST_P(GLCopyTextureCHROMIUMTest, Basic) { 119 TEST_P(GLCopyTextureCHROMIUMTest, Basic) {
69 CopyType copy_type = GetParam(); 120 CopyType copy_type = ::testing::get<0>(GetParam());
121 GLenum dest_target = ::testing::get<1>(GetParam());
122 GLenum binding_target =
123 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target);
70 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; 124 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u };
71 125
72 glBindTexture(GL_TEXTURE_2D, textures_[0]); 126 glBindTexture(GL_TEXTURE_2D, textures_[0]);
73 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 127 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
74 pixels); 128 pixels);
75 129
76 if (copy_type == TexImage) { 130 if (copy_type == TexImage) {
77 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], GL_RGBA, 131 glCopyTextureCHROMIUM(dest_target, textures_[0], textures_[1], GL_RGBA,
78 GL_UNSIGNED_BYTE, false, false, false); 132 GL_UNSIGNED_BYTE, false, false, false);
79 } else { 133 } else {
80 glBindTexture(GL_TEXTURE_2D, textures_[1]); 134 glBindTexture(binding_target, textures_[1]);
81 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 135 glTexImage2D(dest_target, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
82 nullptr); 136 nullptr);
83 137
84 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, 0, 138 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], 0, 0, 0,
85 0, 1, 1, false, false, false); 139 0, 1, 1, false, false, false);
86 } 140 }
87 EXPECT_TRUE(glGetError() == GL_NO_ERROR); 141 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
88 142
143 MakeCubeComplete(dest_target, GL_RGBA, GL_UNSIGNED_BYTE, 1, 1);
144
89 // Check the FB is still bound. 145 // Check the FB is still bound.
90 GLint value = 0; 146 GLint value = 0;
91 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value); 147 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value);
92 GLuint fb_id = value; 148 GLuint fb_id = value;
93 EXPECT_EQ(framebuffer_id_, fb_id); 149 EXPECT_EQ(framebuffer_id_, fb_id);
94 150
95 // Check that FB is complete. 151 // Check that FB is complete.
96 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), 152 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
97 glCheckFramebufferStatus(GL_FRAMEBUFFER)); 153 glCheckFramebufferStatus(GL_FRAMEBUFFER));
98 154
99 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); 155 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels);
100 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 156 EXPECT_TRUE(GL_NO_ERROR == glGetError());
101 } 157 }
102 158
103 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { 159 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) {
104 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { 160 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) {
105 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; 161 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test...";
106 return; 162 return;
107 } 163 }
108 CopyType copy_type = GetParam(); 164
165 CopyType copy_type = ::testing::get<0>(GetParam());
166 GLenum dest_target = ::testing::get<1>(GetParam());
167 GLenum binding_target =
168 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target);
109 169
110 uint8 pixels[1 * 4] = {255u, 0u, 0u, 255u}; 170 uint8 pixels[1 * 4] = {255u, 0u, 0u, 255u};
111 171
112 glBindTexture(GL_TEXTURE_2D, textures_[0]); 172 glBindTexture(GL_TEXTURE_2D, textures_[0]);
113 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 1, 1); 173 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, 174 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
115 pixels); 175 pixels);
116 176
117 glBindTexture(GL_TEXTURE_2D, textures_[1]); 177 glBindTexture(binding_target, textures_[1]);
118 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 1, 1); 178 glTexStorage2DEXT(binding_target, 1, GL_RGBA8_OES, 1, 1);
119 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 179 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, dest_target,
120 textures_[1], 0); 180 textures_[1], 0);
121 EXPECT_TRUE(glGetError() == GL_NO_ERROR); 181 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
122 182
123 if (copy_type == TexImage) { 183 if (copy_type == TexImage) {
124 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], GL_RGBA, 184 glCopyTextureCHROMIUM(dest_target, textures_[0], textures_[1], GL_RGBA,
125 GL_UNSIGNED_BYTE, false, false, false); 185 GL_UNSIGNED_BYTE, false, false, false);
126 EXPECT_TRUE(glGetError() == GL_INVALID_OPERATION); 186 EXPECT_TRUE(glGetError() == GL_INVALID_OPERATION);
127 } else { 187 } else {
128 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, 0, 188 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], 0, 0, 0,
129 0, 1, 1, false, false, false); 189 0, 1, 1, false, false, false);
130 EXPECT_TRUE(glGetError() == GL_NO_ERROR); 190 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
131 191
192 // Similar quirk to MakeCubeComplete() for immutable texture.
193 if (binding_target == GL_TEXTURE_CUBE_MAP) {
194 for (unsigned i = 0; i < 6; i++) {
195 if (dest_target == GL_TEXTURE_CUBE_MAP_POSITIVE_X + i)
196 continue;
197 glCopySubTextureCHROMIUM(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
198 textures_[0], textures_[1], 0, 0, 0, 0, 1, 1,
199 false, false, false);
200 }
201 }
202 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
203
132 // Check the FB is still bound. 204 // Check the FB is still bound.
133 GLint value = 0; 205 GLint value = 0;
134 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value); 206 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value);
135 GLuint fb_id = value; 207 GLuint fb_id = value;
136 EXPECT_EQ(framebuffer_id_, fb_id); 208 EXPECT_EQ(framebuffer_id_, fb_id);
137 209
138 // Check that FB is complete. 210 // Check that FB is complete.
139 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), 211 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
140 glCheckFramebufferStatus(GL_FRAMEBUFFER)); 212 glCheckFramebufferStatus(GL_FRAMEBUFFER));
141 213
142 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); 214 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels);
143 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 215 EXPECT_TRUE(GL_NO_ERROR == glGetError());
144 } 216 }
145 } 217 }
146 218
147 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormat) { 219 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormat) {
148 CopyType copy_type = GetParam(); 220 CopyType copy_type = ::testing::get<0>(GetParam());
221 GLenum dest_target = ::testing::get<1>(GetParam());
222 GLenum binding_target =
223 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target);
224
149 GLint src_formats[] = {GL_ALPHA, GL_RGB, GL_RGBA, 225 GLint src_formats[] = {GL_ALPHA, GL_RGB, GL_RGBA,
150 GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGRA_EXT}; 226 GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGRA_EXT};
151 GLint dest_formats[] = {GL_RGB, GL_RGBA}; 227 GLint dest_formats[] = {GL_RGB, GL_RGBA};
152 228
153 for (size_t src_index = 0; src_index < arraysize(src_formats); src_index++) { 229 for (size_t src_index = 0; src_index < arraysize(src_formats); src_index++) {
154 for (size_t dest_index = 0; dest_index < arraysize(dest_formats); 230 for (size_t dest_index = 0; dest_index < arraysize(dest_formats);
155 dest_index++) { 231 dest_index++) {
156 glBindTexture(GL_TEXTURE_2D, textures_[0]); 232 glBindTexture(GL_TEXTURE_2D, textures_[0]);
157 glTexImage2D(GL_TEXTURE_2D, 0, src_formats[src_index], 1, 1, 0, 233 glTexImage2D(GL_TEXTURE_2D, 0, src_formats[src_index], 1, 1, 0,
158 src_formats[src_index], GL_UNSIGNED_BYTE, nullptr); 234 src_formats[src_index], GL_UNSIGNED_BYTE, nullptr);
159 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 235 EXPECT_TRUE(GL_NO_ERROR == glGetError());
160 236
161 if (copy_type == TexImage) { 237 if (copy_type == TexImage) {
162 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 238 glCopyTextureCHROMIUM(dest_target, textures_[0], textures_[1],
163 dest_formats[dest_index], GL_UNSIGNED_BYTE, 239 dest_formats[dest_index], GL_UNSIGNED_BYTE, false,
164 false, false, false); 240 false, false);
165 } else { 241 } else {
166 glBindTexture(GL_TEXTURE_2D, textures_[1]); 242 glBindTexture(binding_target, textures_[1]);
167 glTexImage2D(GL_TEXTURE_2D, 0, dest_formats[dest_index], 1, 1, 0, 243 glTexImage2D(dest_target, 0, dest_formats[dest_index], 1, 1, 0,
168 dest_formats[dest_index], GL_UNSIGNED_BYTE, nullptr); 244 dest_formats[dest_index], GL_UNSIGNED_BYTE, nullptr);
169 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 245 EXPECT_TRUE(GL_NO_ERROR == glGetError());
170 246
171 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 247 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], 0, 0,
172 0, 0, 0, 1, 1, false, false, false); 248 0, 0, 1, 1, false, false, false);
173 } 249 }
174 250 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError())
175 EXPECT_TRUE(GL_NO_ERROR == glGetError()) << "src_index:" << src_index 251 << "src_index:" << src_index << " dest_index:" << dest_index;
176 << " dest_index:" << dest_index;
177 } 252 }
178 } 253 }
179 } 254 }
180 255
181 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) { 256 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) {
182 CopyType copy_type = GetParam(); 257 CopyType copy_type = ::testing::get<0>(GetParam());
258 GLenum dest_target = ::testing::get<1>(GetParam());
259 GLenum binding_target =
260 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target);
183 glBindTexture(GL_TEXTURE_2D, textures_[0]); 261 glBindTexture(GL_TEXTURE_2D, textures_[0]);
184 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 262 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
185 nullptr); 263 nullptr);
186 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 264 EXPECT_TRUE(GL_NO_ERROR == glGetError());
187 265
188 // Check unsupported format reports error. 266 // Check unsupported format reports error.
189 GLint unsupported_dest_formats[] = {GL_ALPHA, GL_LUMINANCE, 267 GLint unsupported_dest_formats[] = {GL_ALPHA, GL_LUMINANCE,
190 GL_LUMINANCE_ALPHA}; 268 GL_LUMINANCE_ALPHA};
191 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats); 269 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats);
192 dest_index++) { 270 dest_index++) {
193 if (copy_type == TexImage) { 271 if (copy_type == TexImage) {
194 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 272 glCopyTextureCHROMIUM(dest_target, textures_[0], textures_[1],
195 unsupported_dest_formats[dest_index], 273 unsupported_dest_formats[dest_index],
196 GL_UNSIGNED_BYTE, false, false, false); 274 GL_UNSIGNED_BYTE, false, false, false);
197 } else { 275 } else {
198 glBindTexture(GL_TEXTURE_2D, textures_[1]); 276 glBindTexture(binding_target, textures_[1]);
199 glTexImage2D(GL_TEXTURE_2D, 0, unsupported_dest_formats[dest_index], 1, 1, 277 glTexImage2D(dest_target, 0, unsupported_dest_formats[dest_index], 1, 1,
200 0, unsupported_dest_formats[dest_index], GL_UNSIGNED_BYTE, 278 0, unsupported_dest_formats[dest_index], GL_UNSIGNED_BYTE,
201 nullptr); 279 nullptr);
202 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, 280 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], 0, 0, 0,
203 0, 0, 1, 1, false, false, false); 281 0, 1, 1, false, false, false);
204 } 282 }
205 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()) 283 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError())
206 << "dest_index:" << dest_index; 284 << "dest_index:" << dest_index;
207 } 285 }
208 } 286 }
209 287
210 // Test to ensure that the destination texture is redefined if the properties 288 // Test to ensure that the destination texture is redefined if the properties
211 // are different. 289 // are different.
212 TEST_F(GLCopyTextureCHROMIUMTest, RedefineDestinationTexture) { 290 TEST_P(GLCopyTextureCHROMIUMTest, RedefineDestinationTexture) {
291 GLenum dest_target = ::testing::get<1>(GetParam());
292 GLenum binding_target =
293 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target);
213 uint8 pixels[4 * 4] = {255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u, 294 uint8 pixels[4 * 4] = {255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u,
214 255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u}; 295 255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u};
215 296
216 glBindTexture(GL_TEXTURE_2D, textures_[0]); 297 glBindTexture(GL_TEXTURE_2D, textures_[0]);
217 glTexImage2D( 298 glTexImage2D(
218 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 299 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
219 300
220 glBindTexture(GL_TEXTURE_2D, textures_[1]); 301 glBindTexture(binding_target, textures_[1]);
221 glTexImage2D(GL_TEXTURE_2D, 302 glTexImage2D(dest_target, 0, GL_BGRA_EXT, 1, 1, 0, GL_BGRA_EXT,
222 0, 303 GL_UNSIGNED_BYTE, pixels);
223 GL_BGRA_EXT,
224 1,
225 1,
226 0,
227 GL_BGRA_EXT,
228 GL_UNSIGNED_BYTE,
229 pixels);
230 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 304 EXPECT_TRUE(GL_NO_ERROR == glGetError());
231 305
232 // GL_INVALID_OPERATION due to "intrinsic format" != "internal format". 306 // GL_INVALID_OPERATION due to "intrinsic format" != "internal format".
233 glTexSubImage2D( 307 glTexSubImage2D(dest_target, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
234 GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 308 pixels);
235 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()); 309 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError());
236 // GL_INVALID_VALUE due to bad dimensions. 310 // GL_INVALID_VALUE due to bad dimensions.
237 glTexSubImage2D( 311 glTexSubImage2D(dest_target, 0, 1, 1, 1, 1, GL_BGRA_EXT, GL_UNSIGNED_BYTE,
238 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels); 312 pixels);
239 EXPECT_TRUE(GL_INVALID_VALUE == glGetError()); 313 EXPECT_TRUE(GL_INVALID_VALUE == glGetError());
240 314
241 // If the dest texture has different properties, glCopyTextureCHROMIUM() 315 // If the dest texture has different properties, glCopyTextureCHROMIUM()
242 // redefines them. 316 // redefines them.
243 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], GL_RGBA, 317 glCopyTextureCHROMIUM(dest_target, textures_[0], textures_[1], GL_RGBA,
244 GL_UNSIGNED_BYTE, false, false, false); 318 GL_UNSIGNED_BYTE, false, false, false);
245 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 319 EXPECT_TRUE(GL_NO_ERROR == glGetError());
246 320
247 // glTexSubImage2D() succeeds because textures_[1] is redefined into 2x2 321 // glTexSubImage2D() succeeds because textures_[1] is redefined into 2x2
248 // dimension and GL_RGBA format. 322 // dimension and GL_RGBA format.
249 glBindTexture(GL_TEXTURE_2D, textures_[1]); 323 glBindTexture(binding_target, textures_[1]);
250 glTexSubImage2D( 324 glTexSubImage2D(dest_target, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
251 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 325 pixels);
252 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 326 EXPECT_TRUE(GL_NO_ERROR == glGetError());
253 327
328 MakeCubeComplete(dest_target, GL_RGBA, GL_UNSIGNED_BYTE, 2, 2);
329
254 // Check the FB is still bound. 330 // Check the FB is still bound.
255 GLint value = 0; 331 GLint value = 0;
256 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value); 332 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value);
257 GLuint fb_id = value; 333 GLuint fb_id = value;
258 EXPECT_EQ(framebuffer_id_, fb_id); 334 EXPECT_EQ(framebuffer_id_, fb_id);
259 335
260 // Check that FB is complete. 336 // Check that FB is complete.
261 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), 337 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
262 glCheckFramebufferStatus(GL_FRAMEBUFFER)); 338 glCheckFramebufferStatus(GL_FRAMEBUFFER));
263 339
340 #if defined(OS_MACOSX) || defined(OS_WIN)
341 // Despite of "MakeCubeComplete()" quirk, glReadPixels still fails on
342 // mac_chromium_rel_ng and win_chromium_rel_ng.
343 // TODO(dshwang): exclude it for only Nvidia. crbug.com/527126
344 GLsizei size = 2 * 2 * 4;
345 scoped_ptr<uint8[]> read_pixels(new uint8[size]);
346 glReadPixels(0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, read_pixels.get());
347 #else
264 GLTestHelper::CheckPixels(1, 1, 1, 1, 0, &pixels[12]); 348 GLTestHelper::CheckPixels(1, 1, 1, 1, 0, &pixels[12]);
349 #endif
265 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 350 EXPECT_TRUE(GL_NO_ERROR == glGetError());
266 } 351 }
267 352
268 namespace { 353 namespace {
269 354
270 void glEnableDisable(GLint param, GLboolean value) { 355 void glEnableDisable(GLint param, GLboolean value) {
271 if (value) 356 if (value)
272 glEnable(param); 357 glEnable(param);
273 else 358 else
274 glDisable(param); 359 glDisable(param);
275 } 360 }
276 361
277 } // unnamed namespace 362 } // unnamed namespace
278 363
279 // Validate that some basic GL state is not touched upon execution of 364 // Validate that some basic GL state is not touched upon execution of
280 // the extension. 365 // the extension.
281 TEST_P(GLCopyTextureCHROMIUMTest, BasicStatePreservation) { 366 TEST_P(GLCopyTextureCHROMIUMTest, BasicStatePreservation) {
282 CopyType copy_type = GetParam(); 367 CopyType copy_type = ::testing::get<0>(GetParam());
368 GLenum dest_target = ::testing::get<1>(GetParam());
369 GLenum binding_target =
370 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target);
283 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; 371 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u };
284 372
285 glBindFramebuffer(GL_FRAMEBUFFER, 0); 373 glBindFramebuffer(GL_FRAMEBUFFER, 0);
286 374
287 glBindTexture(GL_TEXTURE_2D, textures_[0]); 375 glBindTexture(GL_TEXTURE_2D, textures_[0]);
288 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 376 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
289 pixels); 377 pixels);
290 378
291 if (copy_type == TexSubImage) { 379 if (copy_type == TexSubImage) {
292 glBindTexture(GL_TEXTURE_2D, textures_[1]); 380 glBindTexture(binding_target, textures_[1]);
293 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 381 glTexImage2D(dest_target, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
294 nullptr); 382 nullptr);
295 } 383 }
296 384
297 GLboolean reference_settings[2] = { GL_TRUE, GL_FALSE }; 385 GLboolean reference_settings[2] = { GL_TRUE, GL_FALSE };
298 for (int x = 0; x < 2; ++x) { 386 for (int x = 0; x < 2; ++x) {
299 GLboolean setting = reference_settings[x]; 387 GLboolean setting = reference_settings[x];
300 glEnableDisable(GL_DEPTH_TEST, setting); 388 glEnableDisable(GL_DEPTH_TEST, setting);
301 glEnableDisable(GL_SCISSOR_TEST, setting); 389 glEnableDisable(GL_SCISSOR_TEST, setting);
302 glEnableDisable(GL_STENCIL_TEST, setting); 390 glEnableDisable(GL_STENCIL_TEST, setting);
303 glEnableDisable(GL_CULL_FACE, setting); 391 glEnableDisable(GL_CULL_FACE, setting);
304 glEnableDisable(GL_BLEND, setting); 392 glEnableDisable(GL_BLEND, setting);
305 glColorMask(setting, setting, setting, setting); 393 glColorMask(setting, setting, setting, setting);
306 glDepthMask(setting); 394 glDepthMask(setting);
307 395
308 glActiveTexture(GL_TEXTURE1 + x); 396 glActiveTexture(GL_TEXTURE1 + x);
309 397
310 if (copy_type == TexImage) { 398 if (copy_type == TexImage) {
311 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], GL_RGBA, 399 glCopyTextureCHROMIUM(dest_target, textures_[0], textures_[1], GL_RGBA,
312 GL_UNSIGNED_BYTE, false, false, false); 400 GL_UNSIGNED_BYTE, false, false, false);
313 } else { 401 } else {
314 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, 402 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], 0, 0, 0,
315 0, 0, 1, 1, false, false, false); 403 0, 1, 1, false, false, false);
316 } 404 }
317 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 405 EXPECT_TRUE(GL_NO_ERROR == glGetError());
318 406
319 EXPECT_EQ(setting, glIsEnabled(GL_DEPTH_TEST)); 407 EXPECT_EQ(setting, glIsEnabled(GL_DEPTH_TEST));
320 EXPECT_EQ(setting, glIsEnabled(GL_SCISSOR_TEST)); 408 EXPECT_EQ(setting, glIsEnabled(GL_SCISSOR_TEST));
321 EXPECT_EQ(setting, glIsEnabled(GL_STENCIL_TEST)); 409 EXPECT_EQ(setting, glIsEnabled(GL_STENCIL_TEST));
322 EXPECT_EQ(setting, glIsEnabled(GL_CULL_FACE)); 410 EXPECT_EQ(setting, glIsEnabled(GL_CULL_FACE));
323 EXPECT_EQ(setting, glIsEnabled(GL_BLEND)); 411 EXPECT_EQ(setting, glIsEnabled(GL_BLEND));
324 412
325 GLboolean bool_array[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE }; 413 GLboolean bool_array[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE };
(...skipping 11 matching lines...) Expand all
337 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); 425 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
338 EXPECT_EQ(GL_TEXTURE1 + x, active_texture); 426 EXPECT_EQ(GL_TEXTURE1 + x, active_texture);
339 } 427 }
340 428
341 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 429 EXPECT_TRUE(GL_NO_ERROR == glGetError());
342 }; 430 };
343 431
344 // Verify that invocation of the extension does not modify the bound 432 // Verify that invocation of the extension does not modify the bound
345 // texture state. 433 // texture state.
346 TEST_P(GLCopyTextureCHROMIUMTest, TextureStatePreserved) { 434 TEST_P(GLCopyTextureCHROMIUMTest, TextureStatePreserved) {
347 CopyType copy_type = GetParam(); 435 CopyType copy_type = ::testing::get<0>(GetParam());
436 GLenum dest_target = ::testing::get<1>(GetParam());
437 GLenum binding_target =
438 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target);
439 GLenum get_binding_target = binding_target == GL_TEXTURE_2D
440 ? GL_TEXTURE_BINDING_2D
441 : GL_TEXTURE_BINDING_CUBE_MAP;
348 // Setup the texture used for the extension invocation. 442 // Setup the texture used for the extension invocation.
349 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; 443 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u };
350 glBindTexture(GL_TEXTURE_2D, textures_[0]); 444 glBindTexture(GL_TEXTURE_2D, textures_[0]);
351 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 445 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
352 pixels); 446 pixels);
353 447
354 if (copy_type == TexSubImage) { 448 if (copy_type == TexSubImage) {
355 glBindTexture(GL_TEXTURE_2D, textures_[1]); 449 glBindTexture(binding_target, textures_[1]);
356 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 450 glTexImage2D(dest_target, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
357 nullptr); 451 nullptr);
358 } 452 }
359 453
360 GLuint texture_ids[2]; 454 GLuint texture_ids[2];
361 glGenTextures(2, texture_ids); 455 glGenTextures(2, texture_ids);
362 456
363 glActiveTexture(GL_TEXTURE0); 457 glActiveTexture(GL_TEXTURE0);
364 glBindTexture(GL_TEXTURE_2D, texture_ids[0]); 458 glBindTexture(GL_TEXTURE_2D, texture_ids[0]);
365 459
366 glActiveTexture(GL_TEXTURE1); 460 glActiveTexture(GL_TEXTURE1);
367 glBindTexture(GL_TEXTURE_2D, texture_ids[1]); 461 glBindTexture(binding_target, texture_ids[1]);
368 462
369 if (copy_type == TexImage) { 463 if (copy_type == TexImage) {
370 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], GL_RGBA, 464 glCopyTextureCHROMIUM(dest_target, textures_[0], textures_[1], GL_RGBA,
371 GL_UNSIGNED_BYTE, false, false, false); 465 GL_UNSIGNED_BYTE, false, false, false);
372 } else { 466 } else {
373 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, 0, 467 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], 0, 0, 0,
374 0, 1, 1, false, false, false); 468 0, 1, 1, false, false, false);
375 } 469 }
376 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 470 EXPECT_TRUE(GL_NO_ERROR == glGetError());
377 471
378 GLint active_texture = 0; 472 GLint active_texture = 0;
379 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); 473 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
380 EXPECT_EQ(GL_TEXTURE1, active_texture); 474 EXPECT_EQ(GL_TEXTURE1, active_texture);
381 475
382 GLint bound_texture = 0; 476 GLint bound_texture = 0;
383 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); 477 glGetIntegerv(get_binding_target, &bound_texture);
384 EXPECT_EQ(texture_ids[1], static_cast<GLuint>(bound_texture)); 478 EXPECT_EQ(texture_ids[1], static_cast<GLuint>(bound_texture));
385 glBindTexture(GL_TEXTURE_2D, 0); 479 glBindTexture(binding_target, 0);
386 480
387 bound_texture = 0; 481 bound_texture = 0;
388 glActiveTexture(GL_TEXTURE0); 482 glActiveTexture(GL_TEXTURE0);
389 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); 483 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture);
390 EXPECT_EQ(texture_ids[0], static_cast<GLuint>(bound_texture)); 484 EXPECT_EQ(texture_ids[0], static_cast<GLuint>(bound_texture));
391 glBindTexture(GL_TEXTURE_2D, 0); 485 glBindTexture(GL_TEXTURE_2D, 0);
392 486
393 glDeleteTextures(2, texture_ids); 487 glDeleteTextures(2, texture_ids);
394 488
395 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 489 EXPECT_TRUE(GL_NO_ERROR == glGetError());
396 } 490 }
397 491
398 // Verify that invocation of the extension does not perturb the currently 492 // Verify that invocation of the extension does not perturb the currently
399 // bound FBO state. 493 // bound FBO state.
400 TEST_P(GLCopyTextureCHROMIUMTest, FBOStatePreserved) { 494 TEST_P(GLCopyTextureCHROMIUMTest, FBOStatePreserved) {
401 CopyType copy_type = GetParam(); 495 CopyType copy_type = ::testing::get<0>(GetParam());
496 GLenum dest_target = ::testing::get<1>(GetParam());
497 GLenum binding_target =
498 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target);
402 // Setup the texture used for the extension invocation. 499 // Setup the texture used for the extension invocation.
403 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; 500 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u };
404 glBindTexture(GL_TEXTURE_2D, textures_[0]); 501 glBindTexture(GL_TEXTURE_2D, textures_[0]);
405 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 502 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
406 pixels); 503 pixels);
407 504
408 if (copy_type == TexSubImage) { 505 if (copy_type == TexSubImage) {
409 glBindTexture(GL_TEXTURE_2D, textures_[1]); 506 glBindTexture(binding_target, textures_[1]);
410 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 507 glTexImage2D(dest_target, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
411 nullptr); 508 nullptr);
412 } 509 }
413 510
414 GLuint texture_id; 511 GLuint texture_id;
415 glGenTextures(1, &texture_id); 512 glGenTextures(1, &texture_id);
416 glBindTexture(GL_TEXTURE_2D, texture_id); 513 glBindTexture(GL_TEXTURE_2D, texture_id);
417 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 514 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
418 0); 515 0);
419 516
420 GLuint renderbuffer_id; 517 GLuint renderbuffer_id;
(...skipping 11 matching lines...) Expand all
432 EXPECT_TRUE( 529 EXPECT_TRUE(
433 GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER)); 530 GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER));
434 531
435 // Test that we can write to the bound framebuffer 532 // Test that we can write to the bound framebuffer
436 uint8 expected_color[4] = { 255u, 255u, 0, 255u }; 533 uint8 expected_color[4] = { 255u, 255u, 0, 255u };
437 glClearColor(1.0, 1.0, 0, 1.0); 534 glClearColor(1.0, 1.0, 0, 1.0);
438 glClear(GL_COLOR_BUFFER_BIT); 535 glClear(GL_COLOR_BUFFER_BIT);
439 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color); 536 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color);
440 537
441 if (copy_type == TexImage) { 538 if (copy_type == TexImage) {
442 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], GL_RGBA, 539 glCopyTextureCHROMIUM(dest_target, textures_[0], textures_[1], GL_RGBA,
443 GL_UNSIGNED_BYTE, false, false, false); 540 GL_UNSIGNED_BYTE, false, false, false);
444 } else { 541 } else {
445 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, 0, 542 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], 0, 0, 0,
446 0, 1, 1, false, false, false); 543 0, 1, 1, false, false, false);
447 } 544 }
448 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 545 EXPECT_TRUE(GL_NO_ERROR == glGetError());
449 546
547 MakeCubeComplete(dest_target, GL_RGBA, GL_UNSIGNED_BYTE, 1, 1);
548
450 EXPECT_TRUE(glIsFramebuffer(framebuffer_id)); 549 EXPECT_TRUE(glIsFramebuffer(framebuffer_id));
451 550
452 // Ensure that reading from the framebuffer produces correct pixels. 551 // Ensure that reading from the framebuffer produces correct pixels.
453 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color); 552 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color);
454 553
455 uint8 expected_color2[4] = { 255u, 0, 255u, 255u }; 554 uint8 expected_color2[4] = { 255u, 0, 255u, 255u };
456 glClearColor(1.0, 0, 1.0, 1.0); 555 glClearColor(1.0, 0, 1.0, 1.0);
457 glClear(GL_COLOR_BUFFER_BIT); 556 glClear(GL_COLOR_BUFFER_BIT);
458 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color2); 557 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color2);
459 558
(...skipping 26 matching lines...) Expand all
486 EXPECT_EQ(renderbuffer_id, static_cast<GLuint>(fbo_params)); 585 EXPECT_EQ(renderbuffer_id, static_cast<GLuint>(fbo_params));
487 586
488 glDeleteRenderbuffers(1, &renderbuffer_id); 587 glDeleteRenderbuffers(1, &renderbuffer_id);
489 glDeleteTextures(1, &texture_id); 588 glDeleteTextures(1, &texture_id);
490 glDeleteFramebuffers(1, &framebuffer_id); 589 glDeleteFramebuffers(1, &framebuffer_id);
491 590
492 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 591 EXPECT_TRUE(GL_NO_ERROR == glGetError());
493 } 592 }
494 593
495 TEST_P(GLCopyTextureCHROMIUMTest, ProgramStatePreservation) { 594 TEST_P(GLCopyTextureCHROMIUMTest, ProgramStatePreservation) {
496 CopyType copy_type = GetParam(); 595 CopyType copy_type = ::testing::get<0>(GetParam());
596 GLenum dest_target = ::testing::get<1>(GetParam());
597 GLenum binding_target =
598 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target);
497 // unbind the one created in setup. 599 // unbind the one created in setup.
498 glBindFramebuffer(GL_FRAMEBUFFER, 0); 600 glBindFramebuffer(GL_FRAMEBUFFER, 0);
499 glBindTexture(GL_TEXTURE_2D, 0); 601 glBindTexture(GL_TEXTURE_2D, 0);
500 602
501 GLManager gl2; 603 GLManager gl2;
502 GLManager::Options options; 604 GLManager::Options options;
503 options.size = gfx::Size(16, 16); 605 options.size = gfx::Size(16, 16);
504 options.share_group_manager = &gl_; 606 options.share_group_manager = &gl_;
505 gl2.Initialize(options); 607 gl2.Initialize(options);
506 gl_.MakeCurrent(); 608 gl_.MakeCurrent();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, zero)); 643 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, zero));
542 glDrawArrays(GL_TRIANGLES, 0, 6); 644 glDrawArrays(GL_TRIANGLES, 0, 6);
543 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected)); 645 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected));
544 646
545 // Call copyTextureCHROMIUM 647 // Call copyTextureCHROMIUM
546 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; 648 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u };
547 glBindTexture(GL_TEXTURE_2D, textures_[0]); 649 glBindTexture(GL_TEXTURE_2D, textures_[0]);
548 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 650 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
549 pixels); 651 pixels);
550 if (copy_type == TexImage) { 652 if (copy_type == TexImage) {
551 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], GL_RGBA, 653 glCopyTextureCHROMIUM(dest_target, textures_[0], textures_[1], GL_RGBA,
552 GL_UNSIGNED_BYTE, false, false, false); 654 GL_UNSIGNED_BYTE, false, false, false);
553 } else { 655 } else {
554 glBindTexture(GL_TEXTURE_2D, textures_[1]); 656 glBindTexture(binding_target, textures_[1]);
555 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 657 glTexImage2D(dest_target, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
556 nullptr); 658 nullptr);
557 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, 0, 659 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], 0, 0, 0,
558 0, 1, 1, false, false, false); 660 0, 1, 1, false, false, false);
559 } 661 }
560 662
663 MakeCubeComplete(dest_target, GL_RGBA, GL_UNSIGNED_BYTE, 1, 1);
664
561 // test using program after 665 // test using program after
562 glClear(GL_COLOR_BUFFER_BIT); 666 glClear(GL_COLOR_BUFFER_BIT);
563 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, zero)); 667 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, zero));
564 glDrawArrays(GL_TRIANGLES, 0, 6); 668 glDrawArrays(GL_TRIANGLES, 0, 6);
565 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected)); 669 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected));
566 670
567 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 671 EXPECT_TRUE(GL_NO_ERROR == glGetError());
568 672
569 gl2.MakeCurrent(); 673 gl2.MakeCurrent();
570 gl2.Destroy(); 674 gl2.Destroy();
571 gl_.MakeCurrent(); 675 gl_.MakeCurrent();
572 } 676 }
573 677
574 // Test that glCopyTextureCHROMIUM doesn't leak uninitialized textures. 678 // Test that glCopyTextureCHROMIUM doesn't leak uninitialized textures.
575 TEST_P(GLCopyTextureCHROMIUMTest, UninitializedSource) { 679 TEST_P(GLCopyTextureCHROMIUMTest, UninitializedSource) {
576 CopyType copy_type = GetParam(); 680 CopyType copy_type = ::testing::get<0>(GetParam());
681 GLenum dest_target = ::testing::get<1>(GetParam());
682 GLenum binding_target =
683 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target);
577 const GLsizei kWidth = 64, kHeight = 64; 684 const GLsizei kWidth = 64, kHeight = 64;
578 glBindTexture(GL_TEXTURE_2D, textures_[0]); 685 glBindTexture(GL_TEXTURE_2D, textures_[0]);
579 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, 0, GL_RGBA, 686 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, 0, GL_RGBA,
580 GL_UNSIGNED_BYTE, nullptr); 687 GL_UNSIGNED_BYTE, nullptr);
581 688
582 if (copy_type == TexImage) { 689 if (copy_type == TexImage) {
583 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], GL_RGBA, 690 glCopyTextureCHROMIUM(dest_target, textures_[0], textures_[1], GL_RGBA,
584 GL_UNSIGNED_BYTE, false, false, false); 691 GL_UNSIGNED_BYTE, false, false, false);
585 } else { 692 } else {
586 glBindTexture(GL_TEXTURE_2D, textures_[1]); 693 glBindTexture(binding_target, textures_[1]);
587 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, 0, GL_RGBA, 694 glTexImage2D(dest_target, 0, GL_RGBA, kWidth, kHeight, 0, GL_RGBA,
588 GL_UNSIGNED_BYTE, nullptr); 695 GL_UNSIGNED_BYTE, nullptr);
589 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, 0, 696 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], 0, 0, 0,
590 0, kWidth, kHeight, false, false, false); 697 0, kWidth, kHeight, false, false, false);
591 } 698 }
592 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 699 EXPECT_TRUE(GL_NO_ERROR == glGetError());
593 700
701 MakeCubeComplete(dest_target, GL_RGBA, GL_UNSIGNED_BYTE, kWidth, kHeight);
702
594 uint8 pixels[kHeight][kWidth][4] = {{{1}}}; 703 uint8 pixels[kHeight][kWidth][4] = {{{1}}};
595 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 704 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
596 for (int x = 0; x < kWidth; ++x) { 705 for (int x = 0; x < kWidth; ++x) {
597 for (int y = 0; y < kHeight; ++y) { 706 for (int y = 0; y < kHeight; ++y) {
598 EXPECT_EQ(0, pixels[y][x][0]); 707 EXPECT_EQ(0, pixels[y][x][0]);
599 EXPECT_EQ(0, pixels[y][x][1]); 708 EXPECT_EQ(0, pixels[y][x][1]);
600 EXPECT_EQ(0, pixels[y][x][2]); 709 EXPECT_EQ(0, pixels[y][x][2]);
601 EXPECT_EQ(0, pixels[y][x][3]); 710 EXPECT_EQ(0, pixels[y][x][3]);
602 } 711 }
603 } 712 }
604 713
605 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 714 EXPECT_TRUE(GL_NO_ERROR == glGetError());
606 } 715 }
607 716
608 TEST_F(GLCopyTextureCHROMIUMTest, CopySubTextureDimension) { 717 TEST_P(GLCopyTextureCHROMIUMTest, CopySubTextureDimension) {
718 GLenum dest_target = ::testing::get<1>(GetParam());
719 GLenum binding_target =
720 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target);
609 glBindTexture(GL_TEXTURE_2D, textures_[0]); 721 glBindTexture(GL_TEXTURE_2D, textures_[0]);
610 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 722 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
611 nullptr); 723 nullptr);
612 724
613 glBindTexture(GL_TEXTURE_2D, textures_[1]); 725 glBindTexture(binding_target, textures_[1]);
614 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, 726 glTexImage2D(dest_target, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE,
615 nullptr); 727 nullptr);
616 728
617 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 1, 1, 0, 729 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], 1, 1, 0, 0,
618 0, 1, 1, false, false, false); 730 1, 1, false, false, false);
619 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 731 EXPECT_TRUE(GL_NO_ERROR == glGetError());
620 732
621 // xoffset < 0 733 // xoffset < 0
622 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], -1, 1, 0, 734 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], -1, 1, 0, 0,
623 0, 1, 1, false, false, false); 735 1, 1, false, false, false);
624 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); 736 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE);
625 737
626 // x < 0 738 // x < 0
627 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 1, 1, -1, 739 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], 1, 1, -1, 0,
628 0, 1, 1, false, false, false); 740 1, 1, false, false, false);
629 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); 741 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE);
630 742
631 // xoffset + width > dest_width 743 // xoffset + width > dest_width
632 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 2, 2, 0, 744 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], 2, 2, 0, 0,
633 0, 2, 2, false, false, false); 745 2, 2, false, false, false);
634 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); 746 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE);
635 747
636 // x + width > source_width 748 // x + width > source_width
637 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 0, 1, 749 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], 0, 0, 1, 1,
638 1, 2, 2, false, false, false); 750 2, 2, false, false, false);
639 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); 751 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE);
640 } 752 }
641 753
642 TEST_F(GLCopyTextureCHROMIUMTest, CopySubTextureOffset) { 754 TEST_P(GLCopyTextureCHROMIUMTest, CopySubTextureOffset) {
755 GLenum dest_target = ::testing::get<1>(GetParam());
756 GLenum binding_target =
757 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target);
643 uint8 rgba_pixels[4 * 4] = {255u, 758 uint8 rgba_pixels[4 * 4] = {255u,
644 0u, 759 0u,
645 0u, 760 0u,
646 255u, 761 255u,
647 0u, 762 0u,
648 255u, 763 255u,
649 0u, 764 0u,
650 255u, 765 255u,
651 0u, 766 0u,
652 0u, 767 0u,
653 255u, 768 255u,
654 255u, 769 255u,
655 0u, 770 0u,
656 0u, 771 0u,
657 0u, 772 0u,
658 255u}; 773 255u};
659 glBindTexture(GL_TEXTURE_2D, textures_[0]); 774 glBindTexture(GL_TEXTURE_2D, textures_[0]);
660 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 775 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
661 rgba_pixels); 776 rgba_pixels);
662 777
663 uint8 transparent_pixels[4 * 4] = { 778 uint8 transparent_pixels[4 * 4] = {
664 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u}; 779 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u};
665 glBindTexture(GL_TEXTURE_2D, textures_[1]); 780 glBindTexture(binding_target, textures_[1]);
666 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 781 glTexImage2D(dest_target, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
667 transparent_pixels); 782 transparent_pixels);
668 783
669 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 1, 1, 0, 784 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], 1, 1, 0, 0,
670 0, 1, 1, false, false, false); 785 1, 1, false, false, false);
671 EXPECT_TRUE(glGetError() == GL_NO_ERROR); 786 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
672 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 1, 0, 1, 787 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], 1, 0, 1, 0,
673 0, 1, 1, false, false, false); 788 1, 1, false, false, false);
674 EXPECT_TRUE(glGetError() == GL_NO_ERROR); 789 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
675 glCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 1, 0, 790 glCopySubTextureCHROMIUM(dest_target, textures_[0], textures_[1], 0, 1, 0, 1,
676 1, 1, 1, false, false, false); 791 1, 1, false, false, false);
677 EXPECT_TRUE(glGetError() == GL_NO_ERROR); 792 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
678 793
794 MakeCubeComplete(dest_target, GL_RGBA, GL_UNSIGNED_BYTE, 2, 2);
795
679 // Check the FB is still bound. 796 // Check the FB is still bound.
680 GLint value = 0; 797 GLint value = 0;
681 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value); 798 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value);
682 GLuint fb_id = value; 799 GLuint fb_id = value;
683 EXPECT_EQ(framebuffer_id_, fb_id); 800 EXPECT_EQ(framebuffer_id_, fb_id);
684 801
685 // Check that FB is complete. 802 // Check that FB is complete.
686 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), 803 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
687 glCheckFramebufferStatus(GL_FRAMEBUFFER)); 804 glCheckFramebufferStatus(GL_FRAMEBUFFER));
688 805
689 uint8 transparent[1 * 4] = {0u, 0u, 0u, 0u}; 806 uint8 transparent[1 * 4] = {0u, 0u, 0u, 0u};
690 uint8 red[1 * 4] = {255u, 0u, 0u, 255u}; 807 uint8 red[1 * 4] = {255u, 0u, 0u, 255u};
691 uint8 green[1 * 4] = {0u, 255u, 0u, 255u}; 808 uint8 green[1 * 4] = {0u, 255u, 0u, 255u};
692 uint8 blue[1 * 4] = {0u, 0u, 255u, 255u}; 809 uint8 blue[1 * 4] = {0u, 0u, 255u, 255u};
693 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, transparent); 810 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, transparent);
694 GLTestHelper::CheckPixels(1, 1, 1, 1, 0, red); 811 GLTestHelper::CheckPixels(1, 1, 1, 1, 0, red);
695 GLTestHelper::CheckPixels(1, 0, 1, 1, 0, green); 812 GLTestHelper::CheckPixels(1, 0, 1, 1, 0, green);
696 GLTestHelper::CheckPixels(0, 1, 1, 1, 0, blue); 813 GLTestHelper::CheckPixels(0, 1, 1, 1, 0, blue);
697 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 814 EXPECT_TRUE(GL_NO_ERROR == glGetError());
698 } 815 }
699 816
700 } // namespace gpu 817 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698