| 350 | // ── Main ───────────────────────────────────────────────────────────────────── |
| 351 | |
| 352 | int main(int argc, char** argv) { |
| 353 | app_state app; |
| 354 | app.params.n_threads = 4; |
| 355 | app.params.use_gpu = true; |
| 356 | |
| 357 | const char* image_path = nullptr; |
| 358 | |
| 359 | // Parse args |
| 360 | for (int i = 1; i < argc; ++i) { |
| 361 | if (strcmp(argv[i], "--model") == 0 && i+1 < argc) { |
| 362 | app.params.model_path = argv[++i]; |
| 363 | } else if (strcmp(argv[i], "--image") == 0 && i+1 < argc) { |
| 364 | image_path = argv[++i]; |
| 365 | } else if (strcmp(argv[i], "--threads") == 0 && i+1 < argc) { |
| 366 | app.params.n_threads = atoi(argv[++i]); |
| 367 | } else if (strcmp(argv[i], "--no-gpu") == 0) { |
| 368 | app.params.use_gpu = false; |
| 369 | } else if (strcmp(argv[i], "--help") == 0) { |
| 370 | fprintf(stderr, |
| 371 | "Usage: %s --model <path.ggml> [--image <path>]\n" |
| 372 | " [--threads N] [--no-gpu]\n", argv[0]); |
| 373 | return 0; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | if (app.params.model_path.empty()) { |
| 378 | fprintf(stderr, "Error: --model is required.\n"); |
| 379 | return 1; |
| 380 | } |
| 381 | |
| 382 | fprintf(stderr, "Using %d threads\n", app.params.n_threads); |
| 383 | |
| 384 | // ── Init SDL2 + OpenGL ─────────────────────────────────────────────────── |
| 385 | |
| 386 | if (SDL_Init(SDL_INIT_VIDEO) != 0) { |
| 387 | fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError()); |
| 388 | return 1; |
| 389 | } |
| 390 | |
| 391 | #ifdef __APPLE__ |
| 392 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); |
| 393 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); |
| 394 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); |
| 395 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); |
| 396 | const char* glsl_version = "#version 150"; |
| 397 | #else |
| 398 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); |
| 399 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); |
| 400 | const char* glsl_version = "#version 130"; |
| 401 | #endif |
| 402 | |
| 403 | std::string init_title = basename_of(app.params.model_path); |
| 404 | if (image_path) { |
| 405 | init_title = basename_of(image_path) + " \xe2\x80\x94 " + init_title; |
| 406 | } |
| 407 | |
| 408 | SDL_Window* window = SDL_CreateWindow( |
| 409 | init_title.c_str(), |
nothing calls this directly
no test coverage detected