OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <GLES2/gl2.h> |
| 6 #include <GLES2/gl2ext.h> |
| 7 |
| 8 #include "gpu/command_buffer/tests/gl_manager.h" |
| 9 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 #define SHADER(Src) #Src |
| 14 |
| 15 namespace gpu { |
| 16 |
| 17 class ConsistenUniformLocationsTest : public testing::Test { |
| 18 protected: |
| 19 static const GLsizei kResolution = 4; |
| 20 virtual void SetUp() { |
| 21 gl_.Initialize(gfx::Size(kResolution, kResolution)); |
| 22 } |
| 23 |
| 24 virtual void TearDown() { |
| 25 gl_.Destroy(); |
| 26 } |
| 27 |
| 28 GLManager gl_; |
| 29 }; |
| 30 |
| 31 namespace { |
| 32 |
| 33 struct FormatType { |
| 34 GLenum format; |
| 35 GLenum type; |
| 36 }; |
| 37 |
| 38 } // anonymous namespace |
| 39 |
| 40 TEST_F(ConsistenUniformLocationsTest, Basic) { |
| 41 ASSERT_TRUE( |
| 42 GLTestHelper::HasExtension("GL_CHROMIUM_consistent_uniform_locations")); |
| 43 |
| 44 static const char* v_shader_str = SHADER( |
| 45 attribute vec4 a_position; |
| 46 void main() |
| 47 { |
| 48 gl_Position = a_position; |
| 49 } |
| 50 ); |
| 51 static const char* f_shader_str = SHADER( |
| 52 precision mediump float; |
| 53 uniform vec4 u_colorC; |
| 54 uniform vec4 u_colorB[2]; |
| 55 uniform vec4 u_colorA; |
| 56 void main() |
| 57 { |
| 58 gl_FragColor = u_colorA + u_colorB[0] + u_colorB[1] + u_colorC; |
| 59 } |
| 60 ); |
| 61 |
| 62 static const GLUniformDefinitionCHROMIUM defs[] = { |
| 63 { GL_FLOAT_VEC4, 1, "u_colorC", }, |
| 64 { GL_FLOAT_VEC4, 2, "u_colorB", }, |
| 65 { GL_FLOAT_VEC4, 1, "u_colorA", }, |
| 66 }; |
| 67 |
| 68 GLint locations[4]; |
| 69 |
| 70 glGetUniformLocationsCHROMIUM( |
| 71 defs, arraysize(defs), arraysize(locations), locations); |
| 72 |
| 73 GLint u_colorCLocation = locations[0]; |
| 74 GLint u_colorB0Location = locations[1]; |
| 75 GLint u_colorB1Location = locations[2]; |
| 76 GLint u_colorALocation = locations[3]; |
| 77 |
| 78 GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str); |
| 79 |
| 80 GLint position_loc = glGetAttribLocation(program, "a_position"); |
| 81 |
| 82 GLTestHelper::SetupUnitQuad(position_loc); |
| 83 |
| 84 glUseProgram(program); |
| 85 |
| 86 glUniform4f(u_colorALocation, 0.25f, 0.0f, 0.0f, 0.0f); |
| 87 glUniform4f(u_colorB0Location, 0.0f, 0.50f, 0.0f, 0.0f); |
| 88 glUniform4f(u_colorB1Location, 0.0f, 0.0f, 0.75f, 0.0f); |
| 89 glUniform4f(u_colorCLocation, 0.0f, 0.0f, 0.0f, 1.0f); |
| 90 |
| 91 glDrawArrays(GL_TRIANGLES, 0, 6); |
| 92 |
| 93 static const uint8 expected[] = { 64, 128, 192, 255 }; |
| 94 EXPECT_TRUE( |
| 95 GLTestHelper::CheckPixels(0, 0, kResolution, kResolution, 1, expected)); |
| 96 |
| 97 GLTestHelper::CheckGLError("no errors", __LINE__); |
| 98 } |
| 99 |
| 100 } // namespace gpu |
| 101 |
| 102 |
| 103 |
OLD | NEW |