comparison render_sdl.c @ 1839:78abbabfd58d

Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
author Michael Pavone <pavone@retrodev.com>
date Sun, 14 Apr 2019 23:37:11 -0700
parents 56a1171e29b9
children 419b458f93cd
comparison
equal deleted inserted replaced
1836:601ef72cc16f 1839:78abbabfd58d
495 "#define highp\n"; 495 "#define highp\n";
496 #endif 496 #endif
497 497
498 static GLuint load_shader(char * fname, GLenum shader_type) 498 static GLuint load_shader(char * fname, GLenum shader_type)
499 { 499 {
500 char * shader_path;
501 FILE *f;
502 GLchar *text;
503 long fsize;
504 #ifndef __ANDROID__
500 char const * parts[] = {get_home_dir(), "/.config/blastem/shaders/", fname}; 505 char const * parts[] = {get_home_dir(), "/.config/blastem/shaders/", fname};
501 char * shader_path = alloc_concat_m(3, parts); 506 shader_path = alloc_concat_m(3, parts);
502 FILE * f = fopen(shader_path, "rb"); 507 f = fopen(shader_path, "rb");
503 free(shader_path); 508 free(shader_path);
504 GLchar * text;
505 long fsize;
506 if (f) { 509 if (f) {
507 fsize = file_size(f); 510 fsize = file_size(f);
508 text = malloc(fsize); 511 text = malloc(fsize);
509 if (fread(text, 1, fsize, f) != fsize) { 512 if (fread(text, 1, fsize, f) != fsize) {
510 warning("Error reading from shader file %s\n", fname); 513 warning("Error reading from shader file %s\n", fname);
511 free(text); 514 free(text);
512 return 0; 515 return 0;
513 } 516 }
514 } else { 517 } else {
518 #endif
515 shader_path = path_append("shaders", fname); 519 shader_path = path_append("shaders", fname);
516 uint32_t fsize32; 520 uint32_t fsize32;
517 text = read_bundled_file(shader_path, &fsize32); 521 text = read_bundled_file(shader_path, &fsize32);
518 free(shader_path); 522 free(shader_path);
519 if (!text) { 523 if (!text) {
520 warning("Failed to open shader file %s for reading\n", fname); 524 warning("Failed to open shader file %s for reading\n", fname);
521 return 0; 525 return 0;
522 } 526 }
523 fsize = fsize32; 527 fsize = fsize32;
524 } 528 #ifndef __ANDROID__
529 }
530 #endif
525 text[fsize] = 0; 531 text[fsize] = 0;
526 532
527 if (strncmp(text, "#version", strlen("#version"))) { 533 if (strncmp(text, "#version", strlen("#version"))) {
528 GLchar *tmp = text; 534 GLchar *tmp = text;
529 text = alloc_concat(shader_prefix, tmp); 535 text = alloc_concat(shader_prefix, tmp);
1188 vsync = NULL; 1194 vsync = NULL;
1189 } 1195 }
1190 } 1196 }
1191 if (vsync) { 1197 if (vsync) {
1192 if (SDL_GL_SetSwapInterval(!strcmp("on", vsync)) < 0) { 1198 if (SDL_GL_SetSwapInterval(!strcmp("on", vsync)) < 0) {
1199 #ifdef __ANDROID__
1200 debug_message("Failed to set vsync to %s: %s\n", vsync, SDL_GetError());
1201 #else
1193 warning("Failed to set vsync to %s: %s\n", vsync, SDL_GetError()); 1202 warning("Failed to set vsync to %s: %s\n", vsync, SDL_GetError());
1203 #endif
1194 } 1204 }
1195 } 1205 }
1196 } else { 1206 } else {
1197 warning("OpenGL 2.0 is unavailable, falling back to SDL2 renderer\n"); 1207 warning("OpenGL 2.0 is unavailable, falling back to SDL2 renderer\n");
1198 } 1208 }
1681 frame_counter++; 1691 frame_counter++;
1682 last_frame= SDL_GetTicks(); 1692 last_frame= SDL_GetTicks();
1683 if ((last_frame - start) > FPS_INTERVAL) { 1693 if ((last_frame - start) > FPS_INTERVAL) {
1684 if (start && (last_frame-start)) { 1694 if (start && (last_frame-start)) {
1685 #ifdef __ANDROID__ 1695 #ifdef __ANDROID__
1686 info_message("%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0)); 1696 debug_message("%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0));
1687 #else 1697 #else
1688 if (!fps_caption) { 1698 if (!fps_caption) {
1689 fps_caption = malloc(strlen(caption) + strlen(" - 100000000.1 fps") + 1); 1699 fps_caption = malloc(strlen(caption) + strlen(" - 100000000.1 fps") + 1);
1690 } 1700 }
1691 sprintf(fps_caption, "%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0)); 1701 sprintf(fps_caption, "%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0));