| 187 | } |
| 188 | |
| 189 | s32 compile(CompileOptions &opts) |
| 190 | { |
| 191 | Buffer buf = opts.read(); |
| 192 | |
| 193 | TempAllocator4096 ta; |
| 194 | JsonObject obj(ta); |
| 195 | RETURN_IF_ERROR(sjson::parse(obj, buf)); |
| 196 | |
| 197 | DynamicString name(ta); |
| 198 | RETURN_IF_ERROR(sjson::parse_string(name, obj["source"])); |
| 199 | RETURN_IF_FILE_MISSING(TEXTURE_RESOURCE, name.c_str(), opts); |
| 200 | opts.fake_read(name.c_str()); |
| 201 | |
| 202 | OutputSettings os; |
| 203 | |
| 204 | if (json_object::has(obj, "generate_mips")) { |
| 205 | os.generate_mips = RETURN_IF_ERROR(sjson::parse_bool(obj["generate_mips"])); |
| 206 | } |
| 207 | if (json_object::has(obj, "normal_map")) { |
| 208 | os.normal_map = RETURN_IF_ERROR(sjson::parse_bool(obj["normal_map"])); |
| 209 | } |
| 210 | |
| 211 | JsonObject output(ta); |
| 212 | if (json_object::has(obj, "output")) { |
| 213 | RETURN_IF_ERROR(sjson::parse_object(output, obj["output"])); |
| 214 | s32 err = parse_output(os, output, opts); |
| 215 | ENSURE_OR_RETURN(TEXTURE_RESOURCE, err == 0, opts); |
| 216 | } |
| 217 | |
| 218 | DynamicString tex_src(ta); |
| 219 | DynamicString tex_out(ta); |
| 220 | opts.absolute_path(tex_src, name.c_str()); |
| 221 | opts.temporary_path(tex_out, "ktx"); |
| 222 | |
| 223 | const char *texturec = opts.exe_path(texturec_paths, countof(texturec_paths)); |
| 224 | RETURN_IF_FALSE(TEXTURE_RESOURCE, texturec != NULL |
| 225 | , opts |
| 226 | , "texturec not found" |
| 227 | ); |
| 228 | |
| 229 | char mipskip[16]; |
| 230 | stbsp_snprintf(mipskip, sizeof(mipskip), "--mipskip %u", os.mip_skip_smallest); |
| 231 | |
| 232 | const char *argv[] = |
| 233 | { |
| 234 | texturec, |
| 235 | "-f", |
| 236 | tex_src.c_str(), |
| 237 | "-o", |
| 238 | tex_out.c_str(), |
| 239 | "-t", |
| 240 | s_texture_formats[os.format].name, |
| 241 | (os.normal_map ? "-n" : ""), |
| 242 | (os.linear ? "--linear" : ""), |
| 243 | (os.premultiply_alpha ? "--pma" : ""), |
| 244 | (os.generate_mips ? "-m" : ""), |
| 245 | (os.mip_skip_smallest > 0 ? "--mipskip" : ""), |
| 246 | (os.mip_skip_smallest > 0 ? mipskip : ""), |
nothing calls this directly
no test coverage detected