OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <GLES2/gl2.h> | 5 #include <GLES2/gl2.h> |
6 #include <GLES2/gl2ext.h> | 6 #include <GLES2/gl2ext.h> |
7 #include <GLES2/gl2extchromium.h> | 7 #include <GLES2/gl2extchromium.h> |
8 | 8 |
9 #include "gpu/command_buffer/tests/gl_manager.h" | 9 #include "gpu/command_buffer/tests/gl_manager.h" |
10 #include "gpu/command_buffer/tests/gl_test_utils.h" | 10 #include "gpu/command_buffer/tests/gl_test_utils.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 glDrawArrays(GL_TRIANGLES, 0, 6); | 261 glDrawArrays(GL_TRIANGLES, 0, 6); |
262 | 262 |
263 static const uint8 expected[] = { 204, 204, 204, 204 }; | 263 static const uint8 expected[] = { 204, 204, 204, 204 }; |
264 EXPECT_TRUE( | 264 EXPECT_TRUE( |
265 GLTestHelper::CheckPixels(0, 0, kResolution, kResolution, 1, expected)); | 265 GLTestHelper::CheckPixels(0, 0, kResolution, kResolution, 1, expected)); |
266 | 266 |
267 GLTestHelper::CheckGLError("no errors", __LINE__); | 267 GLTestHelper::CheckGLError("no errors", __LINE__); |
268 | 268 |
269 } | 269 } |
270 | 270 |
| 271 TEST_P(BindUniformLocationTest, UnusedUniformUpdate) { |
| 272 ASSERT_TRUE(GLTestHelper::HasExtension("GL_CHROMIUM_bind_uniform_location")); |
| 273 |
| 274 // clang-format off |
| 275 static const char* kVertexShaderString = SHADER( |
| 276 attribute vec4 a_position; |
| 277 void main() { |
| 278 gl_Position = a_position; |
| 279 } |
| 280 ); |
| 281 static const char* kFragmentShaderString = SHADER( |
| 282 precision mediump float; |
| 283 uniform vec4 u_colorA; |
| 284 uniform float u_colorU; |
| 285 uniform vec4 u_colorC; |
| 286 void main() { |
| 287 gl_FragColor = u_colorA + u_colorC; |
| 288 } |
| 289 ); |
| 290 // clang-format on |
| 291 const GLint kColorULocation = 1; |
| 292 const GLint kNonexistingLocation = 5; |
| 293 const GLint kUnboundLocation = 6; |
| 294 |
| 295 GLuint vertex_shader = |
| 296 GLTestHelper::LoadShader(GL_VERTEX_SHADER, kVertexShaderString); |
| 297 GLuint fragment_shader = |
| 298 GLTestHelper::LoadShader(GL_FRAGMENT_SHADER, kFragmentShaderString); |
| 299 GLuint program = glCreateProgram(); |
| 300 glBindUniformLocationCHROMIUM(program, kColorULocation, "u_colorU"); |
| 301 // The non-existing uniform should behave like existing, but optimized away |
| 302 // uniform. |
| 303 glBindUniformLocationCHROMIUM(program, kNonexistingLocation, "nonexisting"); |
| 304 // Let A and C be assigned automatic locations. |
| 305 glAttachShader(program, vertex_shader); |
| 306 glAttachShader(program, fragment_shader); |
| 307 glLinkProgram(program); |
| 308 GLint linked = 0; |
| 309 glGetProgramiv(program, GL_LINK_STATUS, &linked); |
| 310 EXPECT_EQ(1, linked); |
| 311 glUseProgram(program); |
| 312 |
| 313 // No errors on bound locations, since caller does not know |
| 314 // if the driver optimizes them away or not. |
| 315 glUniform1f(kColorULocation, 0.25f); |
| 316 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 317 |
| 318 // No errors on bound locations of names that do not exist |
| 319 // in the shader. Otherwise it would be inconsistent wrt the |
| 320 // optimization case. |
| 321 glUniform1f(kNonexistingLocation, 0.25f); |
| 322 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 323 |
| 324 // The above are equal to updating -1. |
| 325 glUniform1f(-1, 0.25f); |
| 326 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 327 |
| 328 // No errors when updating with other type either. |
| 329 // The type can not be known with the non-existing case. |
| 330 glUniform2f(kColorULocation, 0.25f, 0.25f); |
| 331 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 332 glUniform2f(kNonexistingLocation, 0.25f, 0.25f); |
| 333 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 334 glUniform2f(-1, 0.25f, 0.25f); |
| 335 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 336 |
| 337 // Ensure that driver or ANGLE has optimized the variable |
| 338 // away and the test tests what it is supposed to. |
| 339 EXPECT_EQ(-1, glGetUniformLocation(program, "u_colorU")); |
| 340 |
| 341 // The bound location gets marked as used and the driver |
| 342 // does not allocate other variables to that location. |
| 343 EXPECT_NE(kColorULocation, glGetUniformLocation(program, "u_colorA")); |
| 344 EXPECT_NE(kColorULocation, glGetUniformLocation(program, "u_colorC")); |
| 345 EXPECT_NE(kNonexistingLocation, glGetUniformLocation(program, "u_colorA")); |
| 346 EXPECT_NE(kNonexistingLocation, glGetUniformLocation(program, "u_colorC")); |
| 347 |
| 348 // Unintuitive: while specifying value works, getting the value does not. |
| 349 GLfloat get_result = 0.0f; |
| 350 glGetUniformfv(program, kColorULocation, &get_result); |
| 351 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); |
| 352 glGetUniformfv(program, kNonexistingLocation, &get_result); |
| 353 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); |
| 354 glGetUniformfv(program, -1, &get_result); |
| 355 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); |
| 356 |
| 357 // Updating an unbound, non-existing location still causes |
| 358 // an error. |
| 359 glUniform1f(kUnboundLocation, 0.25f); |
| 360 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); |
| 361 } |
| 362 |
271 INSTANTIATE_TEST_CASE_P(WithAndWithoutShaderNameMapping, | 363 INSTANTIATE_TEST_CASE_P(WithAndWithoutShaderNameMapping, |
272 BindUniformLocationTest, | 364 BindUniformLocationTest, |
273 ::testing::Bool()); | 365 ::testing::Bool()); |
274 | 366 |
275 } // namespace gpu | 367 } // namespace gpu |
276 | 368 |
277 | 369 |
278 | 370 |
OLD | NEW |