Mercurial > repos > blastem
comparison render_sdl.c @ 1825:56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 04 Apr 2019 23:08:45 -0700 |
parents | 70a1304b432b |
children | 78abbabfd58d |
comparison
equal
deleted
inserted
replaced
1824:62dd62c83b05 | 1825:56a1171e29b9 |
---|---|
552 return ret; | 552 return ret; |
553 } | 553 } |
554 #endif | 554 #endif |
555 | 555 |
556 static uint32_t texture_buf[512 * 513]; | 556 static uint32_t texture_buf[512 * 513]; |
557 #ifndef DISABLE_OPENGL | 557 #ifdef DISABLE_OPENGL |
558 #define RENDER_FORMAT SDL_PIXELFORMAT_ARGB8888 | |
559 #else | |
558 #ifdef USE_GLES | 560 #ifdef USE_GLES |
559 #define INTERNAL_FORMAT GL_RGBA | 561 #define INTERNAL_FORMAT GL_RGBA |
560 #define SRC_FORMAT GL_RGBA | 562 #define SRC_FORMAT GL_RGBA |
561 #define RENDER_FORMAT SDL_PIXELFORMAT_ABGR8888 | 563 #define RENDER_FORMAT SDL_PIXELFORMAT_ABGR8888 |
562 #else | 564 #else |
697 } | 699 } |
698 | 700 |
699 static void update_aspect() | 701 static void update_aspect() |
700 { | 702 { |
701 //reset default values | 703 //reset default values |
704 #ifndef DISABLE_OPENGL | |
702 memcpy(vertex_data, vertex_data_default, sizeof(vertex_data)); | 705 memcpy(vertex_data, vertex_data_default, sizeof(vertex_data)); |
706 #endif | |
703 main_clip.w = main_width; | 707 main_clip.w = main_width; |
704 main_clip.h = main_height; | 708 main_clip.h = main_height; |
705 main_clip.x = main_clip.y = 0; | 709 main_clip.x = main_clip.y = 0; |
706 if (config_aspect() > 0.0f) { | 710 if (config_aspect() > 0.0f) { |
707 float aspect = (float)main_width / main_height; | 711 float aspect = (float)main_width / main_height; |
729 } | 733 } |
730 #endif | 734 #endif |
731 } | 735 } |
732 } | 736 } |
733 | 737 |
734 static ui_render_fun on_context_destroyed, on_context_created; | 738 static ui_render_fun on_context_destroyed, on_context_created, on_ui_fb_resized; |
735 void render_set_gl_context_handlers(ui_render_fun destroy, ui_render_fun create) | 739 void render_set_gl_context_handlers(ui_render_fun destroy, ui_render_fun create) |
736 { | 740 { |
737 on_context_destroyed = destroy; | 741 on_context_destroyed = destroy; |
738 on_context_created = create; | 742 on_context_created = create; |
743 } | |
744 | |
745 void render_set_ui_fb_resize_handler(ui_render_fun resize) | |
746 { | |
747 on_ui_fb_resized = resize; | |
739 } | 748 } |
740 | 749 |
741 static uint8_t scancode_map[SDL_NUM_SCANCODES] = { | 750 static uint8_t scancode_map[SDL_NUM_SCANCODES] = { |
742 [SDL_SCANCODE_A] = 0x1C, | 751 [SDL_SCANCODE_A] = 0x1C, |
743 [SDL_SCANCODE_B] = 0x32, | 752 [SDL_SCANCODE_B] = 0x32, |
904 static uint32_t overscan_top[NUM_VID_STD] = {2, 21}; | 913 static uint32_t overscan_top[NUM_VID_STD] = {2, 21}; |
905 static uint32_t overscan_bot[NUM_VID_STD] = {1, 17}; | 914 static uint32_t overscan_bot[NUM_VID_STD] = {1, 17}; |
906 static uint32_t overscan_left[NUM_VID_STD] = {13, 13}; | 915 static uint32_t overscan_left[NUM_VID_STD] = {13, 13}; |
907 static uint32_t overscan_right[NUM_VID_STD] = {14, 14}; | 916 static uint32_t overscan_right[NUM_VID_STD] = {14, 14}; |
908 static vid_std video_standard = VID_NTSC; | 917 static vid_std video_standard = VID_NTSC; |
918 static uint8_t need_ui_fb_resize; | |
909 | 919 |
910 static int32_t handle_event(SDL_Event *event) | 920 static int32_t handle_event(SDL_Event *event) |
911 { | 921 { |
912 if (custom_event_handler) { | 922 if (custom_event_handler) { |
913 custom_event_handler(event); | 923 custom_event_handler(event); |
972 if (!main_window) { | 982 if (!main_window) { |
973 break; | 983 break; |
974 } | 984 } |
975 main_width = event->window.data1; | 985 main_width = event->window.data1; |
976 main_height = event->window.data2; | 986 main_height = event->window.data2; |
987 need_ui_fb_resize = 1; | |
977 update_aspect(); | 988 update_aspect(); |
978 #ifndef DISABLE_OPENGL | 989 #ifndef DISABLE_OPENGL |
979 if (render_gl) { | 990 if (render_gl) { |
980 if (on_context_destroyed) { | 991 if (on_context_destroyed) { |
981 on_context_destroyed(); | 992 on_context_destroyed(); |
1336 main_height = mode.h; | 1347 main_height = mode.h; |
1337 } else { | 1348 } else { |
1338 main_width = windowed_width; | 1349 main_width = windowed_width; |
1339 main_height = windowed_height; | 1350 main_height = windowed_height; |
1340 } | 1351 } |
1352 if (on_ui_fb_resized) { | |
1353 on_ui_fb_resized(); | |
1354 } | |
1341 | 1355 |
1342 window_setup(); | 1356 window_setup(); |
1343 update_aspect(); | 1357 update_aspect(); |
1344 #ifndef DISABLE_OPENGL | 1358 #ifndef DISABLE_OPENGL |
1345 //need to check render_gl again after window_setup as render option could have changed | 1359 //need to check render_gl again after window_setup as render option could have changed |
1495 if (render_gl && which <= FRAMEBUFFER_EVEN) { | 1509 if (render_gl && which <= FRAMEBUFFER_EVEN) { |
1496 *pitch = LINEBUF_SIZE * sizeof(uint32_t); | 1510 *pitch = LINEBUF_SIZE * sizeof(uint32_t); |
1497 return texture_buf; | 1511 return texture_buf; |
1498 } else { | 1512 } else { |
1499 #endif | 1513 #endif |
1514 if (which == FRAMEBUFFER_UI && which >= num_textures) { | |
1515 sdl_textures = realloc(sdl_textures, sizeof(*sdl_textures) * (FRAMEBUFFER_UI + 1)); | |
1516 for (; num_textures <= FRAMEBUFFER_UI; num_textures++) | |
1517 { | |
1518 sdl_textures[num_textures] = NULL; | |
1519 } | |
1520 } | |
1521 if (which == FRAMEBUFFER_UI && !sdl_textures[which]) { | |
1522 sdl_textures[which] = SDL_CreateTexture(main_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, main_width, main_height); | |
1523 } | |
1500 if (which >= num_textures) { | 1524 if (which >= num_textures) { |
1501 warning("Request for invalid framebuffer number %d\n", which); | 1525 warning("Request for invalid framebuffer number %d\n", which); |
1502 return NULL; | 1526 return NULL; |
1503 } | 1527 } |
1504 void *pixels; | 1528 void *pixels; |
1632 } | 1656 } |
1633 #endif | 1657 #endif |
1634 last_height = height; | 1658 last_height = height; |
1635 if (which <= FRAMEBUFFER_EVEN) { | 1659 if (which <= FRAMEBUFFER_EVEN) { |
1636 render_update_display(); | 1660 render_update_display(); |
1661 } else if (which == FRAMEBUFFER_UI) { | |
1662 SDL_RenderCopy(main_renderer, sdl_textures[which], NULL, NULL); | |
1663 if (need_ui_fb_resize) { | |
1664 SDL_DestroyTexture(sdl_textures[which]); | |
1665 sdl_textures[which] = NULL; | |
1666 if (on_ui_fb_resized) { | |
1667 on_ui_fb_resized(); | |
1668 } | |
1669 need_ui_fb_resize = 0; | |
1670 } | |
1637 } else { | 1671 } else { |
1638 SDL_RenderCopy(extra_renderers[which - FRAMEBUFFER_USER_START], sdl_textures[which], NULL, NULL); | 1672 SDL_RenderCopy(extra_renderers[which - FRAMEBUFFER_USER_START], sdl_textures[which], NULL, NULL); |
1639 SDL_RenderPresent(extra_renderers[which - FRAMEBUFFER_USER_START]); | 1673 SDL_RenderPresent(extra_renderers[which - FRAMEBUFFER_USER_START]); |
1640 } | 1674 } |
1641 if (screenshot_file) { | 1675 if (screenshot_file) { |
1968 //is the only thing that seems to work reliably | 2002 //is the only thing that seems to work reliably |
1969 //when we've just switched to fullscreen mode this should be harmless though | 2003 //when we've just switched to fullscreen mode this should be harmless though |
1970 SDL_SetWindowSize(main_window, windowed_width, windowed_height); | 2004 SDL_SetWindowSize(main_window, windowed_width, windowed_height); |
1971 drain_events(); | 2005 drain_events(); |
1972 in_toggle = 0; | 2006 in_toggle = 0; |
2007 need_ui_fb_resize = 1; | |
1973 } | 2008 } |
1974 | 2009 |
1975 uint32_t render_audio_buffer() | 2010 uint32_t render_audio_buffer() |
1976 { | 2011 { |
1977 return buffer_samples; | 2012 return buffer_samples; |