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 "stdio.h" | 8 #include "stdio.h" |
9 #include <fstream> | 9 #include <fstream> |
10 #include "SkSLCompiler.h" | 10 #include "SkSLCompiler.h" |
11 | 11 |
12 bool endsWith(const std::string& s, const std::string& ending) { | 12 bool endsWith(const std::string& s, const std::string& ending) { |
13 if (s.length() >= ending.length()) { | 13 if (s.length() >= ending.length()) { |
14 return (0 == s.compare(s.length() - ending.length(), ending.length(), en
ding)); | 14 return (0 == s.compare(s.length() - ending.length(), ending.length(), en
ding)); |
15 } | 15 } |
16 return false; | 16 return false; |
17 } | 17 } |
18 | 18 |
19 static SkSL::GLCaps default_caps() { | |
20 return { | |
21 400, | |
22 SkSL::GLCaps::kGL_Standard, | |
23 false, // isCoreProfile | |
24 false, // usesPrecisionModifiers; | |
25 false, // mustDeclareFragmentShaderOutput | |
26 true, // canUseMinAndAbsTogether | |
27 false // mustForceNegatedAtanParamToFloat | |
28 }; | |
29 } | |
30 | |
31 /** | 19 /** |
32 * Very simple standalone executable to facilitate testing. | 20 * Very simple standalone executable to facilitate testing. |
33 */ | 21 */ |
34 int main(int argc, const char** argv) { | 22 int main(int argc, const char** argv) { |
35 if (argc != 3) { | 23 if (argc != 3) { |
36 printf("usage: skslc <input> <output>\n"); | 24 printf("usage: skslc <input> <output>\n"); |
37 exit(1); | 25 exit(1); |
38 } | 26 } |
39 SkSL::Program::Kind kind; | 27 SkSL::Program::Kind kind; |
40 size_t len = strlen(argv[1]); | 28 size_t len = strlen(argv[1]); |
(...skipping 21 matching lines...) Expand all Loading... |
62 printf("%s", compiler.errorText().c_str()); | 50 printf("%s", compiler.errorText().c_str()); |
63 exit(3); | 51 exit(3); |
64 } | 52 } |
65 if (out.rdstate()) { | 53 if (out.rdstate()) { |
66 printf("error writing '%s'\n", argv[2]); | 54 printf("error writing '%s'\n", argv[2]); |
67 exit(4); | 55 exit(4); |
68 } | 56 } |
69 } else if (endsWith(name, ".glsl")) { | 57 } else if (endsWith(name, ".glsl")) { |
70 std::ofstream out(argv[2], std::ofstream::binary); | 58 std::ofstream out(argv[2], std::ofstream::binary); |
71 SkSL::Compiler compiler; | 59 SkSL::Compiler compiler; |
72 if (!compiler.toGLSL(kind, text, default_caps(), out)) { | 60 if (!compiler.toGLSL(kind, text, SkSL::GLCaps(), out)) { |
73 printf("%s", compiler.errorText().c_str()); | 61 printf("%s", compiler.errorText().c_str()); |
74 exit(3); | 62 exit(3); |
75 } | 63 } |
76 if (out.rdstate()) { | 64 if (out.rdstate()) { |
77 printf("error writing '%s'\n", argv[2]); | 65 printf("error writing '%s'\n", argv[2]); |
78 exit(4); | 66 exit(4); |
79 } | 67 } |
80 } else { | 68 } else { |
81 printf("expected output filename to end with '.spirv' or '.glsl'"); | 69 printf("expected output filename to end with '.spirv' or '.glsl'"); |
82 } | 70 } |
83 } | 71 } |
OLD | NEW |