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 #include <GLES2/gl2extchromium.h> | 7 #include <GLES2/gl2extchromium.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "gpu/command_buffer/service/context_group.h" | 10 #include "gpu/command_buffer/service/context_group.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 { | 114 { |
115 gl_FragColor = vec4(0, 0, 1, 1); | 115 gl_FragColor = vec4(0, 0, 1, 1); |
116 } | 116 } |
117 ); | 117 ); |
118 | 118 |
119 // Load the program. | 119 // Load the program. |
120 GLuint vs = GLTestHelper::LoadShader(GL_VERTEX_SHADER, v_shader_str); | 120 GLuint vs = GLTestHelper::LoadShader(GL_VERTEX_SHADER, v_shader_str); |
121 GLuint fs = GLTestHelper::LoadShader(GL_FRAGMENT_SHADER, f_red_shader_str); | 121 GLuint fs = GLTestHelper::LoadShader(GL_FRAGMENT_SHADER, f_red_shader_str); |
122 GLuint program = GLTestHelper::SetupProgram(vs, fs); | 122 GLuint program = GLTestHelper::SetupProgram(vs, fs); |
123 glUseProgram(program); | 123 glUseProgram(program); |
124 glShaderSource(fs, 1, &f_blue_shader_str, NULL); | 124 glShaderSource(fs, 1, &f_blue_shader_str, nullptr); |
125 glCompileShader(fs); | 125 glCompileShader(fs); |
126 glLinkProgram(program); | 126 glLinkProgram(program); |
127 // We specifically don't call UseProgram again. | 127 // We specifically don't call UseProgram again. |
128 GLuint position_loc = glGetAttribLocation(program, "a_position"); | 128 GLuint position_loc = glGetAttribLocation(program, "a_position"); |
129 GLTestHelper::SetupUnitQuad(position_loc); | 129 GLTestHelper::SetupUnitQuad(position_loc); |
130 glDrawArrays(GL_TRIANGLES, 0, 6); | 130 glDrawArrays(GL_TRIANGLES, 0, 6); |
131 uint8_t expected_color[] = { | 131 uint8_t expected_color[] = { |
132 0, 0, 255, 255, | 132 0, 0, 255, 255, |
133 }; | 133 }; |
134 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color)); | 134 EXPECT_TRUE( |
| 135 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color, nullptr)); |
135 GLTestHelper::CheckGLError("no errors", __LINE__); | 136 GLTestHelper::CheckGLError("no errors", __LINE__); |
136 } | 137 } |
137 | 138 |
138 TEST_F(GLProgramTest, ShaderLengthSpecified) { | 139 TEST_F(GLProgramTest, ShaderLengthSpecified) { |
139 const std::string valid_shader_str = SHADER( | 140 const std::string valid_shader_str = SHADER( |
140 attribute vec4 a_position; | 141 attribute vec4 a_position; |
141 void main() | 142 void main() |
142 { | 143 { |
143 gl_Position = a_position; | 144 gl_Position = a_position; |
144 } | 145 } |
145 ); | 146 ); |
146 | 147 |
147 const std::string invalid_shader = valid_shader_str + "invalid suffix"; | 148 const std::string invalid_shader = valid_shader_str + "invalid suffix"; |
148 | 149 |
149 // Compiling invalid program should fail. | 150 // Compiling invalid program should fail. |
150 const char* invalid_shader_strings[] = { invalid_shader.c_str() }; | 151 const char* invalid_shader_strings[] = { invalid_shader.c_str() }; |
151 GLuint vs = glCreateShader(GL_VERTEX_SHADER); | 152 GLuint vs = glCreateShader(GL_VERTEX_SHADER); |
152 glShaderSource(vs, 1, invalid_shader_strings, NULL); | 153 glShaderSource(vs, 1, invalid_shader_strings, nullptr); |
153 glCompileShader(vs); | 154 glCompileShader(vs); |
154 | 155 |
155 GLint compile_state = 0; | 156 GLint compile_state = 0; |
156 glGetShaderiv(vs, GL_COMPILE_STATUS, &compile_state); | 157 glGetShaderiv(vs, GL_COMPILE_STATUS, &compile_state); |
157 EXPECT_EQ(GL_FALSE, compile_state); | 158 EXPECT_EQ(GL_FALSE, compile_state); |
158 | 159 |
159 // Compiling program cutting off invalid parts should succeed. | 160 // Compiling program cutting off invalid parts should succeed. |
160 const GLint lengths[] = { valid_shader_str.length() }; | 161 const GLint lengths[] = { valid_shader_str.length() }; |
161 glShaderSource(vs, 1, invalid_shader_strings, lengths); | 162 glShaderSource(vs, 1, invalid_shader_strings, lengths); |
162 glCompileShader(vs); | 163 glCompileShader(vs); |
(...skipping 29 matching lines...) Expand all Loading... |
192 GLint color_location = glGetUniformLocation(program, "u_color"); | 193 GLint color_location = glGetUniformLocation(program, "u_color"); |
193 glUniform4f(color_location, 0.0f, 0.0f, 1.0f, 1.0f); | 194 glUniform4f(color_location, 0.0f, 0.0f, 1.0f, 1.0f); |
194 | 195 |
195 // We specifically don't call UseProgram again. | 196 // We specifically don't call UseProgram again. |
196 GLuint position_loc = glGetAttribLocation(program, "a_position"); | 197 GLuint position_loc = glGetAttribLocation(program, "a_position"); |
197 GLTestHelper::SetupUnitQuad(position_loc); | 198 GLTestHelper::SetupUnitQuad(position_loc); |
198 glDrawArrays(GL_TRIANGLES, 0, 6); | 199 glDrawArrays(GL_TRIANGLES, 0, 6); |
199 uint8_t expected_color[] = { | 200 uint8_t expected_color[] = { |
200 0, 0, 255, 255, | 201 0, 0, 255, 255, |
201 }; | 202 }; |
202 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color)); | 203 EXPECT_TRUE( |
| 204 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color, nullptr)); |
203 GLTestHelper::CheckGLError("no errors", __LINE__); | 205 GLTestHelper::CheckGLError("no errors", __LINE__); |
204 } | 206 } |
205 | 207 |
206 TEST_F(WebGLProgramTest, DeferCompileWithExt) { | 208 TEST_F(WebGLProgramTest, DeferCompileWithExt) { |
207 // This test must have extensions enabled. | 209 // This test must have extensions enabled. |
208 gles2::ContextGroup* context_group = gl_.decoder()->GetContextGroup(); | 210 gles2::ContextGroup* context_group = gl_.decoder()->GetContextGroup(); |
209 gles2::FeatureInfo* feature_info = context_group->feature_info(); | 211 gles2::FeatureInfo* feature_info = context_group->feature_info(); |
210 const gles2::FeatureInfo::FeatureFlags& flags = feature_info->feature_flags(); | 212 const gles2::FeatureInfo::FeatureFlags& flags = feature_info->feature_flags(); |
211 if (!flags.ext_frag_depth) | 213 if (!flags.ext_frag_depth) |
212 return; | 214 return; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 glDeleteShader(fs); | 277 glDeleteShader(fs); |
276 | 278 |
277 glLinkProgram(program); | 279 glLinkProgram(program); |
278 | 280 |
279 GLint linked = 0; | 281 GLint linked = 0; |
280 glGetProgramiv(program, GL_LINK_STATUS, &linked); | 282 glGetProgramiv(program, GL_LINK_STATUS, &linked); |
281 EXPECT_NE(0, linked); | 283 EXPECT_NE(0, linked); |
282 } | 284 } |
283 | 285 |
284 } // namespace gpu | 286 } // namespace gpu |
OLD | NEW |