Mercurial > repos > blastem
comparison render_sdl.c @ 1328:70faad89d491
Add config file option to disable Open GL rendering
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 23 Apr 2017 00:54:33 -0700 |
parents | 071e761bcdcf |
children | baaf05fd64c4 |
comparison
equal
deleted
inserted
replaced
1327:57637d17b59e | 1328:70faad89d491 |
---|---|
384 } | 384 } |
385 } | 385 } |
386 } | 386 } |
387 | 387 |
388 #ifndef DISABLE_OPENGL | 388 #ifndef DISABLE_OPENGL |
389 flags |= SDL_WINDOW_OPENGL; | 389 char *gl_enabled_str = tern_find_path_default(config, "video\0gl\0", def, TVAL_PTR).ptrval; |
390 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); | 390 uint8_t gl_enabled = strcmp(gl_enabled_str, "off") != 0; |
391 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); | 391 if (gl_enabled) |
392 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); | 392 { |
393 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); | 393 flags |= SDL_WINDOW_OPENGL; |
394 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | 394 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); |
395 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); | |
396 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); | |
397 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); | |
398 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | |
399 } | |
395 #endif | 400 #endif |
396 main_window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags); | 401 main_window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags); |
397 if (!main_window) { | 402 if (!main_window) { |
398 fatal_error("Unable to create SDL window: %s\n", SDL_GetError()); | 403 fatal_error("Unable to create SDL window: %s\n", SDL_GetError()); |
399 } | 404 } |
400 #ifndef DISABLE_OPENGL | 405 #ifndef DISABLE_OPENGL |
401 main_context = SDL_GL_CreateContext(main_window); | 406 if (gl_enabled) |
402 GLenum res = glewInit(); | 407 { |
403 if (res != GLEW_OK) { | 408 main_context = SDL_GL_CreateContext(main_window); |
404 warning("Initialization of GLEW failed with code %d\n", res); | 409 GLenum res = glewInit(); |
405 } | 410 if (res != GLEW_OK) { |
406 | 411 warning("Initialization of GLEW failed with code %d\n", res); |
407 if (res == GLEW_OK && GLEW_VERSION_2_0) { | 412 } |
408 render_gl = 1; | 413 |
409 if (!strcmp("tear", vsync)) { | 414 if (res == GLEW_OK && GLEW_VERSION_2_0) { |
410 if (SDL_GL_SetSwapInterval(-1) < 0) { | 415 render_gl = 1; |
411 warning("late tear is not available (%s), using normal vsync\n", SDL_GetError()); | 416 if (!strcmp("tear", vsync)) { |
412 vsync = "on"; | 417 if (SDL_GL_SetSwapInterval(-1) < 0) { |
413 } else { | 418 warning("late tear is not available (%s), using normal vsync\n", SDL_GetError()); |
414 vsync = NULL; | 419 vsync = "on"; |
415 } | 420 } else { |
416 } | 421 vsync = NULL; |
417 if (vsync) { | 422 } |
418 if (SDL_GL_SetSwapInterval(!strcmp("on", vsync)) < 0) { | 423 } |
419 warning("Failed to set vsync to %s: %s\n", vsync, SDL_GetError()); | 424 if (vsync) { |
420 } | 425 if (SDL_GL_SetSwapInterval(!strcmp("on", vsync)) < 0) { |
421 } | 426 warning("Failed to set vsync to %s: %s\n", vsync, SDL_GetError()); |
422 } else { | 427 } |
423 warning("OpenGL 2.0 is unavailable, falling back to SDL2 renderer\n"); | 428 } |
429 } else { | |
430 warning("OpenGL 2.0 is unavailable, falling back to SDL2 renderer\n"); | |
431 } | |
432 } | |
433 if (!render_gl) { | |
424 #endif | 434 #endif |
425 flags = SDL_RENDERER_ACCELERATED; | 435 flags = SDL_RENDERER_ACCELERATED; |
426 if (!strcmp("on", vsync) || !strcmp("tear", vsync)) { | 436 if (!strcmp("on", vsync) || !strcmp("tear", vsync)) { |
427 flags |= SDL_RENDERER_PRESENTVSYNC; | 437 flags |= SDL_RENDERER_PRESENTVSYNC; |
428 } | 438 } |