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