Mercurial > repos > blastem
comparison render_sdl.c @ 1631:c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 04 Nov 2018 22:51:50 -0800 |
parents | 18a946ec74c8 |
children | 9b7cba9ba541 |
comparison
equal
deleted
inserted
replaced
1630:5aa0c3c43b97 | 1631:c4ba3177b72d |
---|---|
23 #endif | 23 #endif |
24 | 24 |
25 #define MAX_EVENT_POLL_PER_FRAME 2 | 25 #define MAX_EVENT_POLL_PER_FRAME 2 |
26 | 26 |
27 static SDL_Window *main_window; | 27 static SDL_Window *main_window; |
28 static SDL_Window **extra_windows; | |
28 static SDL_Renderer *main_renderer; | 29 static SDL_Renderer *main_renderer; |
30 static SDL_Renderer **extra_renderers; | |
29 static SDL_Texture **sdl_textures; | 31 static SDL_Texture **sdl_textures; |
30 static uint8_t num_textures; | 32 static uint8_t num_textures; |
31 static SDL_Rect main_clip; | 33 static SDL_Rect main_clip; |
32 static SDL_GLContext *main_context; | 34 static SDL_GLContext *main_context; |
33 | 35 |
1033 overscan_right[i] = atoi(val); | 1035 overscan_right[i] = atoi(val); |
1034 } | 1036 } |
1035 } | 1037 } |
1036 } | 1038 } |
1037 } | 1039 } |
1040 render_gl = 0; | |
1038 | 1041 |
1039 #ifndef DISABLE_OPENGL | 1042 #ifndef DISABLE_OPENGL |
1040 char *gl_enabled_str = tern_find_path_default(config, "video\0gl\0", def, TVAL_PTR).ptrval; | 1043 char *gl_enabled_str = tern_find_path_default(config, "video\0gl\0", def, TVAL_PTR).ptrval; |
1041 uint8_t gl_enabled = strcmp(gl_enabled_str, "off") != 0; | 1044 uint8_t gl_enabled = strcmp(gl_enabled_str, "off") != 0; |
1042 if (gl_enabled) | 1045 if (gl_enabled) |
1321 free(screenshot_path); | 1324 free(screenshot_path); |
1322 } | 1325 } |
1323 screenshot_path = path; | 1326 screenshot_path = path; |
1324 } | 1327 } |
1325 | 1328 |
1329 uint8_t render_create_window(char *caption, uint32_t width, uint32_t height) | |
1330 { | |
1331 num_textures++; | |
1332 sdl_textures = realloc(sdl_textures, num_textures * sizeof(*sdl_textures)); | |
1333 extra_windows = realloc(extra_windows, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*extra_windows)); | |
1334 extra_renderers = realloc(extra_renderers, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*extra_renderers)); | |
1335 uint8_t win_idx = num_textures - FRAMEBUFFER_USER_START - 1; | |
1336 extra_windows[win_idx] = SDL_CreateWindow(caption, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, 0); | |
1337 if (!extra_windows[win_idx]) { | |
1338 goto fail_window; | |
1339 } | |
1340 extra_renderers[win_idx] = SDL_CreateRenderer(extra_windows[win_idx], -1, SDL_RENDERER_ACCELERATED); | |
1341 if (!extra_renderers[win_idx]) { | |
1342 goto fail_renderer; | |
1343 } | |
1344 uint8_t texture_idx = num_textures-1; | |
1345 sdl_textures[texture_idx] = SDL_CreateTexture(extra_renderers[win_idx], SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height); | |
1346 if (!sdl_textures[texture_idx]) { | |
1347 goto fail_texture; | |
1348 } | |
1349 return texture_idx; | |
1350 | |
1351 fail_texture: | |
1352 SDL_DestroyRenderer(extra_renderers[win_idx]); | |
1353 fail_renderer: | |
1354 SDL_DestroyWindow(extra_windows[win_idx]); | |
1355 fail_window: | |
1356 num_textures--; | |
1357 return 0; | |
1358 } | |
1359 | |
1326 uint32_t *locked_pixels; | 1360 uint32_t *locked_pixels; |
1327 uint32_t locked_pitch; | 1361 uint32_t locked_pitch; |
1328 uint32_t *render_get_framebuffer(uint8_t which, int *pitch) | 1362 uint32_t *render_get_framebuffer(uint8_t which, int *pitch) |
1329 { | 1363 { |
1330 #ifndef DISABLE_OPENGL | 1364 #ifndef DISABLE_OPENGL |
1465 SDL_UnlockTexture(sdl_textures[which]); | 1499 SDL_UnlockTexture(sdl_textures[which]); |
1466 #ifndef DISABLE_OPENGL | 1500 #ifndef DISABLE_OPENGL |
1467 } | 1501 } |
1468 #endif | 1502 #endif |
1469 last_height = height; | 1503 last_height = height; |
1470 render_update_display(); | 1504 if (which <= FRAMEBUFFER_EVEN) { |
1505 render_update_display(); | |
1506 } else { | |
1507 SDL_RenderCopy(extra_renderers[which - FRAMEBUFFER_USER_START], sdl_textures[which], NULL, NULL); | |
1508 SDL_RenderPresent(extra_renderers[which - FRAMEBUFFER_USER_START]); | |
1509 } | |
1471 if (screenshot_file) { | 1510 if (screenshot_file) { |
1472 fclose(screenshot_file); | 1511 fclose(screenshot_file); |
1473 } | 1512 } |
1474 if (which <= FRAMEBUFFER_EVEN) { | 1513 if (which <= FRAMEBUFFER_EVEN) { |
1475 last = which; | 1514 last = which; |
1833 | 1872 |
1834 uint8_t render_has_gl(void) | 1873 uint8_t render_has_gl(void) |
1835 { | 1874 { |
1836 return render_gl; | 1875 return render_gl; |
1837 } | 1876 } |
1877 | |
1878 uint8_t render_get_active_framebuffer(void) | |
1879 { | |
1880 if (SDL_GetWindowFlags(main_window) & SDL_WINDOW_INPUT_FOCUS) { | |
1881 return FRAMEBUFFER_ODD; | |
1882 } | |
1883 for (int i = 0; i < num_textures - 2; i++) | |
1884 { | |
1885 if (extra_windows[i] && (SDL_GetWindowFlags(extra_windows[i]) & SDL_WINDOW_INPUT_FOCUS)) { | |
1886 return FRAMEBUFFER_USER_START + i; | |
1887 } | |
1888 } | |
1889 return 0xFF; | |
1890 } |