OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkSLCompiler.h" | 8 #include "SkSLCompiler.h" |
9 | 9 |
10 #include "Test.h" | 10 #include "Test.h" |
11 | 11 |
12 static void test(skiatest::Reporter* r, const char* src, SkSL::GLCaps caps, cons
t char* expected) { | 12 static void test(skiatest::Reporter* r, const char* src, SkSL::GLCaps caps, cons
t char* expected) { |
13 SkSL::Compiler compiler; | 13 SkSL::Compiler compiler; |
14 std::string output; | 14 std::string output; |
15 bool result = compiler.toGLSL(SkSL::Program::kFragment_Kind, src, caps, &out
put); | 15 bool result = compiler.toGLSL(SkSL::Program::kFragment_Kind, src, caps, &out
put); |
16 if (!result) { | 16 if (!result) { |
17 SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().
c_str()); | 17 SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().
c_str()); |
18 } | 18 } |
19 REPORTER_ASSERT(r, result); | 19 REPORTER_ASSERT(r, result); |
20 if (result) { | 20 if (result) { |
21 if (output != expected) { | 21 if (output != expected) { |
22 SkDebugf("GLSL MISMATCH:\nsource:\n%s\n\nexpected:\n'%s'\n\nreceived
:\n'%s'", src, | 22 SkDebugf("GLSL MISMATCH:\nsource:\n%s\n\nexpected:\n'%s'\n\nreceived
:\n'%s'", src, |
23 expected, output.c_str()); | 23 expected, output.c_str()); |
24 } | 24 } |
25 REPORTER_ASSERT(r, output == expected); | 25 REPORTER_ASSERT(r, output == expected); |
26 } | 26 } |
27 } | 27 } |
28 | 28 |
29 static SkSL::GLCaps default_caps() { | 29 static SkSL::GLCaps default_caps() { |
30 return { | 30 return SkSL::GLCaps(); |
31 400, | |
32 SkSL::GLCaps::kGL_Standard, | |
33 false, // isCoreProfile | |
34 false, // usesPrecisionModifiers; | |
35 false, // mustDeclareFragmentShaderOutput | |
36 true, // canUseMinAndAbsTogether | |
37 false // mustForceNegatedAtanParamToFloat | |
38 }; | |
39 } | 31 } |
40 | 32 |
41 DEF_TEST(SkSLHelloWorld, r) { | 33 DEF_TEST(SkSLHelloWorld, r) { |
42 test(r, | 34 test(r, |
43 "void main() { sk_FragColor = vec4(0.75); }", | 35 "void main() { sk_FragColor = vec4(0.75); }", |
44 default_caps(), | 36 default_caps(), |
45 "#version 400\n" | 37 "#version 400\n" |
46 "void main() {\n" | 38 "void main() {\n" |
47 " gl_FragColor = vec4(0.75);\n" | 39 " gl_FragColor = vec4(0.75);\n" |
48 "}\n"); | 40 "}\n"); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 test(r, | 372 test(r, |
381 "float test1[] = float[](1, 2, 3, 4);" | 373 "float test1[] = float[](1, 2, 3, 4);" |
382 "vec2 test2[] = vec2[](vec2(1, 2), vec2(3, 4));" | 374 "vec2 test2[] = vec2[](vec2(1, 2), vec2(3, 4));" |
383 "mat4 test3[] = mat4[]();", | 375 "mat4 test3[] = mat4[]();", |
384 default_caps(), | 376 default_caps(), |
385 "#version 400\n" | 377 "#version 400\n" |
386 "float test1[] = float[](1.0, 2.0, 3.0, 4.0);\n" | 378 "float test1[] = float[](1.0, 2.0, 3.0, 4.0);\n" |
387 "vec2 test2[] = vec2[](vec2(1.0, 2.0), vec2(3.0, 4.0));\n" | 379 "vec2 test2[] = vec2[](vec2(1.0, 2.0), vec2(3.0, 4.0));\n" |
388 "mat4 test3[] = mat4[]();\n"); | 380 "mat4 test3[] = mat4[]();\n"); |
389 } | 381 } |
| 382 |
| 383 DEF_TEST(SkSLDerivatives, r) { |
| 384 test(r, |
| 385 "void main() { float x = dFdx(1); }", |
| 386 default_caps(), |
| 387 "#version 400\n" |
| 388 "void main() {\n" |
| 389 " float x = dFdx(1.0);\n" |
| 390 "}\n"); |
| 391 SkSL::GLCaps caps = default_caps(); |
| 392 caps.fShaderDerivativeExtensionString = "GL_OES_standard_derivatives"; |
| 393 test(r, |
| 394 "void main() { float x = 1; }", |
| 395 caps, |
| 396 "#version 400\n" |
| 397 "void main() {\n" |
| 398 " float x = 1.0;\n" |
| 399 "}\n"); |
| 400 test(r, |
| 401 "void main() { float x = dFdx(1); }", |
| 402 caps, |
| 403 "#version 400\n" |
| 404 "#extension GL_OES_standard_derivatives : require\n" |
| 405 "void main() {\n" |
| 406 " float x = dFdx(1.0);\n" |
| 407 "}\n"); |
| 408 } |
OLD | NEW |