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 | 8 |
| 9 #include "gpu/command_buffer/service/context_group.h" |
8 #include "gpu/command_buffer/tests/gl_manager.h" | 10 #include "gpu/command_buffer/tests/gl_manager.h" |
9 #include "gpu/command_buffer/tests/gl_test_utils.h" | 11 #include "gpu/command_buffer/tests/gl_test_utils.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 #define SHADER(Src) #Src | 15 #define SHADER(Src) #Src |
14 | 16 |
15 namespace gpu { | 17 namespace gpu { |
16 | 18 |
17 class GLProgramTest : public testing::Test { | 19 class GLProgramTest : public testing::Test { |
(...skipping 162 matching lines...) Loading... |
180 | 182 |
181 // We specifically don't call UseProgram again. | 183 // We specifically don't call UseProgram again. |
182 GLuint position_loc = glGetAttribLocation(program, "a_position"); | 184 GLuint position_loc = glGetAttribLocation(program, "a_position"); |
183 GLTestHelper::SetupUnitQuad(position_loc); | 185 GLTestHelper::SetupUnitQuad(position_loc); |
184 glDrawArrays(GL_TRIANGLES, 0, 6); | 186 glDrawArrays(GL_TRIANGLES, 0, 6); |
185 uint8 expected_color[] = { 0, 0, 255, 255, }; | 187 uint8 expected_color[] = { 0, 0, 255, 255, }; |
186 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color)); | 188 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color)); |
187 GLTestHelper::CheckGLError("no errors", __LINE__); | 189 GLTestHelper::CheckGLError("no errors", __LINE__); |
188 } | 190 } |
189 | 191 |
| 192 TEST_F(GLProgramTest, DeferCompileWithExt) { |
| 193 // This test must have extensions enabled. |
| 194 gles2::ContextGroup* context_group = gl_.decoder()->GetContextGroup(); |
| 195 gles2::FeatureInfo* feature_info = context_group->feature_info(); |
| 196 const gles2::FeatureInfo::FeatureFlags& flags = feature_info->feature_flags(); |
| 197 if (!flags.ext_frag_depth) |
| 198 return; |
| 199 |
| 200 static const char* v_shdr_str = R"( |
| 201 attribute vec4 vPosition; |
| 202 void main() |
| 203 { |
| 204 gl_Position = vPosition; |
| 205 } |
| 206 )"; |
| 207 static const char* f_shdr_str = R"( |
| 208 #extension GL_EXT_frag_depth : enable |
| 209 void main() |
| 210 { |
| 211 gl_FragDepthEXT = 1.0; |
| 212 } |
| 213 )"; |
| 214 |
| 215 // First compile and link to be shader compiles. |
| 216 GLuint vs_good = GLTestHelper::CompileShader(GL_VERTEX_SHADER, v_shdr_str); |
| 217 GLuint fs_good = GLTestHelper::CompileShader(GL_FRAGMENT_SHADER, f_shdr_str); |
| 218 GLuint program_good = GLTestHelper::LinkProgram(vs_good, fs_good); |
| 219 GLint linked_good = 0; |
| 220 glGetProgramiv(program_good, GL_LINK_STATUS, &linked_good); |
| 221 EXPECT_NE(0, linked_good); |
| 222 |
| 223 // Disable extension and be sure shader no longer compiles. |
| 224 ASSERT_TRUE(glEnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation")); |
| 225 GLuint vs_bad = GLTestHelper::CompileShader(GL_VERTEX_SHADER, v_shdr_str); |
| 226 GLuint fs_bad = GLTestHelper::CompileShader(GL_FRAGMENT_SHADER, f_shdr_str); |
| 227 GLuint program_bad = GLTestHelper::LinkProgram(vs_bad, fs_bad); |
| 228 GLint linked_bad = 0; |
| 229 glGetProgramiv(program_bad, GL_LINK_STATUS, &linked_bad); |
| 230 EXPECT_EQ(0, linked_bad); |
| 231 |
| 232 // Relinking good compilations without extension disabled should still link. |
| 233 GLuint program_defer_good = GLTestHelper::LinkProgram(vs_good, fs_good); |
| 234 GLint linked_defer_good = 0; |
| 235 glGetProgramiv(program_defer_good, GL_LINK_STATUS, &linked_defer_good); |
| 236 EXPECT_NE(0, linked_defer_good); |
| 237 |
| 238 // linking bad compilations with extension enabled should still not link. |
| 239 GLuint vs_bad2 = GLTestHelper::CompileShader(GL_VERTEX_SHADER, v_shdr_str); |
| 240 GLuint fs_bad2 = GLTestHelper::CompileShader(GL_FRAGMENT_SHADER, f_shdr_str); |
| 241 glRequestExtensionCHROMIUM("GL_EXT_frag_depth"); |
| 242 GLuint program_bad2 = GLTestHelper::LinkProgram(vs_bad2, fs_bad2); |
| 243 GLint linked_bad2 = 0; |
| 244 glGetProgramiv(program_bad2, GL_LINK_STATUS, &linked_bad2); |
| 245 EXPECT_EQ(0, linked_bad2); |
| 246 |
| 247 // Be sure extension was actually turned on by recompiling. |
| 248 GLuint vs_good2 = GLTestHelper::LoadShader(GL_VERTEX_SHADER, v_shdr_str); |
| 249 GLuint fs_good2 = GLTestHelper::LoadShader(GL_FRAGMENT_SHADER, f_shdr_str); |
| 250 GLuint program_good2 = GLTestHelper::SetupProgram(vs_good2, fs_good2); |
| 251 EXPECT_NE(0u, program_good2); |
| 252 } |
| 253 |
190 } // namespace gpu | 254 } // namespace gpu |
191 | 255 |
OLD | NEW |