OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef GL_GLEXT_PROTOTYPES | 5 #ifndef GL_GLEXT_PROTOTYPES |
6 #define GL_GLEXT_PROTOTYPES | 6 #define GL_GLEXT_PROTOTYPES |
7 #endif | 7 #endif |
8 | 8 |
9 #include <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
10 #include <GLES2/gl2ext.h> | 10 #include <GLES2/gl2ext.h> |
11 #include <GLES2/gl2extchromium.h> | 11 #include <GLES2/gl2extchromium.h> |
12 #include <stdint.h> | 12 #include <stdint.h> |
13 | 13 |
14 #include "gpu/command_buffer/tests/gl_manager.h" | 14 #include "gpu/command_buffer/tests/gl_manager.h" |
15 #include "gpu/command_buffer/tests/gl_test_utils.h" | 15 #include "gpu/command_buffer/tests/gl_test_utils.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 #define SHADER(src) #src | 19 #define SHADER(src) #src |
20 | 20 |
21 namespace gpu { | 21 namespace gpu { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 enum CopyType { TexImage, TexSubImage }; | |
26 const CopyType kCopyTypes[] = { | |
27 TexImage, | |
28 TexSubImage, | |
29 }; | |
30 | |
31 const uint8_t kCompressedImageColor[4] = {255u, 0u, 0u, 255u}; | 25 const uint8_t kCompressedImageColor[4] = {255u, 0u, 0u, 255u}; |
32 | 26 |
33 // Single compressed ATC block of source pixels all set to: | 27 // Single compressed ATC block of source pixels all set to: |
34 // kCompressedImageColor. | 28 // kCompressedImageColor. |
35 const uint8_t kCompressedImageATC[8] = {0x0, 0x7c, 0x0, 0xf8, | 29 const uint8_t kCompressedImageATC[8] = {0x0, 0x7c, 0x0, 0xf8, |
36 0x55, 0x55, 0x55, 0x55}; | 30 0x55, 0x55, 0x55, 0x55}; |
37 | 31 |
38 // Single compressed ATCIA block of source pixels all set to: | 32 // Single compressed ATCIA block of source pixels all set to: |
39 // kCompressedImageColor. | 33 // kCompressedImageColor. |
40 const uint8_t kCompressedImageATCIA[16] = {0xff, 0xff, 0x0, 0x0, 0x0, 0x0, | 34 const uint8_t kCompressedImageATCIA[16] = {0xff, 0xff, 0x0, 0x0, 0x0, 0x0, |
41 0x0, 0x0, 0x0, 0x7c, 0x0, 0xf8, | 35 0x0, 0x0, 0x0, 0x7c, 0x0, 0xf8, |
42 0x55, 0x55, 0x55, 0x55}; | 36 0x55, 0x55, 0x55, 0x55}; |
43 | 37 |
44 // Single compressed DXT1 block of source pixels all set to: | 38 // Single compressed DXT1 block of source pixels all set to: |
45 // kCompressedImageColor. | 39 // kCompressedImageColor. |
46 const uint8_t kCompressedImageDXT1[8] = {0x00, 0xf8, 0x00, 0xf8, | 40 const uint8_t kCompressedImageDXT1[8] = {0x00, 0xf8, 0x00, 0xf8, |
47 0xaa, 0xaa, 0xaa, 0xaa}; | 41 0xaa, 0xaa, 0xaa, 0xaa}; |
48 | 42 |
49 // Four compressed DXT1 blocks solidly colored in red, green, blue and black: | |
50 // [R][G] | |
51 // [B][b] | |
52 const uint8_t kCompressedImageDXT1RGB[32] = { | |
53 0x0, 0xf8, 0x0, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa, 0xe0, 0x7, 0xe0, | |
54 0x7, 0xaa, 0xaa, 0xaa, 0xaa, 0x1f, 0x0, 0x1f, 0x0, 0xaa, 0xaa, | |
55 0xaa, 0xaa, 0x0, 0x0, 0x0, 0x0, 0xaa, 0xaa, 0xaa, 0xaa}; | |
56 | |
57 // Single compressed DXT5 block of source pixels all set to: | 43 // Single compressed DXT5 block of source pixels all set to: |
58 // kCompressedImageColor. | 44 // kCompressedImageColor. |
59 const uint8_t kCompressedImageDXT5[16] = {0xff, 0xff, 0x0, 0x0, 0x0, 0x0, | 45 const uint8_t kCompressedImageDXT5[16] = {0xff, 0xff, 0x0, 0x0, 0x0, 0x0, |
60 0x0, 0x0, 0x0, 0xf8, 0x0, 0xf8, | 46 0x0, 0x0, 0x0, 0xf8, 0x0, 0xf8, |
61 0xaa, 0xaa, 0xaa, 0xaa}; | 47 0xaa, 0xaa, 0xaa, 0xaa}; |
62 | 48 |
63 // Single compressed DXT1 block of source pixels all set to: | 49 // Single compressed DXT1 block of source pixels all set to: |
64 // kCompressedImageColor. | 50 // kCompressedImageColor. |
65 const uint8_t kCompressedImageETC1[8] = {0x0, 0x0, 0xf8, 0x2, | 51 const uint8_t kCompressedImageETC1[8] = {0x0, 0x0, 0xf8, 0x2, |
66 0xff, 0xff, 0x0, 0x0}; | 52 0xff, 0xff, 0x0, 0x0}; |
67 | 53 |
68 // Single block of zeroes, used for texture pre-allocation. | |
69 const uint8_t kInvalidCompressedImage[8] = {0x0, 0x0, 0x0, 0x0, | |
70 0x0, 0x0, 0x0, 0x0}; | |
71 | |
72 // Four blocks of zeroes, used for texture pre-allocation. | |
73 const uint8_t kInvalidCompressedImageLarge[32] = { | |
74 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | |
75 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | |
76 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; | |
77 | |
78 void glEnableDisable(GLint param, GLboolean value) { | 54 void glEnableDisable(GLint param, GLboolean value) { |
79 if (value) | 55 if (value) |
80 glEnable(param); | 56 glEnable(param); |
81 else | 57 else |
82 glDisable(param); | 58 glDisable(param); |
83 } | 59 } |
84 | 60 |
85 } // unnamed namespace | 61 } // unnamed namespace |
86 | 62 |
87 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. | 63 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. |
88 class GLCompressedCopyTextureCHROMIUMTest | 64 class GLCompressedCopyTextureCHROMIUMTest |
89 : public testing::Test, | 65 : public testing::Test { |
90 public ::testing::WithParamInterface<CopyType> { | |
91 protected: | 66 protected: |
92 void SetUp() override { | 67 void SetUp() override { |
93 gl_.Initialize(GLManager::Options()); | 68 gl_.Initialize(GLManager::Options()); |
94 | 69 |
95 glGenTextures(2, textures_); | 70 glGenTextures(2, textures_); |
96 } | 71 } |
97 | 72 |
98 void TearDown() override { | 73 void TearDown() override { |
99 glDeleteTextures(2, textures_); | 74 glDeleteTextures(2, textures_); |
100 gl_.Destroy(); | 75 gl_.Destroy(); |
(...skipping 17 matching lines...) Expand all Loading... |
118 } | 93 } |
119 ); | 94 ); |
120 return GLTestHelper::LoadProgram(v_shader_src, f_shader_src); | 95 return GLTestHelper::LoadProgram(v_shader_src, f_shader_src); |
121 } | 96 } |
122 | 97 |
123 GLManager gl_; | 98 GLManager gl_; |
124 GLuint textures_[2]; | 99 GLuint textures_[2]; |
125 GLuint framebuffer_id_; | 100 GLuint framebuffer_id_; |
126 }; | 101 }; |
127 | 102 |
128 INSTANTIATE_TEST_CASE_P(CopyType, | |
129 GLCompressedCopyTextureCHROMIUMTest, | |
130 ::testing::ValuesIn(kCopyTypes)); | |
131 | |
132 // Test to ensure that the basic functionality of the extension works. | 103 // Test to ensure that the basic functionality of the extension works. |
133 TEST_P(GLCompressedCopyTextureCHROMIUMTest, Basic) { | 104 TEST_F(GLCompressedCopyTextureCHROMIUMTest, Basic) { |
134 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { | 105 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { |
135 LOG(INFO) << | 106 LOG(INFO) << |
136 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; | 107 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; |
137 return; | 108 return; |
138 } | 109 } |
139 | 110 |
140 CopyType copy_type = GetParam(); | |
141 | |
142 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 111 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
143 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
144 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 113 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
145 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 114 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
146 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 115 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
147 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | 116 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
148 4, 4, 0, | 117 4, 4, 0, |
149 sizeof(kCompressedImageDXT1), kCompressedImageDXT1); | 118 sizeof(kCompressedImageDXT1), kCompressedImageDXT1); |
150 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | 119 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
151 | 120 |
152 glBindTexture(GL_TEXTURE_2D, textures_[1]); | 121 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
153 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 122 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
154 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 123 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
155 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 124 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
156 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 125 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
157 if (copy_type == TexImage) { | 126 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]); |
158 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]); | |
159 } else { | |
160 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | |
161 4, 4, 0, | |
162 sizeof(kInvalidCompressedImage), | |
163 kInvalidCompressedImage); | |
164 | |
165 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], | |
166 textures_[1], 0, 0, 0, 0, 4, 4); | |
167 } | |
168 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | 127 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
169 | 128 |
170 // Load shader program. | 129 // Load shader program. |
171 GLuint program = LoadProgram(); | 130 GLuint program = LoadProgram(); |
172 ASSERT_NE(program, 0u); | 131 ASSERT_NE(program, 0u); |
173 GLint position_loc = glGetAttribLocation(program, "a_position"); | 132 GLint position_loc = glGetAttribLocation(program, "a_position"); |
174 GLint texture_loc = glGetUniformLocation(program, "u_texture"); | 133 GLint texture_loc = glGetUniformLocation(program, "u_texture"); |
175 ASSERT_NE(position_loc, -1); | 134 ASSERT_NE(position_loc, -1); |
176 ASSERT_NE(texture_loc, -1); | 135 ASSERT_NE(texture_loc, -1); |
177 glUseProgram(program); | 136 glUseProgram(program); |
178 | 137 |
179 // Load geometry. | 138 // Load geometry. |
180 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc); | 139 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc); |
181 ASSERT_NE(vbo, 0u); | 140 ASSERT_NE(vbo, 0u); |
182 | 141 |
183 // Load texture. | 142 // Load texture. |
184 glActiveTexture(GL_TEXTURE0); | 143 glActiveTexture(GL_TEXTURE0); |
185 glBindTexture(GL_TEXTURE_2D, textures_[1]); | 144 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
186 glUniform1i(texture_loc, 0); | 145 glUniform1i(texture_loc, 0); |
187 | 146 |
188 // Draw. | 147 // Draw. |
189 glDrawArrays(GL_TRIANGLES, 0, 6); | 148 glDrawArrays(GL_TRIANGLES, 0, 6); |
190 glFlush(); | 149 glFlush(); |
191 | 150 |
192 GLTestHelper::CheckPixels(0, 0, 4, 4, 0, kCompressedImageColor); | 151 GLTestHelper::CheckPixels(0, 0, 4, 4, 0, kCompressedImageColor); |
193 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 152 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
194 } | 153 } |
195 | 154 |
196 TEST_P(GLCompressedCopyTextureCHROMIUMTest, InternalFormat) { | 155 TEST_F(GLCompressedCopyTextureCHROMIUMTest, InternalFormat) { |
197 CopyType copy_type = GetParam(); | |
198 | |
199 struct Image { | 156 struct Image { |
200 const GLint format; | 157 const GLint format; |
201 const uint8_t* data; | 158 const uint8_t* data; |
202 const GLsizei data_size; | 159 const GLsizei data_size; |
203 | 160 |
204 Image(const GLint format, const uint8_t* data, const GLsizei data_size) | 161 Image(const GLint format, const uint8_t* data, const GLsizei data_size) |
205 : format(format), data(data), data_size(data_size) {} | 162 : format(format), data(data), data_size(data_size) {} |
206 }; | 163 }; |
207 std::vector<scoped_ptr<Image>> supported_formats; | 164 std::vector<scoped_ptr<Image>> supported_formats; |
208 | 165 |
209 if ((GLTestHelper::HasExtension("GL_AMD_compressed_ATC_texture") || | 166 if (GLTestHelper::HasExtension("GL_AMD_compressed_ATC_texture") || |
210 GLTestHelper::HasExtension("GL_ATI_texture_compression_atitc")) && | 167 GLTestHelper::HasExtension("GL_ATI_texture_compression_atitc")) { |
211 copy_type != TexSubImage) { | |
212 supported_formats.push_back(make_scoped_ptr(new Image( | 168 supported_formats.push_back(make_scoped_ptr(new Image( |
213 GL_ATC_RGB_AMD, | 169 GL_ATC_RGB_AMD, |
214 kCompressedImageATC, | 170 kCompressedImageATC, |
215 sizeof(kCompressedImageATC)))); | 171 sizeof(kCompressedImageATC)))); |
216 supported_formats.push_back(make_scoped_ptr(new Image( | 172 supported_formats.push_back(make_scoped_ptr(new Image( |
217 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, | 173 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, |
218 kCompressedImageATCIA, | 174 kCompressedImageATCIA, |
219 sizeof(kCompressedImageATCIA)))); | 175 sizeof(kCompressedImageATCIA)))); |
220 } | 176 } |
221 if (GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { | 177 if (GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { |
222 supported_formats.push_back(make_scoped_ptr(new Image( | 178 supported_formats.push_back(make_scoped_ptr(new Image( |
223 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | 179 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
224 kCompressedImageDXT1, | 180 kCompressedImageDXT1, |
225 sizeof(kCompressedImageDXT1)))); | 181 sizeof(kCompressedImageDXT1)))); |
226 } | 182 } |
227 if (GLTestHelper::HasExtension("GL_ANGLE_texture_compression_dxt5") || | 183 if (GLTestHelper::HasExtension("GL_ANGLE_texture_compression_dxt5") || |
228 GLTestHelper::HasExtension("GL_EXT_texture_compression_s3tc")) { | 184 GLTestHelper::HasExtension("GL_EXT_texture_compression_s3tc")) { |
229 supported_formats.push_back(make_scoped_ptr(new Image( | 185 supported_formats.push_back(make_scoped_ptr(new Image( |
230 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, | 186 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, |
231 kCompressedImageDXT5, | 187 kCompressedImageDXT5, |
232 sizeof(kCompressedImageDXT5)))); | 188 sizeof(kCompressedImageDXT5)))); |
233 } | 189 } |
234 if (GLTestHelper::HasExtension("GL_OES_compressed_ETC1_RGB8_texture") && | 190 if (GLTestHelper::HasExtension("GL_OES_compressed_ETC1_RGB8_texture")) { |
235 copy_type != TexSubImage) { | |
236 supported_formats.push_back(make_scoped_ptr(new Image( | 191 supported_formats.push_back(make_scoped_ptr(new Image( |
237 GL_ETC1_RGB8_OES, | 192 GL_ETC1_RGB8_OES, |
238 kCompressedImageETC1, | 193 kCompressedImageETC1, |
239 sizeof(kCompressedImageETC1)))); | 194 sizeof(kCompressedImageETC1)))); |
240 } | 195 } |
241 | 196 |
242 for (const auto& image : supported_formats) { | 197 for (const auto& image : supported_formats) { |
243 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 198 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
244 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 199 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
245 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
246 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
247 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
248 glCompressedTexImage2D(GL_TEXTURE_2D, 0, image->format, | 203 glCompressedTexImage2D(GL_TEXTURE_2D, 0, image->format, |
249 4, 4, 0, image->data_size, image->data); | 204 4, 4, 0, image->data_size, image->data); |
250 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 205 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
251 | 206 |
252 glBindTexture(GL_TEXTURE_2D, textures_[1]); | 207 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
253 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 208 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
254 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 209 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
255 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 210 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
256 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 211 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
257 if (copy_type == TexImage) { | 212 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]); |
258 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], | |
259 textures_[1]); | |
260 } else { | |
261 glCompressedTexImage2D(GL_TEXTURE_2D, 0, image->format, 4, 4, 0, | |
262 sizeof(kInvalidCompressedImage), | |
263 kInvalidCompressedImage); | |
264 | |
265 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], | |
266 textures_[1], 0, 0, 0, 0, 4, 4); | |
267 } | |
268 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 213 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
269 } | 214 } |
270 } | 215 } |
271 | 216 |
272 TEST_P(GLCompressedCopyTextureCHROMIUMTest, InternalFormatNotSupported) { | 217 TEST_F(GLCompressedCopyTextureCHROMIUMTest, InternalFormatNotSupported) { |
273 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { | 218 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { |
274 LOG(INFO) << | 219 LOG(INFO) << |
275 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; | 220 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; |
276 return; | 221 return; |
277 } | 222 } |
278 | 223 |
279 CopyType copy_type = GetParam(); | |
280 | |
281 const uint8_t kUncompressedPixels[1 * 4] = {255u, 0u, 0u, 255u}; | 224 const uint8_t kUncompressedPixels[1 * 4] = {255u, 0u, 0u, 255u}; |
282 | 225 |
283 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 226 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
284 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 227 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
285 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 228 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
286 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 229 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
287 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 230 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
288 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 231 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
289 kUncompressedPixels); | 232 kUncompressedPixels); |
290 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | 233 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
291 | 234 |
292 glBindTexture(GL_TEXTURE_2D, textures_[1]); | 235 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
293 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 236 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
294 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 237 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
295 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 238 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
296 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 239 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
297 | 240 |
298 // Check that the GL_RGBA format reports an error. | 241 // Check that the GL_RGBA format reports an error. |
299 if (copy_type == TexImage) { | 242 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]); |
300 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]); | |
301 } else { | |
302 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
303 kUncompressedPixels); | |
304 | |
305 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], | |
306 textures_[1], 0, 0, 0, 0, 1, 1); | |
307 } | |
308 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()); | 243 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()); |
309 } | 244 } |
310 | 245 |
311 TEST_P(GLCompressedCopyTextureCHROMIUMTest, InvalidTextureIds) { | 246 TEST_F(GLCompressedCopyTextureCHROMIUMTest, InvalidTextureIds) { |
312 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { | 247 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { |
313 LOG(INFO) | 248 LOG(INFO) |
314 << "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; | 249 << "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; |
315 return; | 250 return; |
316 } | 251 } |
317 | 252 |
318 CopyType copy_type = GetParam(); | |
319 | |
320 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 253 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
321 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
322 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 255 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
323 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 256 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
324 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 257 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
325 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, | 258 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, |
326 4, 0, sizeof(kCompressedImageDXT1), | 259 4, 0, sizeof(kCompressedImageDXT1), |
327 kCompressedImageDXT1); | 260 kCompressedImageDXT1); |
328 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | 261 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
329 | 262 |
330 glBindTexture(GL_TEXTURE_2D, textures_[1]); | 263 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
331 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 264 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
332 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 265 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
333 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 266 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
334 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 267 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
335 if (copy_type == TexImage) { | |
336 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], 99993); | |
337 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); | |
338 | 268 |
339 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, 99994, textures_[1]); | 269 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], 99993); |
340 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); | 270 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); |
341 | 271 |
342 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, 99995, 99996); | 272 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, 99994, textures_[1]); |
343 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); | 273 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); |
344 | 274 |
345 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]); | 275 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, 99995, 99996); |
346 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | 276 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); |
347 } else { | |
348 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, | |
349 4, 0, sizeof(kInvalidCompressedImage), | |
350 kInvalidCompressedImage); | |
351 | 277 |
352 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], 99993, 0, 0, | 278 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]); |
353 0, 0, 4, 4); | 279 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
354 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); | |
355 | |
356 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, 99994, textures_[1], 0, 0, | |
357 0, 0, 4, 4); | |
358 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); | |
359 | |
360 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, 99995, 99996, 0, 0, 0, 0, | |
361 4, 4); | |
362 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); | |
363 | |
364 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], | |
365 textures_[1], 0, 0, 0, 0, 4, 4); | |
366 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
367 } | |
368 } | 280 } |
369 | 281 |
370 // Validate that some basic GL state is not touched upon execution of | 282 // Validate that some basic GL state is not touched upon execution of |
371 // the extension. | 283 // the extension. |
372 TEST_P(GLCompressedCopyTextureCHROMIUMTest, BasicStatePreservation) { | 284 TEST_F(GLCompressedCopyTextureCHROMIUMTest, BasicStatePreservation) { |
373 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { | 285 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { |
374 LOG(INFO) << | 286 LOG(INFO) << |
375 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; | 287 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; |
376 return; | 288 return; |
377 } | 289 } |
378 | 290 |
379 CopyType copy_type = GetParam(); | |
380 | |
381 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 291 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
382 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 292 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
383 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 293 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
384 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 294 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
385 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 295 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
386 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | 296 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
387 4, 4, 0, | 297 4, 4, 0, |
388 sizeof(kCompressedImageDXT1), kCompressedImageDXT1); | 298 sizeof(kCompressedImageDXT1), kCompressedImageDXT1); |
389 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | 299 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
390 | 300 |
391 glBindTexture(GL_TEXTURE_2D, textures_[1]); | 301 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
392 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 302 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
393 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 303 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
394 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 304 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
395 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 305 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
396 | 306 |
397 if (copy_type == TexSubImage) { | |
398 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | |
399 4, 4, 0, | |
400 sizeof(kInvalidCompressedImage), | |
401 kInvalidCompressedImage); | |
402 } | |
403 | |
404 GLboolean reference_settings[2] = { GL_TRUE, GL_FALSE }; | 307 GLboolean reference_settings[2] = { GL_TRUE, GL_FALSE }; |
405 for (int x = 0; x < 2; ++x) { | 308 for (int x = 0; x < 2; ++x) { |
406 GLboolean setting = reference_settings[x]; | 309 GLboolean setting = reference_settings[x]; |
407 glEnableDisable(GL_DEPTH_TEST, setting); | 310 glEnableDisable(GL_DEPTH_TEST, setting); |
408 glEnableDisable(GL_SCISSOR_TEST, setting); | 311 glEnableDisable(GL_SCISSOR_TEST, setting); |
409 glEnableDisable(GL_STENCIL_TEST, setting); | 312 glEnableDisable(GL_STENCIL_TEST, setting); |
410 glEnableDisable(GL_CULL_FACE, setting); | 313 glEnableDisable(GL_CULL_FACE, setting); |
411 glEnableDisable(GL_BLEND, setting); | 314 glEnableDisable(GL_BLEND, setting); |
412 glColorMask(setting, setting, setting, setting); | 315 glColorMask(setting, setting, setting, setting); |
413 glDepthMask(setting); | 316 glDepthMask(setting); |
414 | 317 |
415 glActiveTexture(GL_TEXTURE1 + x); | 318 glActiveTexture(GL_TEXTURE1 + x); |
416 | 319 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]); |
417 if (copy_type == TexImage) { | |
418 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], | |
419 textures_[1]); | |
420 } else { | |
421 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], | |
422 textures_[1], 0, 0, 0, 0, 4, 4); | |
423 } | |
424 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | 320 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
425 | 321 |
426 EXPECT_EQ(setting, glIsEnabled(GL_DEPTH_TEST)); | 322 EXPECT_EQ(setting, glIsEnabled(GL_DEPTH_TEST)); |
427 EXPECT_EQ(setting, glIsEnabled(GL_SCISSOR_TEST)); | 323 EXPECT_EQ(setting, glIsEnabled(GL_SCISSOR_TEST)); |
428 EXPECT_EQ(setting, glIsEnabled(GL_STENCIL_TEST)); | 324 EXPECT_EQ(setting, glIsEnabled(GL_STENCIL_TEST)); |
429 EXPECT_EQ(setting, glIsEnabled(GL_CULL_FACE)); | 325 EXPECT_EQ(setting, glIsEnabled(GL_CULL_FACE)); |
430 EXPECT_EQ(setting, glIsEnabled(GL_BLEND)); | 326 EXPECT_EQ(setting, glIsEnabled(GL_BLEND)); |
431 | 327 |
432 GLboolean bool_array[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE }; | 328 GLboolean bool_array[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE }; |
433 glGetBooleanv(GL_DEPTH_WRITEMASK, bool_array); | 329 glGetBooleanv(GL_DEPTH_WRITEMASK, bool_array); |
434 EXPECT_EQ(setting, bool_array[0]); | 330 EXPECT_EQ(setting, bool_array[0]); |
435 | 331 |
436 bool_array[0] = GL_FALSE; | 332 bool_array[0] = GL_FALSE; |
437 glGetBooleanv(GL_COLOR_WRITEMASK, bool_array); | 333 glGetBooleanv(GL_COLOR_WRITEMASK, bool_array); |
438 EXPECT_EQ(setting, bool_array[0]); | 334 EXPECT_EQ(setting, bool_array[0]); |
439 EXPECT_EQ(setting, bool_array[1]); | 335 EXPECT_EQ(setting, bool_array[1]); |
440 EXPECT_EQ(setting, bool_array[2]); | 336 EXPECT_EQ(setting, bool_array[2]); |
441 EXPECT_EQ(setting, bool_array[3]); | 337 EXPECT_EQ(setting, bool_array[3]); |
442 | 338 |
443 GLint active_texture = 0; | 339 GLint active_texture = 0; |
444 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); | 340 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); |
445 EXPECT_EQ(GL_TEXTURE1 + x, active_texture); | 341 EXPECT_EQ(GL_TEXTURE1 + x, active_texture); |
446 } | 342 } |
447 | 343 |
448 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 344 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
449 }; | 345 }; |
450 | 346 |
451 // Verify that invocation of the extension does not modify the bound | 347 // Verify that invocation of the extension does not modify the bound |
452 // texture state. | 348 // texture state. |
453 TEST_P(GLCompressedCopyTextureCHROMIUMTest, TextureStatePreserved) { | 349 TEST_F(GLCompressedCopyTextureCHROMIUMTest, TextureStatePreserved) { |
454 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { | 350 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { |
455 LOG(INFO) << | 351 LOG(INFO) << |
456 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; | 352 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; |
457 return; | 353 return; |
458 } | 354 } |
459 | 355 |
460 CopyType copy_type = GetParam(); | |
461 | |
462 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 356 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
463 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 357 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
464 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 358 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
465 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 359 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
466 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 360 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
467 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | 361 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
468 4, 4, 0, | 362 4, 4, 0, |
469 sizeof(kCompressedImageDXT1), kCompressedImageDXT1); | 363 sizeof(kCompressedImageDXT1), kCompressedImageDXT1); |
470 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | 364 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
471 | 365 |
472 glBindTexture(GL_TEXTURE_2D, textures_[1]); | 366 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
473 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 367 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
474 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 368 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
475 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 369 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
476 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 370 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
477 | 371 |
478 if (copy_type == TexSubImage) { | |
479 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | |
480 4, 4, 0, | |
481 sizeof(kInvalidCompressedImage), | |
482 kInvalidCompressedImage); | |
483 } | |
484 | |
485 GLuint texture_ids[2]; | 372 GLuint texture_ids[2]; |
486 glGenTextures(2, texture_ids); | 373 glGenTextures(2, texture_ids); |
487 | 374 |
488 glActiveTexture(GL_TEXTURE0); | 375 glActiveTexture(GL_TEXTURE0); |
489 glBindTexture(GL_TEXTURE_2D, texture_ids[0]); | 376 glBindTexture(GL_TEXTURE_2D, texture_ids[0]); |
490 | 377 |
491 glActiveTexture(GL_TEXTURE1); | 378 glActiveTexture(GL_TEXTURE1); |
492 glBindTexture(GL_TEXTURE_2D, texture_ids[1]); | 379 glBindTexture(GL_TEXTURE_2D, texture_ids[1]); |
493 | 380 |
494 if (copy_type == TexImage) { | 381 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]); |
495 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]); | |
496 } else { | |
497 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], | |
498 textures_[1], 0, 0, 0, 0, 4, 4); | |
499 } | |
500 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 382 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
501 | 383 |
502 GLint active_texture = 0; | 384 GLint active_texture = 0; |
503 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); | 385 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); |
504 EXPECT_EQ(GL_TEXTURE1, active_texture); | 386 EXPECT_EQ(GL_TEXTURE1, active_texture); |
505 | 387 |
506 GLint bound_texture = 0; | 388 GLint bound_texture = 0; |
507 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); | 389 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); |
508 EXPECT_EQ(texture_ids[1], static_cast<GLuint>(bound_texture)); | 390 EXPECT_EQ(texture_ids[1], static_cast<GLuint>(bound_texture)); |
509 glBindTexture(GL_TEXTURE_2D, 0); | 391 glBindTexture(GL_TEXTURE_2D, 0); |
510 | 392 |
511 bound_texture = 0; | 393 bound_texture = 0; |
512 glActiveTexture(GL_TEXTURE0); | 394 glActiveTexture(GL_TEXTURE0); |
513 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); | 395 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); |
514 EXPECT_EQ(texture_ids[0], static_cast<GLuint>(bound_texture)); | 396 EXPECT_EQ(texture_ids[0], static_cast<GLuint>(bound_texture)); |
515 glBindTexture(GL_TEXTURE_2D, 0); | 397 glBindTexture(GL_TEXTURE_2D, 0); |
516 | 398 |
517 glDeleteTextures(2, texture_ids); | 399 glDeleteTextures(2, texture_ids); |
518 | 400 |
519 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 401 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
520 } | 402 } |
521 | 403 |
522 TEST_F(GLCompressedCopyTextureCHROMIUMTest, CopySubTextureDimension) { | |
523 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { | |
524 LOG(INFO) << | |
525 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; | |
526 return; | |
527 } | |
528 | |
529 glBindTexture(GL_TEXTURE_2D, textures_[0]); | |
530 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
531 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
532 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
533 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
534 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | |
535 8, 8, 0, | |
536 sizeof(kCompressedImageDXT1RGB), | |
537 kCompressedImageDXT1RGB); | |
538 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
539 | |
540 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
541 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
542 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
543 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
544 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
545 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | |
546 8, 8, 0, | |
547 sizeof(kInvalidCompressedImageLarge), | |
548 kInvalidCompressedImageLarge); | |
549 | |
550 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], | |
551 textures_[1], 4, 4, 0, 0, 4, 4); | |
552 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | |
553 | |
554 // Reset the destination texture as it might have been converted to RGBA. | |
555 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | |
556 8, 8, 0, | |
557 sizeof(kInvalidCompressedImageLarge), | |
558 kInvalidCompressedImageLarge); | |
559 | |
560 // xoffset < 0 | |
561 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], | |
562 -4, 4, 0, 0, 4, 4); | |
563 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); | |
564 | |
565 // x < 0 | |
566 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], | |
567 4, 4, -4, 0, 4, 4); | |
568 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); | |
569 | |
570 // xoffset + width > dest_width | |
571 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], | |
572 8, 8, 0, 0, 4, 4); | |
573 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); | |
574 | |
575 // x + width > source_width | |
576 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], | |
577 0, 0, 8, 8, 4, 4); | |
578 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE); | |
579 | |
580 // xoffset not within block-boundary | |
581 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], | |
582 3, 0, 0, 0, 4, 4); | |
583 EXPECT_TRUE(glGetError() == GL_INVALID_OPERATION); | |
584 | |
585 // x not within block-boundary | |
586 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], | |
587 0, 0, 3, 0, 4, 4); | |
588 EXPECT_TRUE(glGetError() == GL_INVALID_OPERATION); | |
589 } | |
590 | |
591 TEST_F(GLCompressedCopyTextureCHROMIUMTest, CopySubTextureOffset) { | |
592 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { | |
593 LOG(INFO) << | |
594 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; | |
595 return; | |
596 } | |
597 | |
598 glBindTexture(GL_TEXTURE_2D, textures_[0]); | |
599 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
600 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
601 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
602 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
603 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | |
604 8, 8, 0, | |
605 sizeof(kCompressedImageDXT1RGB), | |
606 kCompressedImageDXT1RGB); | |
607 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
608 | |
609 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
610 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
611 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
612 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
613 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
614 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | |
615 8, 8, 0, | |
616 sizeof(kInvalidCompressedImageLarge), | |
617 kInvalidCompressedImageLarge); | |
618 | |
619 // Load shader program. | |
620 GLuint program = LoadProgram(); | |
621 ASSERT_NE(program, 0u); | |
622 GLint position_loc = glGetAttribLocation(program, "a_position"); | |
623 GLint texture_loc = glGetUniformLocation(program, "u_texture"); | |
624 ASSERT_NE(position_loc, -1); | |
625 ASSERT_NE(texture_loc, -1); | |
626 glUseProgram(program); | |
627 | |
628 // Load geometry. | |
629 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc); | |
630 ASSERT_NE(vbo, 0u); | |
631 | |
632 // Load texture. | |
633 glActiveTexture(GL_TEXTURE0); | |
634 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
635 glUniform1i(texture_loc, 0); | |
636 | |
637 const uint8_t kBlack[1 * 4] = {0u, 0u, 0u, 255u}; | |
638 const uint8_t kRed[1 * 4] = {255u, 0u, 0u, 255u}; | |
639 const uint8_t kGreen[1 * 4] = {0u, 255u, 0u, 255u}; | |
640 const uint8_t kBlue[1 * 4] = {0u, 0u, 255u, 255u}; | |
641 | |
642 // Copy each block one by one in a clockwise fashion. Note that we reset the | |
643 // destination texture after each copy operation. That's because on some | |
644 // platforms we might fallback into replacing the compressed destination | |
645 // texture with an uncompressed one. | |
646 | |
647 // Move blue block up. | |
648 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], | |
649 textures_[1], 0, 0, 0, 4, 4, 4); | |
650 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
651 | |
652 glDrawArrays(GL_TRIANGLES, 0, 6); | |
653 glFlush(); | |
654 GLTestHelper::CheckPixels(0, 0, 2, 2, 0, kBlue); | |
655 | |
656 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
657 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | |
658 8, 8, 0, | |
659 sizeof(kInvalidCompressedImageLarge), | |
660 kInvalidCompressedImageLarge); | |
661 | |
662 // Move red block right. | |
663 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], | |
664 textures_[1], 4, 0, 0, 0, 4, 4); | |
665 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
666 | |
667 glDrawArrays(GL_TRIANGLES, 0, 6); | |
668 glFlush(); | |
669 GLTestHelper::CheckPixels(2, 0, 2, 2, 0, kRed); | |
670 | |
671 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | |
672 8, 8, 0, | |
673 sizeof(kInvalidCompressedImageLarge), | |
674 kInvalidCompressedImageLarge); | |
675 | |
676 // Move green block down. | |
677 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], | |
678 textures_[1], 4, 4, 4, 0, 4, 4); | |
679 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
680 | |
681 glDrawArrays(GL_TRIANGLES, 0, 6); | |
682 glFlush(); | |
683 GLTestHelper::CheckPixels(2, 2, 2, 2, 0, kGreen); | |
684 | |
685 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | |
686 8, 8, 0, | |
687 sizeof(kInvalidCompressedImageLarge), | |
688 kInvalidCompressedImageLarge); | |
689 | |
690 // Move black block left. | |
691 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], | |
692 textures_[1], 0, 4, 4, 4, 4, 4); | |
693 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
694 | |
695 glDrawArrays(GL_TRIANGLES, 0, 6); | |
696 glFlush(); | |
697 GLTestHelper::CheckPixels(0, 2, 2, 2, 0, kBlack); | |
698 | |
699 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | |
700 } | |
701 | |
702 TEST_F(GLCompressedCopyTextureCHROMIUMTest, CopySubTexturePreservation) { | |
703 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { | |
704 LOG(INFO) << | |
705 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; | |
706 return; | |
707 } | |
708 | |
709 glBindTexture(GL_TEXTURE_2D, textures_[0]); | |
710 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
711 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
712 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
713 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
714 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | |
715 4, 4, 0, | |
716 sizeof(kCompressedImageDXT1), | |
717 kCompressedImageDXT1); | |
718 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
719 | |
720 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
721 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
722 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
723 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
724 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
725 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | |
726 8, 8, 0, | |
727 sizeof(kCompressedImageDXT1RGB), | |
728 kCompressedImageDXT1RGB); | |
729 | |
730 // Copy entire first texture into the second, replacing the green block: | |
731 // [R][R] | |
732 // [B][b] | |
733 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], | |
734 textures_[1], 4, 0, 0, 0, 4, 4); | |
735 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
736 | |
737 // Load shader program. | |
738 GLuint program = LoadProgram(); | |
739 ASSERT_NE(program, 0u); | |
740 GLint position_loc = glGetAttribLocation(program, "a_position"); | |
741 GLint texture_loc = glGetUniformLocation(program, "u_texture"); | |
742 ASSERT_NE(position_loc, -1); | |
743 ASSERT_NE(texture_loc, -1); | |
744 glUseProgram(program); | |
745 | |
746 // Load geometry. | |
747 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc); | |
748 ASSERT_NE(vbo, 0u); | |
749 | |
750 // Load texture. | |
751 glActiveTexture(GL_TEXTURE0); | |
752 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
753 glUniform1i(texture_loc, 0); | |
754 | |
755 // Draw. | |
756 glDrawArrays(GL_TRIANGLES, 0, 6); | |
757 glFlush(); | |
758 | |
759 const uint8_t kBlack[1 * 4] = {0u, 0u, 0u, 255u}; | |
760 const uint8_t kRed[1 * 4] = {255u, 0u, 0u, 255u}; | |
761 const uint8_t kBlue[1 * 4] = {0u, 0u, 255u, 255u}; | |
762 | |
763 // Note that while destination texture is 8 x 8 pixels the viewport is only | |
764 // 4 x 4. | |
765 GLTestHelper::CheckPixels(0, 0, 4, 2, 0, kRed); | |
766 GLTestHelper::CheckPixels(0, 2, 2, 2, 0, kBlue); | |
767 GLTestHelper::CheckPixels(2, 2, 2, 2, 0, kBlack); | |
768 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | |
769 } | |
770 | |
771 } // namespace gpu | 404 } // namespace gpu |
OLD | NEW |