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