OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 glLinkProgram(program); | 114 glLinkProgram(program); |
115 // We specifically don't call UseProgram again. | 115 // We specifically don't call UseProgram again. |
116 GLuint position_loc = glGetAttribLocation(program, "a_position"); | 116 GLuint position_loc = glGetAttribLocation(program, "a_position"); |
117 GLTestHelper::SetupUnitQuad(position_loc); | 117 GLTestHelper::SetupUnitQuad(position_loc); |
118 glDrawArrays(GL_TRIANGLES, 0, 6); | 118 glDrawArrays(GL_TRIANGLES, 0, 6); |
119 uint8 expected_color[] = { 0, 0, 255, 255, }; | 119 uint8 expected_color[] = { 0, 0, 255, 255, }; |
120 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color)); | 120 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color)); |
121 GLTestHelper::CheckGLError("no errors", __LINE__); | 121 GLTestHelper::CheckGLError("no errors", __LINE__); |
122 } | 122 } |
123 | 123 |
| 124 TEST_F(GLProgramTest, ShaderLengthSpecified) { |
| 125 const std::string valid_shader_str = SHADER( |
| 126 attribute vec4 a_position; |
| 127 void main() |
| 128 { |
| 129 gl_Position = a_position; |
| 130 } |
| 131 ); |
| 132 |
| 133 const std::string invalid_shader = valid_shader_str + "invalid suffix"; |
| 134 |
| 135 // Compiling invalid program should fail. |
| 136 const char* invalid_shader_strings[] = { invalid_shader.c_str() }; |
| 137 GLuint vs = glCreateShader(GL_VERTEX_SHADER); |
| 138 glShaderSource(vs, 1, invalid_shader_strings, NULL); |
| 139 glCompileShader(vs); |
| 140 |
| 141 GLint compile_state = 0; |
| 142 glGetShaderiv(vs, GL_COMPILE_STATUS, &compile_state); |
| 143 EXPECT_EQ(GL_FALSE, compile_state); |
| 144 |
| 145 // Compiling program cutting off invalid parts should succeed. |
| 146 const GLint lengths[] = { valid_shader_str.length() }; |
| 147 glShaderSource(vs, 1, invalid_shader_strings, lengths); |
| 148 glCompileShader(vs); |
| 149 glGetShaderiv(vs, GL_COMPILE_STATUS, &compile_state); |
| 150 EXPECT_EQ(GL_TRUE, compile_state); |
| 151 } |
| 152 |
124 TEST_F(GLProgramTest, UniformsInCurrentProgram) { | 153 TEST_F(GLProgramTest, UniformsInCurrentProgram) { |
125 static const char* v_shader_str = SHADER( | 154 static const char* v_shader_str = SHADER( |
126 attribute vec4 a_position; | 155 attribute vec4 a_position; |
127 void main() | 156 void main() |
128 { | 157 { |
129 gl_Position = a_position; | 158 gl_Position = a_position; |
130 } | 159 } |
131 ); | 160 ); |
132 static const char* f_shader_str = SHADER( | 161 static const char* f_shader_str = SHADER( |
133 precision mediump float; | 162 precision mediump float; |
(...skipping 19 matching lines...) Expand all Loading... |
153 GLuint position_loc = glGetAttribLocation(program, "a_position"); | 182 GLuint position_loc = glGetAttribLocation(program, "a_position"); |
154 GLTestHelper::SetupUnitQuad(position_loc); | 183 GLTestHelper::SetupUnitQuad(position_loc); |
155 glDrawArrays(GL_TRIANGLES, 0, 6); | 184 glDrawArrays(GL_TRIANGLES, 0, 6); |
156 uint8 expected_color[] = { 0, 0, 255, 255, }; | 185 uint8 expected_color[] = { 0, 0, 255, 255, }; |
157 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color)); | 186 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color)); |
158 GLTestHelper::CheckGLError("no errors", __LINE__); | 187 GLTestHelper::CheckGLError("no errors", __LINE__); |
159 } | 188 } |
160 | 189 |
161 } // namespace gpu | 190 } // namespace gpu |
162 | 191 |
OLD | NEW |