53 IS_COMMENT_MAYBE_BEG = 3,
54 IS_COMMENT_MAYBE_END = 4,
58 int offset_checkpoint = 0;
59 int newlines_checkpoint = 0;
64 while (offset < size) {
65 const char c_curr = getc(fpin);
68 if (context == IS_SPACE) {
69 if (c_curr ==
' ' || c_curr ==
'\t' || c_curr ==
'\n') {
72 else if (c_curr ==
'/') {
73 context = IS_COMMENT_MAYBE_BEG;
80 else if (context == IS_COMMENT) {
82 context = IS_COMMENT_MAYBE_END;
85 else if (context == IS_COMMENT_MAYBE_BEG) {
94 else if (context == IS_COMMENT_MAYBE_END) {
98 else if (c_curr ==
'*') {
102 context = IS_COMMENT;
106 if (c_curr ==
'\n') {
110 if (context == IS_SPACE) {
111 offset_checkpoint = offset;
112 newlines_checkpoint = newlines;
116 if (offset != offset_checkpoint) {
117 fseek(fpin, offset_checkpoint, SEEK_SET);
119 *r_newlines = newlines_checkpoint;
120 return offset_checkpoint;
130 bool strip_leading_c_comments_test =
false;
131 int leading_newlines = 0;
136 "datatoc <data_file_from> <data_file_to> [--options=strip_leading_c_comments]\n");
141 const char *arg_extra = argv[3];
142 const char *arg_transform =
"--options=";
143 if (
STRPREFIX(arg_extra, arg_transform)) {
145 const char *
options = arg_extra + strlen(arg_transform);
146 if (strcmp(
options,
"strip_leading_c_comments") == 0) {
147 strip_leading_c_comments_test =
true;
155 printf(
"Unknown argument <%s>, expected --options=[...] or none.\n", arg_extra);
160 fpin = fopen(argv[1],
"rb");
162 printf(
"Unable to open input <%s>\n", argv[1]);
168 fseek(fpin, 0
L, SEEK_END);
170 fseek(fpin, 0
L, SEEK_SET);
172 if (strip_leading_c_comments_test) {
177 if (argv[1][0] ==
'.') {
182 printf(
"Making C file <%s>\n", argv[2]);
185 argv_len =
int(strlen(argv[1]));
186 for (i = 0; i < argv_len; i++) {
187 if (argv[1][i] ==
'.') {
192 fpout = fopen(argv[2],
"w");
194 fprintf(stderr,
"Unable to open output <%s>\n", argv[2]);
198 fprintf(fpout,
"/* DataToC output of file <%s> */\n\n", argv[1]);
201 fprintf(fpout,
"extern const int datatoc_%s_size;\n", argv[1]);
202 fprintf(fpout,
"extern const char datatoc_%s[];\n\n", argv[1]);
204 fprintf(fpout,
"const int datatoc_%s_size = %d;\n", argv[1],
int(leading_newlines + size));
205 fprintf(fpout,
"const char datatoc_%s[] = {\n", argv[1]);
207 if (leading_newlines) {
208 while (leading_newlines--) {
209 if (leading_newlines % 32 == 31) {
210 fprintf(fpout,
"\n");
212 fprintf(fpout,
"%3d,",
'\n');
214 fprintf(fpout,
"\n");
221 if (size % 32 == 31) {
222 fprintf(fpout,
"\n");
226 fprintf(fpout,
"%3d,", getc(fpin));
232 fprintf(fpout,
"0\n};\n\n");
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int