Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: gpu/command_buffer/tests/gl_program_unittest.cc

Issue 1143393007: Teach GPU command buffer whether a context is webgl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 8
9 #include "gpu/command_buffer/service/context_group.h" 9 #include "gpu/command_buffer/service/context_group.h"
10 #include "gpu/command_buffer/tests/gl_manager.h" 10 #include "gpu/command_buffer/tests/gl_manager.h"
11 #include "gpu/command_buffer/tests/gl_test_utils.h" 11 #include "gpu/command_buffer/tests/gl_test_utils.h"
12 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 #define SHADER(Src) #Src 15 #define SHADER(Src) #Src
16 16
17 namespace gpu { 17 namespace gpu {
18 18
19 class GLProgramTest : public testing::Test { 19 class GLProgramTest : public testing::Test {
20 protected: 20 protected:
21 void SetUp() override { gl_.Initialize(GLManager::Options()); } 21 void SetUp() override { gl_.Initialize(GLManager::Options()); }
22 22
23 void TearDown() override { gl_.Destroy(); } 23 void TearDown() override { gl_.Destroy(); }
24 24
25 GLManager gl_; 25 GLManager gl_;
26 }; 26 };
27 27
28 class WebGLProgramTest : public GLProgramTest {
29 protected:
30 void SetUp() override {
31 GLManager::Options options;
32 options.webgl_version = 1;
33 gl_.Initialize(options);
34 }
35 };
36
28 TEST_F(GLProgramTest, GetSetUniform) { 37 TEST_F(GLProgramTest, GetSetUniform) {
29 static const char* v_shader_str = SHADER( 38 static const char* v_shader_str = SHADER(
30 attribute vec4 a_vertex; 39 attribute vec4 a_vertex;
31 attribute vec3 a_normal; 40 attribute vec3 a_normal;
32 41
33 uniform mat4 u_modelViewProjMatrix; 42 uniform mat4 u_modelViewProjMatrix;
34 43
35 struct MyStruct 44 struct MyStruct
36 { 45 {
37 int x; 46 int x;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 191
183 // We specifically don't call UseProgram again. 192 // We specifically don't call UseProgram again.
184 GLuint position_loc = glGetAttribLocation(program, "a_position"); 193 GLuint position_loc = glGetAttribLocation(program, "a_position");
185 GLTestHelper::SetupUnitQuad(position_loc); 194 GLTestHelper::SetupUnitQuad(position_loc);
186 glDrawArrays(GL_TRIANGLES, 0, 6); 195 glDrawArrays(GL_TRIANGLES, 0, 6);
187 uint8 expected_color[] = { 0, 0, 255, 255, }; 196 uint8 expected_color[] = { 0, 0, 255, 255, };
188 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color)); 197 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color));
189 GLTestHelper::CheckGLError("no errors", __LINE__); 198 GLTestHelper::CheckGLError("no errors", __LINE__);
190 } 199 }
191 200
192 TEST_F(GLProgramTest, DeferCompileWithExt) { 201 TEST_F(WebGLProgramTest, DeferCompileWithExt) {
193 // This test must have extensions enabled. 202 // This test must have extensions enabled.
194 gles2::ContextGroup* context_group = gl_.decoder()->GetContextGroup(); 203 gles2::ContextGroup* context_group = gl_.decoder()->GetContextGroup();
195 gles2::FeatureInfo* feature_info = context_group->feature_info(); 204 gles2::FeatureInfo* feature_info = context_group->feature_info();
196 const gles2::FeatureInfo::FeatureFlags& flags = feature_info->feature_flags(); 205 const gles2::FeatureInfo::FeatureFlags& flags = feature_info->feature_flags();
197 if (!flags.ext_frag_depth) 206 if (!flags.ext_frag_depth)
198 return; 207 return;
199 208
200 static const char* v_shdr_str = R"( 209 static const char* v_shdr_str = R"(
201 attribute vec4 vPosition; 210 attribute vec4 vPosition;
202 void main() 211 void main()
203 { 212 {
204 gl_Position = vPosition; 213 gl_Position = vPosition;
205 } 214 }
206 )"; 215 )";
207 static const char* f_shdr_str = R"( 216 static const char* f_shdr_str = R"(
208 #extension GL_EXT_frag_depth : enable 217 #extension GL_EXT_frag_depth : enable
209 void main() 218 void main()
210 { 219 {
211 gl_FragDepthEXT = 1.0; 220 gl_FragDepthEXT = 1.0;
212 } 221 }
213 )"; 222 )";
214 223
215 // First compile and link to be shader compiles. 224 // Extension is disabled by default and be sure shader does not compile.
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); 225 GLuint vs_bad = GLTestHelper::CompileShader(GL_VERTEX_SHADER, v_shdr_str);
226 GLuint fs_bad = GLTestHelper::CompileShader(GL_FRAGMENT_SHADER, f_shdr_str); 226 GLuint fs_bad = GLTestHelper::CompileShader(GL_FRAGMENT_SHADER, f_shdr_str);
227 GLuint program_bad = GLTestHelper::LinkProgram(vs_bad, fs_bad); 227 GLuint program_bad = GLTestHelper::LinkProgram(vs_bad, fs_bad);
228 GLint linked_bad = 0; 228 GLint linked_bad = 0;
229 glGetProgramiv(program_bad, GL_LINK_STATUS, &linked_bad); 229 glGetProgramiv(program_bad, GL_LINK_STATUS, &linked_bad);
230 EXPECT_EQ(0, linked_bad); 230 EXPECT_EQ(0, linked_bad);
231 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. 232 // 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"); 233 glRequestExtensionCHROMIUM("GL_EXT_frag_depth");
242 GLuint program_bad2 = GLTestHelper::LinkProgram(vs_bad2, fs_bad2); 234 program_bad = GLTestHelper::LinkProgram(vs_bad, fs_bad);
243 GLint linked_bad2 = 0; 235 linked_bad = 0;
244 glGetProgramiv(program_bad2, GL_LINK_STATUS, &linked_bad2); 236 glGetProgramiv(program_bad, GL_LINK_STATUS, &linked_bad);
245 EXPECT_EQ(0, linked_bad2); 237 EXPECT_EQ(0, linked_bad);
246 238
247 // Be sure extension was actually turned on by recompiling. 239 // Be sure extension was actually turned on by recompiling.
248 GLuint vs_good2 = GLTestHelper::LoadShader(GL_VERTEX_SHADER, v_shdr_str); 240 GLuint vs_good = GLTestHelper::LoadShader(GL_VERTEX_SHADER, v_shdr_str);
249 GLuint fs_good2 = GLTestHelper::LoadShader(GL_FRAGMENT_SHADER, f_shdr_str); 241 GLuint fs_good = GLTestHelper::LoadShader(GL_FRAGMENT_SHADER, f_shdr_str);
250 GLuint program_good2 = GLTestHelper::SetupProgram(vs_good2, fs_good2); 242 GLuint program_good = GLTestHelper::SetupProgram(vs_good, fs_good);
251 EXPECT_NE(0u, program_good2); 243 EXPECT_NE(0u, program_good);
252 } 244 }
253 245
254 TEST_F(GLProgramTest, DeleteAttachedShaderLinks) { 246 TEST_F(GLProgramTest, DeleteAttachedShaderLinks) {
255 static const char* v_shdr_str = R"( 247 static const char* v_shdr_str = R"(
256 attribute vec4 vPosition; 248 attribute vec4 vPosition;
257 void main() 249 void main()
258 { 250 {
259 gl_Position = vPosition; 251 gl_Position = vPosition;
260 } 252 }
261 )"; 253 )";
(...skipping 17 matching lines...) Expand all
279 271
280 glLinkProgram(program); 272 glLinkProgram(program);
281 273
282 GLint linked = 0; 274 GLint linked = 0;
283 glGetProgramiv(program, GL_LINK_STATUS, &linked); 275 glGetProgramiv(program, GL_LINK_STATUS, &linked);
284 EXPECT_NE(0, linked); 276 EXPECT_NE(0, linked);
285 } 277 }
286 278
287 } // namespace gpu 279 } // namespace gpu
288 280
OLDNEW
« gpu/command_buffer/service/context_group.h ('K') | « gpu/command_buffer/tests/gl_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698