Mercurial > repos > blastem
annotate render_sdl.c @ 2685:da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 30 Mar 2025 00:06:53 -0700 |
parents | 69c1093f8726 |
children | 05915f01046d |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
445
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
445
diff
changeset
|
2 Copyright 2013 Michael Pavone |
487
c08a4efeee7f
Update opengl branch from default. Fix build breakage unrelated to merge
Mike Pavone <pavone@retrodev.com>
diff
changeset
|
3 This file is part of BlastEm. |
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
445
diff
changeset
|
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
445
diff
changeset
|
5 */ |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include <stdlib.h> |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include <stdio.h> |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
744
diff
changeset
|
8 #include <string.h> |
500
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
9 #include <math.h> |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include "render.h" |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
11 #include "render_sdl.h" |
66 | 12 #include "blastem.h" |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
13 #include "genesis.h" |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1580
diff
changeset
|
14 #include "bindings.h" |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
15 #include "util.h" |
1693
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
16 #include "paths.h" |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
17 #include "ppm.h" |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
18 #include "png.h" |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
19 #include "config.h" |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
20 #include "controller_info.h" |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
22 #ifndef DISABLE_OPENGL |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
23 #ifdef USE_GLES |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
24 #include <SDL_opengles2.h> |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
25 #else |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
26 #include <GL/glew.h> |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
27 #endif |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
28 #endif |
2640
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
29 #ifdef __EMSCRIPTEN__ |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
30 #include <emscripten.h> |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
31 #endif |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
32 |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
33 #define MAX_EVENT_POLL_PER_FRAME 2 |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
34 |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
35 |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
36 typedef struct { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
37 SDL_Window *win; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
38 SDL_Renderer *renderer; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
39 SDL_Texture *sdl_texture; |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
40 SDL_Texture **static_images; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
41 window_close_handler on_close; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
42 uint32_t width; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
43 uint32_t height; |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
44 uint8_t num_static; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
45 #ifndef DISABLE_OPENGL |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
46 SDL_GLContext *gl_context; |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
47 pixel_t *texture_buf; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
48 uint32_t tex_width; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
49 uint32_t tex_height; |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
50 GLuint gl_texture[2]; |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
51 GLuint *gl_static_images; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
52 GLuint vshader; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
53 GLuint fshader; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
54 GLuint program; |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
55 GLuint gl_buffers[3]; |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
56 GLuint image_buffer; |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
57 GLfloat *image_vertices; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
58 GLint un_texture; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
59 GLint un_width; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
60 GLint un_height; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
61 GLint at_pos; |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
62 GLint at_uv; |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
63 uint8_t color[4]; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
64 #endif |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
65 } extra_window; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
66 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
67 static SDL_Window *main_window; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
68 static extra_window *extras; |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
69 static SDL_Renderer *main_renderer; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
70 static SDL_Texture *sdl_textures[FRAMEBUFFER_UI + 1]; |
1649
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
71 static window_close_handler *close_handlers; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
72 static uint8_t num_extras; |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
73 static SDL_Rect main_clip; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
74 static SDL_GLContext *main_context; |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
75 |
2392
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
76 static int main_width, main_height, windowed_width, windowed_height; |
914
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
77 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
78 static uint8_t render_gl = 1; |
2392
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
79 static uint8_t scanlines, is_fullscreen, force_cursor; |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
81 static uint32_t last_frame = 0; |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
82 |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
83 static SDL_mutex *audio_mutex, *frame_mutex, *free_buffer_mutex; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
84 static SDL_cond *audio_ready, *frame_ready; |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
85 static uint8_t quitting = 0; |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
86 |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
87 enum { |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
88 SYNC_AUDIO, |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
89 SYNC_AUDIO_THREAD, |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
90 SYNC_VIDEO, |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
91 SYNC_EXTERNAL |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
92 }; |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
93 |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
94 static uint8_t sync_src; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
95 static uint32_t min_buffered; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
96 |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
97 pixel_t **frame_buffers; |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
98 uint32_t num_buffers; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
99 uint32_t buffer_storage; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
100 |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
101 uint32_t render_min_buffered(void) |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
102 { |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
103 return min_buffered; |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
104 } |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
105 |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
106 uint8_t render_is_audio_sync(void) |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
107 { |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
108 return sync_src < SYNC_VIDEO; |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
109 } |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
110 |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
111 uint8_t render_should_release_on_exit(void) |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
112 { |
2600
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
113 #ifdef __EMSCRIPTEN__ |
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
114 return 0; |
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
115 #else |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
116 return sync_src != SYNC_AUDIO_THREAD; |
2600
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
117 #endif |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
118 } |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
119 |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
120 void render_buffer_consumed(audio_source *src) |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
121 { |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
122 SDL_CondSignal(src->opaque); |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
123 } |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
124 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
125 static void audio_callback(void * userdata, uint8_t *byte_stream, int len) |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 { |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
127 SDL_LockMutex(audio_mutex); |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
128 uint8_t all_ready; |
2640
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
129 #ifdef __EMSCRIPTEN__ |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
130 if (!all_sources_ready()) { |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
131 memset(byte_stream, 0, len); |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
132 SDL_UnlockMutex(audio_mutex); |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
133 return; |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
134 } |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
135 #else |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
136 do { |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
137 all_ready = all_sources_ready(); |
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
138 if (!quitting && !all_ready) { |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
139 SDL_CondWait(audio_ready, audio_mutex); |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
140 } |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
141 } while(!quitting && !all_ready); |
2640
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
142 #endif |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
143 if (!quitting) { |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
144 mix_and_convert(byte_stream, len, NULL); |
361 | 145 } |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
146 SDL_UnlockMutex(audio_mutex); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
147 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
148 |
1564
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
149 #define NO_LAST_BUFFERED -2000000000 |
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
150 static int32_t last_buffered = NO_LAST_BUFFERED; |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
151 static float average_change; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
152 #define BUFFER_FRAMES_THRESHOLD 6 |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
153 #define BASE_MAX_ADJUST 0.0125 |
1565
61fafcbc2c38
Audio DRC now sounds good in both NTSC and PAL, just need to adjust constants to minimize latency without leading to dropouts
Michael Pavone <pavone@retrodev.com>
parents:
1564
diff
changeset
|
154 static float max_adjust; |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
155 static int32_t cur_min_buffered; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
156 static uint32_t min_remaining_buffer; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
157 static void audio_callback_drc(void *userData, uint8_t *byte_stream, int len) |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
158 { |
1589
780604a036e4
Limit underflow warning spam
Michael Pavone <pavone@retrodev.com>
parents:
1588
diff
changeset
|
159 if (cur_min_buffered < 0) { |
780604a036e4
Limit underflow warning spam
Michael Pavone <pavone@retrodev.com>
parents:
1588
diff
changeset
|
160 //underflow last frame, but main thread hasn't gotten a chance to call SDL_PauseAudio yet |
780604a036e4
Limit underflow warning spam
Michael Pavone <pavone@retrodev.com>
parents:
1588
diff
changeset
|
161 return; |
780604a036e4
Limit underflow warning spam
Michael Pavone <pavone@retrodev.com>
parents:
1588
diff
changeset
|
162 } |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
163 cur_min_buffered = mix_and_convert(byte_stream, len, &min_remaining_buffer); |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
164 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
165 |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
166 static void audio_callback_run_on_audio(void *user_data, uint8_t *byte_stream, int len) |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
167 { |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
168 if (current_system) { |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
169 current_system->resume_context(current_system); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
170 } |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
171 mix_and_convert(byte_stream, len, NULL); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
172 } |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
173 |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
174 void render_lock_audio() |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
175 { |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
176 if (sync_src == SYNC_AUDIO) { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
177 SDL_LockMutex(audio_mutex); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
178 } else { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
179 SDL_LockAudio(); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
180 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
181 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
182 |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
183 void render_unlock_audio() |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
184 { |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
185 if (sync_src == SYNC_AUDIO) { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
186 SDL_UnlockMutex(audio_mutex); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
187 } else { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
188 SDL_UnlockAudio(); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
189 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
190 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
191 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
192 static void render_close_audio() |
361 | 193 { |
194 SDL_LockMutex(audio_mutex); | |
195 quitting = 1; | |
196 SDL_CondSignal(audio_ready); | |
197 SDL_UnlockMutex(audio_mutex); | |
198 SDL_CloseAudio(); | |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
199 /* |
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
200 FIXME: move this to render_audio.c |
1797
5ff8f0d28188
Make sure there are no races between main thread and audio thread around mix_buf. Fix lack of proper termination in shader loading code
Mike Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
201 if (mix_buf) { |
5ff8f0d28188
Make sure there are no races between main thread and audio thread around mix_buf. Fix lack of proper termination in shader loading code
Mike Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
202 free(mix_buf); |
5ff8f0d28188
Make sure there are no races between main thread and audio thread around mix_buf. Fix lack of proper termination in shader loading code
Mike Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
203 mix_buf = NULL; |
5ff8f0d28188
Make sure there are no races between main thread and audio thread around mix_buf. Fix lack of proper termination in shader loading code
Mike Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
204 } |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
205 */ |
361 | 206 } |
207 | |
2370 | 208 static uint8_t audio_active; |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
209 void *render_new_audio_opaque(void) |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
210 { |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
211 return SDL_CreateCond(); |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
212 } |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
213 |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
214 void render_free_audio_opaque(void *opaque) |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
215 { |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
216 SDL_DestroyCond(opaque); |
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
217 } |
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
218 |
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
219 void render_audio_created(audio_source *source) |
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
220 { |
2370 | 221 audio_active = 1; |
1981
3537514ea206
Go back to unpausing audio in render_video_loop to ensure the core is no longer running on the main thread when audio callbacks start when using run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
222 if (sync_src == SYNC_AUDIO) { |
2004
66f08024d9e9
Fix occasional deadlock on startup when using audio sync
Michael Pavone <pavone@retrodev.com>
parents:
1981
diff
changeset
|
223 //SDL_PauseAudio acquires the audio device lock, which is held while the callback runs |
66f08024d9e9
Fix occasional deadlock on startup when using audio sync
Michael Pavone <pavone@retrodev.com>
parents:
1981
diff
changeset
|
224 //since our callback can itself be stuck waiting on the audio_ready condition variable |
66f08024d9e9
Fix occasional deadlock on startup when using audio sync
Michael Pavone <pavone@retrodev.com>
parents:
1981
diff
changeset
|
225 //calling SDL_PauseAudio(0) again for audio sources after the first can deadlock |
66f08024d9e9
Fix occasional deadlock on startup when using audio sync
Michael Pavone <pavone@retrodev.com>
parents:
1981
diff
changeset
|
226 //fortunately SDL_GetAudioStatus does not acquire the lock so is safe to call here |
66f08024d9e9
Fix occasional deadlock on startup when using audio sync
Michael Pavone <pavone@retrodev.com>
parents:
1981
diff
changeset
|
227 if (SDL_GetAudioStatus() == SDL_AUDIO_PAUSED) { |
66f08024d9e9
Fix occasional deadlock on startup when using audio sync
Michael Pavone <pavone@retrodev.com>
parents:
1981
diff
changeset
|
228 SDL_PauseAudio(0); |
66f08024d9e9
Fix occasional deadlock on startup when using audio sync
Michael Pavone <pavone@retrodev.com>
parents:
1981
diff
changeset
|
229 } |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
230 } |
1980
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1979
diff
changeset
|
231 if (current_system && sync_src == SYNC_AUDIO_THREAD) { |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1979
diff
changeset
|
232 system_request_exit(current_system, 0); |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
233 } |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
234 } |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
235 |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
236 void render_source_paused(audio_source *src, uint8_t remaining_sources) |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
237 { |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
238 if (sync_src == SYNC_AUDIO) { |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
239 SDL_CondSignal(audio_ready); |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
240 } |
1980
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1979
diff
changeset
|
241 if (!remaining_sources && render_is_audio_sync()) { |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1979
diff
changeset
|
242 SDL_PauseAudio(1); |
2370 | 243 audio_active = 0; |
1980
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1979
diff
changeset
|
244 if (sync_src == SYNC_AUDIO_THREAD) { |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1979
diff
changeset
|
245 SDL_CondSignal(frame_ready); |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1979
diff
changeset
|
246 } |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
247 } |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
248 } |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
249 |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
250 void render_source_resumed(audio_source *src) |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
251 { |
2370 | 252 audio_active = 1; |
1981
3537514ea206
Go back to unpausing audio in render_video_loop to ensure the core is no longer running on the main thread when audio callbacks start when using run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
253 if (sync_src == SYNC_AUDIO) { |
2004
66f08024d9e9
Fix occasional deadlock on startup when using audio sync
Michael Pavone <pavone@retrodev.com>
parents:
1981
diff
changeset
|
254 //SDL_PauseAudio acquires the audio device lock, which is held while the callback runs |
66f08024d9e9
Fix occasional deadlock on startup when using audio sync
Michael Pavone <pavone@retrodev.com>
parents:
1981
diff
changeset
|
255 //since our callback can itself be stuck waiting on the audio_ready condition variable |
66f08024d9e9
Fix occasional deadlock on startup when using audio sync
Michael Pavone <pavone@retrodev.com>
parents:
1981
diff
changeset
|
256 //calling SDL_PauseAudio(0) again for audio sources after the first can deadlock |
66f08024d9e9
Fix occasional deadlock on startup when using audio sync
Michael Pavone <pavone@retrodev.com>
parents:
1981
diff
changeset
|
257 //fortunately SDL_GetAudioStatus does not acquire the lock so is safe to call here |
66f08024d9e9
Fix occasional deadlock on startup when using audio sync
Michael Pavone <pavone@retrodev.com>
parents:
1981
diff
changeset
|
258 if (SDL_GetAudioStatus() == SDL_AUDIO_PAUSED) { |
66f08024d9e9
Fix occasional deadlock on startup when using audio sync
Michael Pavone <pavone@retrodev.com>
parents:
1981
diff
changeset
|
259 SDL_PauseAudio(0); |
66f08024d9e9
Fix occasional deadlock on startup when using audio sync
Michael Pavone <pavone@retrodev.com>
parents:
1981
diff
changeset
|
260 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
261 } |
1980
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1979
diff
changeset
|
262 if (current_system && sync_src == SYNC_AUDIO_THREAD) { |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1979
diff
changeset
|
263 system_request_exit(current_system, 0); |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1979
diff
changeset
|
264 } |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
265 } |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
266 |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
267 uint8_t audio_deadlock_hack(void); |
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
268 |
2640
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
269 static ui_render_fun audio_full_cb; |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
270 void render_set_audio_full_fun(ui_render_fun cb) |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
271 { |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
272 audio_full_cb = cb; |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
273 } |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
274 |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
275 void render_do_audio_ready(audio_source *src) |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
276 { |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
277 if (sync_src == SYNC_AUDIO_THREAD) { |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
278 int16_t *tmp = src->front; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
279 src->front = src->back; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
280 src->back = tmp; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
281 src->front_populated = 1; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
282 src->buffer_pos = 0; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
283 if (all_sources_ready()) { |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
284 //we've emulated far enough to fill the current buffer |
1980
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1979
diff
changeset
|
285 system_request_exit(current_system, 0); |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
286 } |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
287 } else if (sync_src == SYNC_AUDIO) { |
2640
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
288 uint8_t all_ready = 0; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
289 SDL_LockMutex(audio_mutex); |
2640
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
290 #ifndef __EMSCRIPTEN__ |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
291 if (src->front_populated) { |
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
292 if (audio_deadlock_hack()) { |
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
293 SDL_CondSignal(audio_ready); |
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
294 } |
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
295 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
296 while (src->front_populated) { |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
297 SDL_CondWait(src->opaque, audio_mutex); |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
298 } |
2640
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
299 #endif |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
300 int16_t *tmp = src->front; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
301 src->front = src->back; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
302 src->back = tmp; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
303 src->front_populated = 1; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
304 src->buffer_pos = 0; |
2640
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
305 all_ready = all_sources_ready(); |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
306 SDL_CondSignal(audio_ready); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
307 SDL_UnlockMutex(audio_mutex); |
2640
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
308 if (all_ready && audio_full_cb) { |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
309 audio_full_cb(); |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
310 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
311 } else { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
312 uint32_t num_buffered; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
313 SDL_LockAudio(); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
314 src->read_end = src->buffer_pos; |
1565
61fafcbc2c38
Audio DRC now sounds good in both NTSC and PAL, just need to adjust constants to minimize latency without leading to dropouts
Michael Pavone <pavone@retrodev.com>
parents:
1564
diff
changeset
|
315 num_buffered = ((src->read_end - src->read_start) & src->mask) / src->num_channels; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
316 SDL_UnlockAudio(); |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
317 if (num_buffered >= min_buffered && SDL_GetAudioStatus() == SDL_AUDIO_PAUSED) { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
318 SDL_PauseAudio(0); |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
319 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
320 } |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
321 } |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
322 |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
323 static SDL_Joystick * joysticks[MAX_JOYSTICKS]; |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
324 static int joystick_sdl_index[MAX_JOYSTICKS]; |
1860
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
325 static uint8_t joystick_index_locked[MAX_JOYSTICKS]; |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
326 |
914
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
327 int render_width() |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
328 { |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
329 return main_width; |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
330 } |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
331 |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
332 int render_height() |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
333 { |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
334 return main_height; |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
335 } |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
336 |
2405
b50fa7602e39
Fix libblastem target
Michael Pavone <pavone@retrodev.com>
parents:
2404
diff
changeset
|
337 uint8_t render_fullscreen(void) |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
338 { |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
339 return is_fullscreen; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
340 } |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
341 |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
342 pixel_t render_map_color(uint8_t r, uint8_t g, uint8_t b) |
426
add9e2f5c0e3
Make VDP render in native pixel format of the renderer for a modest performance gain and to make it easier to use OpenGL for rendering
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
343 { |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
344 #ifdef USE_RGB565 |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
345 return r << 8 & 0xF800 | g << 3 & 0x07E0 | b >> 3; |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
346 #else |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
347 #ifdef USE_GLES |
2346
0111c8344477
Fix some issues identified by asan/ubsan
Michael Pavone <pavone@retrodev.com>
parents:
2318
diff
changeset
|
348 return 255UL << 24 | b << 16 | g << 8 | r; |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
349 #else |
2346
0111c8344477
Fix some issues identified by asan/ubsan
Michael Pavone <pavone@retrodev.com>
parents:
2318
diff
changeset
|
350 return 255UL << 24 | r << 16 | g << 8 | b; |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
351 #endif |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
352 #endif |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
353 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
354 |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
355 static uint8_t external_sync; |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
356 void render_set_external_sync(uint8_t ext_sync_on) |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
357 { |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
358 if (ext_sync_on != external_sync) { |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
359 external_sync = ext_sync_on; |
1975
3701517d852c
Avoid expensive re-init from switching to external sync after render_init has been called
Michael Pavone <pavone@retrodev.com>
parents:
1967
diff
changeset
|
360 if (windowed_width) { |
3701517d852c
Avoid expensive re-init from switching to external sync after render_init has been called
Michael Pavone <pavone@retrodev.com>
parents:
1967
diff
changeset
|
361 //only do this if render_init has already been called |
3701517d852c
Avoid expensive re-init from switching to external sync after render_init has been called
Michael Pavone <pavone@retrodev.com>
parents:
1967
diff
changeset
|
362 render_config_updated(); |
3701517d852c
Avoid expensive re-init from switching to external sync after render_init has been called
Michael Pavone <pavone@retrodev.com>
parents:
1967
diff
changeset
|
363 } |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
364 } |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
365 } |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
366 |
2308
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
367 static int tex_width, tex_height; |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
368 #ifndef DISABLE_OPENGL |
2390
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
369 static GLuint textures[3], buffers[2], vshader, fshader, program; |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
370 static GLint un_textures[2], un_width, un_height, un_texsize, un_curfield, un_interlaced, un_scanlines, at_pos; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
371 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
372 static GLfloat vertex_data_default[] = { |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
373 -1.0f, -1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
374 1.0f, -1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
375 -1.0f, 1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
376 1.0f, 1.0f |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
377 }; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
378 |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
379 static GLfloat uvs[] = { |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
380 0.0f, 1.0f, |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
381 1.0f, 1.0f, |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
382 0.0f, 0.0f, |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
383 1.0f, 0.0f |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
384 }; |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
385 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
386 static GLfloat vertex_data[8]; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
387 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
388 static const GLushort element_data[] = {0, 1, 2, 3}; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
389 |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
390 static const GLchar shader_prefix[] = |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
391 #ifdef USE_GLES |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
392 "#version 100\n"; |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
393 #else |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
394 "#version 110\n" |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
395 "#define lowp\n" |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
396 "#define mediump\n" |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
397 "#define highp\n"; |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
398 #endif |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
399 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
400 static GLuint load_shader(char * fname, GLenum shader_type) |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
401 { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
402 char * shader_path; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
403 FILE *f; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
404 GLchar *text; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
405 long fsize; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
406 #ifndef __ANDROID__ |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
407 char const * parts[] = {get_home_dir(), "/.config/blastem/shaders/", fname}; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
408 shader_path = alloc_concat_m(3, parts); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
409 f = fopen(shader_path, "rb"); |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
410 free(shader_path); |
1693
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
411 if (f) { |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
412 fsize = file_size(f); |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
413 text = malloc(fsize); |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
414 if (fread(text, 1, fsize, f) != fsize) { |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
415 warning("Error reading from shader file %s\n", fname); |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
416 free(text); |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
417 return 0; |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
418 } |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
419 } else { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
420 #endif |
1693
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
421 shader_path = path_append("shaders", fname); |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
422 uint32_t fsize32; |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
423 text = read_bundled_file(shader_path, &fsize32); |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
424 free(shader_path); |
1693
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
425 if (!text) { |
800 | 426 warning("Failed to open shader file %s for reading\n", fname); |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
427 return 0; |
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
428 } |
1693
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
429 fsize = fsize32; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
430 #ifndef __ANDROID__ |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
431 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
432 #endif |
1797
5ff8f0d28188
Make sure there are no races between main thread and audio thread around mix_buf. Fix lack of proper termination in shader loading code
Mike Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
433 text[fsize] = 0; |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
434 |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
435 if (strncmp(text, "#version", strlen("#version"))) { |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
436 GLchar *tmp = text; |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
437 text = alloc_concat(shader_prefix, tmp); |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
438 free(tmp); |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
439 fsize += strlen(shader_prefix); |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
440 } |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
441 GLuint ret = glCreateShader(shader_type); |
1820
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
442 if (!ret) { |
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
443 warning("glCreateShader failed with error %d\n", glGetError()); |
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
444 return 0; |
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
445 } |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
446 glShaderSource(ret, 1, (const GLchar **)&text, (const GLint *)&fsize); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
447 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
448 glCompileShader(ret); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
449 GLint compile_status, loglen; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
450 glGetShaderiv(ret, GL_COMPILE_STATUS, &compile_status); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
451 if (!compile_status) { |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
452 glGetShaderiv(ret, GL_INFO_LOG_LENGTH, &loglen); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
453 text = malloc(loglen); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
454 glGetShaderInfoLog(ret, loglen, NULL, text); |
800 | 455 warning("Shader %s failed to compile:\n%s\n", fname, text); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
456 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
457 glDeleteShader(ret); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
458 return 0; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
459 } |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
460 return ret; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
461 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
462 #endif |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
463 |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
464 static pixel_t texture_buf[512 * 513]; |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
465 #ifdef DISABLE_OPENGL |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
466 #ifdef USE_RGB565 |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
467 #define RENDER_FORMAT SDL_PIXELFORMAT_RGB565 |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
468 #else |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
469 #define RENDER_FORMAT SDL_PIXELFORMAT_ARGB8888 |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
470 #endif |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
471 #else //DISABLE_OPENGL |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
472 #ifdef USE_RGB565 |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
473 #define INTERNAL_FORMAT GL_RGB |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
474 #define SRC_FORMAT GL_RGB |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
475 #define SRC_TYPE GL_UNSIGNED_SHORT_5_6_5 |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
476 #define RENDER_FORMAT SDL_PIXELFORMAT_RGB565 |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
477 #else //USE_RGB565 |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
478 #define SRC_TYPE GL_UNSIGNED_BYTE |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
479 #ifdef USE_GLES |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
480 #define INTERNAL_FORMAT GL_RGBA |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
481 #define SRC_FORMAT GL_RGBA |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
482 #define RENDER_FORMAT SDL_PIXELFORMAT_ABGR8888 |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
483 #else //USE_GLES |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
484 #define INTERNAL_FORMAT GL_RGBA8 |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
485 #define SRC_FORMAT GL_BGRA |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
486 #define RENDER_FORMAT SDL_PIXELFORMAT_ARGB8888 |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
487 #endif //USE_GLES |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
488 #endif //USE_RGB565 |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
489 |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
490 #ifdef USE_GLES |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
491 #define SRC_FORMAT32 GL_RGBA |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
492 #else |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
493 #define SRC_FORMAT32 GL_BGRA |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
494 #endif |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
495 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
496 static void gl_setup() |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
497 { |
1403
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
498 tern_val def = {.ptrval = "linear"}; |
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
499 char *scaling = tern_find_path_default(config, "video\0scaling\0", def, TVAL_PTR).ptrval; |
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
500 GLint filter = strcmp(scaling, "linear") ? GL_NEAREST : GL_LINEAR; |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
501 glGenTextures(3, textures); |
1977
f3cca4b3f17a
Allow use of NPOT textures as a config option. Useful for some mobile GPUs
Michael Pavone <pavone@retrodev.com>
parents:
1975
diff
changeset
|
502 def.ptrval = "off"; |
f3cca4b3f17a
Allow use of NPOT textures as a config option. Useful for some mobile GPUs
Michael Pavone <pavone@retrodev.com>
parents:
1975
diff
changeset
|
503 char *npot_textures = tern_find_path_default(config, "video\0npot_textures\0", def, TVAL_PTR).ptrval; |
f3cca4b3f17a
Allow use of NPOT textures as a config option. Useful for some mobile GPUs
Michael Pavone <pavone@retrodev.com>
parents:
1975
diff
changeset
|
504 if (!strcmp(npot_textures, "on")) { |
f3cca4b3f17a
Allow use of NPOT textures as a config option. Useful for some mobile GPUs
Michael Pavone <pavone@retrodev.com>
parents:
1975
diff
changeset
|
505 tex_width = LINEBUF_SIZE; |
f3cca4b3f17a
Allow use of NPOT textures as a config option. Useful for some mobile GPUs
Michael Pavone <pavone@retrodev.com>
parents:
1975
diff
changeset
|
506 tex_height = 294; //PAL height with full borders |
f3cca4b3f17a
Allow use of NPOT textures as a config option. Useful for some mobile GPUs
Michael Pavone <pavone@retrodev.com>
parents:
1975
diff
changeset
|
507 } else { |
f3cca4b3f17a
Allow use of NPOT textures as a config option. Useful for some mobile GPUs
Michael Pavone <pavone@retrodev.com>
parents:
1975
diff
changeset
|
508 tex_width = tex_height = 512; |
f3cca4b3f17a
Allow use of NPOT textures as a config option. Useful for some mobile GPUs
Michael Pavone <pavone@retrodev.com>
parents:
1975
diff
changeset
|
509 } |
2031
0757da8ee702
Fix some stuff that was calling printf directly
Michael Pavone <pavone@retrodev.com>
parents:
2018
diff
changeset
|
510 debug_message("Using %dx%d textures\n", tex_width, tex_height); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
511 for (int i = 0; i < 3; i++) |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
512 { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
513 glBindTexture(GL_TEXTURE_2D, textures[i]); |
1403
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
514 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); |
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
515 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
516 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
517 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
518 if (i < 2) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
519 //TODO: Fixme for PAL + invalid display mode |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
520 glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT, tex_width, tex_height, 0, SRC_FORMAT, SRC_TYPE, texture_buf); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
521 } else { |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
522 pixel_t blank = render_map_color(0, 0, 0); |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
523 glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT, 1, 1, 0, SRC_FORMAT, SRC_TYPE, &blank); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
524 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
525 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
526 glGenBuffers(2, buffers); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
527 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
528 glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
529 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
530 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(element_data), element_data, GL_STATIC_DRAW); |
1403
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
531 def.ptrval = "default.v.glsl"; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
532 vshader = load_shader(tern_find_path_default(config, "video\0vertex_shader\0", def, TVAL_PTR).ptrval, GL_VERTEX_SHADER); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
533 def.ptrval = "default.f.glsl"; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
534 fshader = load_shader(tern_find_path_default(config, "video\0fragment_shader\0", def, TVAL_PTR).ptrval, GL_FRAGMENT_SHADER); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
535 program = glCreateProgram(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
536 glAttachShader(program, vshader); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
537 glAttachShader(program, fshader); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
538 glLinkProgram(program); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
539 GLint link_status; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
540 glGetProgramiv(program, GL_LINK_STATUS, &link_status); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
541 if (!link_status) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
542 fputs("Failed to link shader program\n", stderr); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
543 exit(1); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
544 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
545 un_textures[0] = glGetUniformLocation(program, "textures[0]"); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
546 un_textures[1] = glGetUniformLocation(program, "textures[1]"); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
547 un_width = glGetUniformLocation(program, "width"); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
548 un_height = glGetUniformLocation(program, "height"); |
1977
f3cca4b3f17a
Allow use of NPOT textures as a config option. Useful for some mobile GPUs
Michael Pavone <pavone@retrodev.com>
parents:
1975
diff
changeset
|
549 un_texsize = glGetUniformLocation(program, "texsize"); |
2390
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
550 un_curfield = glGetUniformLocation(program, "curfield"); |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
551 un_interlaced = glGetUniformLocation(program, "interlaced"); |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
552 un_scanlines = glGetUniformLocation(program, "scanlines"); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
553 at_pos = glGetAttribLocation(program, "pos"); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
554 } |
1593
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
555 |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
556 static void gl_teardown() |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
557 { |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
558 glDeleteProgram(program); |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
559 glDeleteShader(vshader); |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
560 glDeleteShader(fshader); |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
561 glDeleteBuffers(2, buffers); |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
562 glDeleteTextures(3, textures); |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
563 } |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
564 #endif //DISABLE_OPENGL |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
565 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
566 static uint8_t texture_init; |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
567 static void render_alloc_surfaces() |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
568 { |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
569 if (texture_init) { |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
570 return; |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
571 } |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
572 texture_init = 1; |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
573 #ifndef DISABLE_OPENGL |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
574 if (render_gl) { |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
575 gl_setup(); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
576 } else { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
577 #endif |
1403
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
578 tern_val def = {.ptrval = "linear"}; |
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
579 char *scaling = tern_find_path_default(config, "video\0scaling\0", def, TVAL_PTR).ptrval; |
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
580 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, scaling); |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
581 //TODO: Fixme for invalid display mode |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
582 sdl_textures[0] = sdl_textures[1] = SDL_CreateTexture(main_renderer, RENDER_FORMAT, SDL_TEXTUREACCESS_STREAMING, LINEBUF_SIZE, 588); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
583 #ifndef DISABLE_OPENGL |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
584 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
585 #endif |
426
add9e2f5c0e3
Make VDP render in native pixel format of the renderer for a modest performance gain and to make it easier to use OpenGL for rendering
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
586 } |
add9e2f5c0e3
Make VDP render in native pixel format of the renderer for a modest performance gain and to make it easier to use OpenGL for rendering
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
587 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
588 static void free_surfaces(void) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
589 { |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
590 for (int i = 0; i <= FRAMEBUFFER_UI; i++) |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
591 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
592 if (sdl_textures[i]) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
593 SDL_DestroyTexture(sdl_textures[i]); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
594 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
595 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
596 texture_init = 0; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
597 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
598 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
599 static char * caption = NULL; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
600 static char * fps_caption = NULL; |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
601 |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
602 static void render_quit() |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
603 { |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
604 render_close_audio(); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
605 free_surfaces(); |
1593
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
606 #ifndef DISABLE_OPENGL |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
607 if (render_gl) { |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
608 gl_teardown(); |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
609 SDL_GL_DeleteContext(main_context); |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
610 } |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
611 #endif |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
612 } |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
613 |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
614 static float config_aspect() |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
615 { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
616 static float aspect = 0.0f; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
617 if (aspect == 0.0f) { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
618 char *config_aspect = tern_find_path_default(config, "video\0aspect\0", (tern_val){.ptrval = "4:3"}, TVAL_PTR).ptrval; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
619 if (strcmp("stretch", config_aspect)) { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
620 aspect = 4.0f/3.0f; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
621 char *end; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
622 float aspect_numerator = strtof(config_aspect, &end); |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
623 if (aspect_numerator > 0.0f && *end == ':') { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
624 float aspect_denominator = strtof(end+1, &end); |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
625 if (aspect_denominator > 0.0f && !*end) { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
626 aspect = aspect_numerator / aspect_denominator; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
627 } |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
628 } |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
629 } else { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
630 aspect = -1.0f; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
631 } |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
632 } |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
633 return aspect; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
634 } |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
635 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
636 static void update_aspect() |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
637 { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
638 //reset default values |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
639 #ifndef DISABLE_OPENGL |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
640 memcpy(vertex_data, vertex_data_default, sizeof(vertex_data)); |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
641 #endif |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
642 main_clip.w = main_width; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
643 main_clip.h = main_height; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
644 main_clip.x = main_clip.y = 0; |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
645 if (config_aspect() > 0.0f) { |
2644
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
646 char *integer_scaling_str = tern_find_path_default(config, "video\0integer_scaling\0", (tern_val){.ptrval = "off"}, TVAL_PTR).ptrval; |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
647 uint8_t integer_scaling = !strcmp(integer_scaling_str, "on"); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
648 float aspect = (float)main_width / main_height; |
2644
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
649 if (!integer_scaling && fabs(aspect - config_aspect()) < 0.01f) { |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
650 //close enough for government work |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
651 return; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
652 } |
2644
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
653 uint32_t height, scale; |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
654 if (integer_scaling) { |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
655 height = render_emulated_height(); |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
656 if (aspect >= config_aspect()) { |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
657 scale = main_height / height; |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
658 } else { |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
659 uint32_t aspect_height = 0.5f + (float)main_width / config_aspect(); |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
660 scale = aspect_height / height; |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
661 } |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
662 } |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
663 #ifndef DISABLE_OPENGL |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
664 if (render_gl) { |
2644
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
665 if (integer_scaling) { |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
666 float vscale = ((float)(scale * height)) / (float)main_height; |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
667 float hscale = (config_aspect() * (float)(scale * height)) / (float)main_width; |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
668 for (int i = 0; i < 4; i++) |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
669 { |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
670 vertex_data[i*2] *= hscale; |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
671 vertex_data[i*2+1] *= vscale; |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
672 } |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
673 } else { |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
674 for (int i = 0; i < 4; i++) |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
675 { |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
676 if (aspect > config_aspect()) { |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
677 vertex_data[i*2] *= config_aspect()/aspect; |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
678 } else { |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
679 vertex_data[i*2+1] *= aspect/config_aspect(); |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
680 } |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
681 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
682 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
683 } else { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
684 #endif |
2644
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
685 if (integer_scaling) { |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
686 main_clip.h = height * scale; |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
687 main_clip.w = main_clip.h * config_aspect(); |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
688 } else { |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
689 main_clip.w = aspect > config_aspect() ? config_aspect() * (float)main_height : main_width; |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
690 main_clip.h = aspect > config_aspect() ? main_height : main_width / config_aspect(); |
c5c9498ff279
Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents:
2640
diff
changeset
|
691 } |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
692 main_clip.x = (main_width - main_clip.w) / 2; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
693 main_clip.y = (main_height - main_clip.h) / 2; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
694 #ifndef DISABLE_OPENGL |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
695 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
696 #endif |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
697 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
698 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
699 |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
700 static ui_render_fun on_context_destroyed, on_context_created, on_ui_fb_resized; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
701 void render_set_gl_context_handlers(ui_render_fun destroy, ui_render_fun create) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
702 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
703 on_context_destroyed = destroy; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
704 on_context_created = create; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
705 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
706 |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
707 void render_set_ui_fb_resize_handler(ui_render_fun resize) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
708 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
709 on_ui_fb_resized = resize; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
710 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
711 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
712 static uint8_t scancode_map[SDL_NUM_SCANCODES] = { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
713 [SDL_SCANCODE_A] = 0x1C, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
714 [SDL_SCANCODE_B] = 0x32, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
715 [SDL_SCANCODE_C] = 0x21, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
716 [SDL_SCANCODE_D] = 0x23, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
717 [SDL_SCANCODE_E] = 0x24, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
718 [SDL_SCANCODE_F] = 0x2B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
719 [SDL_SCANCODE_G] = 0x34, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
720 [SDL_SCANCODE_H] = 0x33, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
721 [SDL_SCANCODE_I] = 0x43, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
722 [SDL_SCANCODE_J] = 0x3B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
723 [SDL_SCANCODE_K] = 0x42, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
724 [SDL_SCANCODE_L] = 0x4B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
725 [SDL_SCANCODE_M] = 0x3A, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
726 [SDL_SCANCODE_N] = 0x31, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
727 [SDL_SCANCODE_O] = 0x44, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
728 [SDL_SCANCODE_P] = 0x4D, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
729 [SDL_SCANCODE_Q] = 0x15, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
730 [SDL_SCANCODE_R] = 0x2D, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
731 [SDL_SCANCODE_S] = 0x1B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
732 [SDL_SCANCODE_T] = 0x2C, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
733 [SDL_SCANCODE_U] = 0x3C, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
734 [SDL_SCANCODE_V] = 0x2A, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
735 [SDL_SCANCODE_W] = 0x1D, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
736 [SDL_SCANCODE_X] = 0x22, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
737 [SDL_SCANCODE_Y] = 0x35, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
738 [SDL_SCANCODE_Z] = 0x1A, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
739 [SDL_SCANCODE_1] = 0x16, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
740 [SDL_SCANCODE_2] = 0x1E, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
741 [SDL_SCANCODE_3] = 0x26, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
742 [SDL_SCANCODE_4] = 0x25, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
743 [SDL_SCANCODE_5] = 0x2E, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
744 [SDL_SCANCODE_6] = 0x36, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
745 [SDL_SCANCODE_7] = 0x3D, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
746 [SDL_SCANCODE_8] = 0x3E, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
747 [SDL_SCANCODE_9] = 0x46, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
748 [SDL_SCANCODE_0] = 0x45, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
749 [SDL_SCANCODE_RETURN] = 0x5A, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
750 [SDL_SCANCODE_ESCAPE] = 0x76, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
751 [SDL_SCANCODE_SPACE] = 0x29, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
752 [SDL_SCANCODE_TAB] = 0x0D, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
753 [SDL_SCANCODE_BACKSPACE] = 0x66, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
754 [SDL_SCANCODE_MINUS] = 0x4E, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
755 [SDL_SCANCODE_EQUALS] = 0x55, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
756 [SDL_SCANCODE_LEFTBRACKET] = 0x54, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
757 [SDL_SCANCODE_RIGHTBRACKET] = 0x5B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
758 [SDL_SCANCODE_BACKSLASH] = 0x5D, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
759 [SDL_SCANCODE_SEMICOLON] = 0x4C, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
760 [SDL_SCANCODE_APOSTROPHE] = 0x52, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
761 [SDL_SCANCODE_GRAVE] = 0x0E, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
762 [SDL_SCANCODE_COMMA] = 0x41, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
763 [SDL_SCANCODE_PERIOD] = 0x49, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
764 [SDL_SCANCODE_SLASH] = 0x4A, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
765 [SDL_SCANCODE_CAPSLOCK] = 0x58, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
766 [SDL_SCANCODE_F1] = 0x05, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
767 [SDL_SCANCODE_F2] = 0x06, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
768 [SDL_SCANCODE_F3] = 0x04, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
769 [SDL_SCANCODE_F4] = 0x0C, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
770 [SDL_SCANCODE_F5] = 0x03, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
771 [SDL_SCANCODE_F6] = 0x0B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
772 [SDL_SCANCODE_F7] = 0x83, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
773 [SDL_SCANCODE_F8] = 0x0A, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
774 [SDL_SCANCODE_F9] = 0x01, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
775 [SDL_SCANCODE_F10] = 0x09, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
776 [SDL_SCANCODE_F11] = 0x78, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
777 [SDL_SCANCODE_F12] = 0x07, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
778 [SDL_SCANCODE_LCTRL] = 0x14, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
779 [SDL_SCANCODE_LSHIFT] = 0x12, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
780 [SDL_SCANCODE_LALT] = 0x11, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
781 [SDL_SCANCODE_RCTRL] = 0x18, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
782 [SDL_SCANCODE_RSHIFT] = 0x59, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
783 [SDL_SCANCODE_RALT] = 0x17, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
784 [SDL_SCANCODE_INSERT] = 0x81, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
785 [SDL_SCANCODE_PAUSE] = 0x82, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
786 [SDL_SCANCODE_PRINTSCREEN] = 0x84, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
787 [SDL_SCANCODE_SCROLLLOCK] = 0x7E, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
788 [SDL_SCANCODE_DELETE] = 0x85, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
789 [SDL_SCANCODE_LEFT] = 0x86, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
790 [SDL_SCANCODE_HOME] = 0x87, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
791 [SDL_SCANCODE_END] = 0x88, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
792 [SDL_SCANCODE_UP] = 0x89, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
793 [SDL_SCANCODE_DOWN] = 0x8A, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
794 [SDL_SCANCODE_PAGEUP] = 0x8B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
795 [SDL_SCANCODE_PAGEDOWN] = 0x8C, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
796 [SDL_SCANCODE_RIGHT] = 0x8D, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
797 [SDL_SCANCODE_NUMLOCKCLEAR] = 0x77, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
798 [SDL_SCANCODE_KP_DIVIDE] = 0x80, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
799 [SDL_SCANCODE_KP_MULTIPLY] = 0x7C, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
800 [SDL_SCANCODE_KP_MINUS] = 0x7B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
801 [SDL_SCANCODE_KP_PLUS] = 0x79, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
802 [SDL_SCANCODE_KP_ENTER] = 0x19, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
803 [SDL_SCANCODE_KP_1] = 0x69, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
804 [SDL_SCANCODE_KP_2] = 0x72, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
805 [SDL_SCANCODE_KP_3] = 0x7A, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
806 [SDL_SCANCODE_KP_4] = 0x6B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
807 [SDL_SCANCODE_KP_5] = 0x73, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
808 [SDL_SCANCODE_KP_6] = 0x74, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
809 [SDL_SCANCODE_KP_7] = 0x6C, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
810 [SDL_SCANCODE_KP_8] = 0x75, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
811 [SDL_SCANCODE_KP_9] = 0x7D, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
812 [SDL_SCANCODE_KP_0] = 0x70, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
813 [SDL_SCANCODE_KP_PERIOD] = 0x71, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
814 }; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
815 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
816 static drop_handler drag_drop_handler; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
817 void render_set_drag_drop_handler(drop_handler handler) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
818 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
819 drag_drop_handler = handler; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
820 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
821 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
822 static event_handler custom_event_handler; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
823 void render_set_event_handler(event_handler handler) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
824 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
825 custom_event_handler = handler; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
826 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
827 |
2318
1c7329ac7f3f
Make UI respect stick deadzone
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
828 int render_find_joystick_index(SDL_JoystickID instanceID) |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
829 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
830 for (int i = 0; i < MAX_JOYSTICKS; i++) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
831 if (joysticks[i] && SDL_JoystickInstanceID(joysticks[i]) == instanceID) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
832 return i; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
833 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
834 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
835 return -1; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
836 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
837 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
838 static int lowest_unused_joystick_index() |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
839 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
840 for (int i = 0; i < MAX_JOYSTICKS; i++) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
841 if (!joysticks[i]) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
842 return i; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
843 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
844 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
845 return -1; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
846 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
847 |
1860
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
848 static int lowest_unlocked_joystick_index(void) |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
849 { |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
850 for (int i = 0; i < MAX_JOYSTICKS; i++) { |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
851 if (!joystick_index_locked[i]) { |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
852 return i; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
853 } |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
854 } |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
855 return -1; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
856 } |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
857 |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
858 SDL_Joystick *render_get_joystick(int index) |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
859 { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
860 if (index >= MAX_JOYSTICKS) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
861 return NULL; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
862 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
863 return joysticks[index]; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
864 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
865 |
1608
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
866 char* render_joystick_type_id(int index) |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
867 { |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
868 SDL_Joystick *stick = render_get_joystick(index); |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
869 if (!stick) { |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
870 return NULL; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
871 } |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
872 char *guid_string = malloc(33); |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
873 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(stick), guid_string, 33); |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
874 return guid_string; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
875 } |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
876 |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
877 SDL_GameController *render_get_controller(int index) |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
878 { |
1862
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
879 if (index >= MAX_JOYSTICKS || !joysticks[index]) { |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
880 return NULL; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
881 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
882 return SDL_GameControllerOpen(joystick_sdl_index[index]); |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
883 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
884 |
1862
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
885 static uint8_t gc_events_enabled; |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
886 static SDL_GameController *controllers[MAX_JOYSTICKS]; |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
887 void render_enable_gamepad_events(uint8_t enabled) |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
888 { |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
889 if (enabled != gc_events_enabled) { |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
890 gc_events_enabled = enabled; |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
891 for (int i = 0; i < MAX_JOYSTICKS; i++) { |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
892 if (enabled) { |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
893 controllers[i] = render_get_controller(i); |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
894 } else if (controllers[i]) { |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
895 SDL_GameControllerClose(controllers[i]); |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
896 controllers[i] = NULL; |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
897 } |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
898 } |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
899 } |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
900 } |
2315
b67e4e930fa4
Workaround for SDL2 being unreliable in updating mapping for already "open" game controller
Michael Pavone <pavone@retrodev.com>
parents:
2308
diff
changeset
|
901 uint8_t render_are_gamepad_events_enabled(void) |
b67e4e930fa4
Workaround for SDL2 being unreliable in updating mapping for already "open" game controller
Michael Pavone <pavone@retrodev.com>
parents:
2308
diff
changeset
|
902 { |
b67e4e930fa4
Workaround for SDL2 being unreliable in updating mapping for already "open" game controller
Michael Pavone <pavone@retrodev.com>
parents:
2308
diff
changeset
|
903 return gc_events_enabled; |
b67e4e930fa4
Workaround for SDL2 being unreliable in updating mapping for already "open" game controller
Michael Pavone <pavone@retrodev.com>
parents:
2308
diff
changeset
|
904 } |
1862
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
905 |
2200
f11f4399d64b
Crop display in game gear mode
Michael Pavone <pavone@retrodev.com>
parents:
2093
diff
changeset
|
906 static uint32_t overscan_top[NUM_VID_STD] = {2, 21, 51}; |
f11f4399d64b
Crop display in game gear mode
Michael Pavone <pavone@retrodev.com>
parents:
2093
diff
changeset
|
907 static uint32_t overscan_bot[NUM_VID_STD] = {1, 17, 48}; |
f11f4399d64b
Crop display in game gear mode
Michael Pavone <pavone@retrodev.com>
parents:
2093
diff
changeset
|
908 static uint32_t overscan_left[NUM_VID_STD] = {13, 13, 61}; |
f11f4399d64b
Crop display in game gear mode
Michael Pavone <pavone@retrodev.com>
parents:
2093
diff
changeset
|
909 static uint32_t overscan_right[NUM_VID_STD] = {14, 14, 62}; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
910 static vid_std video_standard = VID_NTSC; |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
911 static uint8_t need_ui_fb_resize; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
912 |
1860
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
913 int lock_joystick_index(int joystick, int desired_index) |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
914 { |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
915 if (desired_index < 0) { |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
916 desired_index = lowest_unlocked_joystick_index(); |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
917 if (desired_index < 0 || desired_index >= joystick) { |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
918 return joystick; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
919 } |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
920 } |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
921 SDL_Joystick *tmp_joy = joysticks[joystick]; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
922 int tmp_index = joystick_sdl_index[joystick]; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
923 joysticks[joystick] = joysticks[desired_index]; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
924 joystick_sdl_index[joystick] = joystick_sdl_index[desired_index]; |
2239
b2f788f08a31
Fix bug in controller reordering implementation
Michael Pavone <pavone@retrodev.com>
parents:
2200
diff
changeset
|
925 joystick_index_locked[joystick] = joystick_index_locked[desired_index]; |
1860
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
926 joysticks[desired_index] = tmp_joy; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
927 joystick_sdl_index[desired_index] = tmp_index; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
928 joystick_index_locked[desired_index] = 1; |
1861
fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
Michael Pavone <pavone@retrodev.com>
parents:
1860
diff
changeset
|
929 //update bindings as the controllers being swapped may have different mappings |
fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
Michael Pavone <pavone@retrodev.com>
parents:
1860
diff
changeset
|
930 handle_joy_added(desired_index); |
fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
Michael Pavone <pavone@retrodev.com>
parents:
1860
diff
changeset
|
931 if (joysticks[joystick]) { |
fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
Michael Pavone <pavone@retrodev.com>
parents:
1860
diff
changeset
|
932 handle_joy_added(joystick); |
fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
Michael Pavone <pavone@retrodev.com>
parents:
1860
diff
changeset
|
933 } |
1860
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
934 return desired_index; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
935 } |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
936 |
2308
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
937 static float ui_scale_x = 1.0f, ui_scale_y = 1.0f; |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
938 int render_ui_to_pixels_x(int ui) |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
939 { |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
940 return ui * ui_scale_x + 0.5f; |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
941 } |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
942 |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
943 int render_ui_to_pixels_y(int ui) |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
944 { |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
945 return ui * ui_scale_y + 0.5f; |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
946 } |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
947 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
948 static int32_t handle_event(SDL_Event *event) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
949 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
950 if (custom_event_handler) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
951 custom_event_handler(event); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
952 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
953 switch (event->type) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
954 case SDL_KEYDOWN: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
955 handle_keydown(event->key.keysym.sym, scancode_map[event->key.keysym.scancode]); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
956 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
957 case SDL_KEYUP: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
958 handle_keyup(event->key.keysym.sym, scancode_map[event->key.keysym.scancode]); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
959 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
960 case SDL_JOYBUTTONDOWN: |
2318
1c7329ac7f3f
Make UI respect stick deadzone
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
961 handle_joydown(render_find_joystick_index(event->jbutton.which), event->jbutton.button); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
962 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
963 case SDL_JOYBUTTONUP: |
2318
1c7329ac7f3f
Make UI respect stick deadzone
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
964 handle_joyup(lock_joystick_index(render_find_joystick_index(event->jbutton.which), -1), event->jbutton.button); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
965 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
966 case SDL_JOYHATMOTION: |
2318
1c7329ac7f3f
Make UI respect stick deadzone
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
967 handle_joy_dpad(lock_joystick_index(render_find_joystick_index(event->jhat.which), -1), event->jhat.hat, event->jhat.value); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
968 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
969 case SDL_JOYAXISMOTION: |
2318
1c7329ac7f3f
Make UI respect stick deadzone
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
970 handle_joy_axis(lock_joystick_index(render_find_joystick_index(event->jaxis.which), -1), event->jaxis.axis, event->jaxis.value); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
971 break; |
2679
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
972 case SDL_JOYDEVICEADDED: { |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
973 int index = lowest_unused_joystick_index(); |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
974 if (index >= 0) { |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
975 SDL_Joystick * joy = SDL_JoystickOpen(event->jdevice.which); |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
976 if (SDL_JoystickNumAxes(joy) == 3 && SDL_JoystickNumButtons(joy) == 0) { |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
977 //probably just an acclerometer or gyro |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
978 SDL_JoystickClose(joy); |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
979 break; |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
980 } |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
981 joysticks[index] = joy; |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
982 joystick_sdl_index[index] = event->jdevice.which; |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
983 joystick_index_locked[index] = 0; |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
984 if (gc_events_enabled) { |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
985 controllers[index] = SDL_GameControllerOpen(event->jdevice.which); |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
986 } |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
987 if (joy) { |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
988 debug_message("Joystick %d added: %s\n", index, SDL_JoystickName(joy)); |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
989 debug_message("\tNum Axes: %d\n\tNum Buttons: %d\n\tNum Hats: %d\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy)); |
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
990 handle_joy_added(index); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
991 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
992 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
993 break; |
2679
69c1093f8726
Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
Michael Pavone <pavone@retrodev.com>
parents:
2667
diff
changeset
|
994 } |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
995 case SDL_JOYDEVICEREMOVED: { |
2318
1c7329ac7f3f
Make UI respect stick deadzone
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
996 int index = render_find_joystick_index(event->jdevice.which); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
997 if (index >= 0) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
998 SDL_JoystickClose(joysticks[index]); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
999 joysticks[index] = NULL; |
1862
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
1000 if (controllers[index]) { |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
1001 SDL_GameControllerClose(controllers[index]); |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
1002 controllers[index] = NULL; |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
1003 } |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1004 debug_message("Joystick %d removed\n", index); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1005 } else { |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1006 debug_message("Failed to find removed joystick with instance ID: %d\n", index); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1007 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1008 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1009 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1010 case SDL_MOUSEMOTION: |
2308
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1011 handle_mouse_moved(event->motion.which, event->motion.x * ui_scale_x + 0.5f, event->motion.y * ui_scale_y + 0.5f + overscan_top[video_standard], event->motion.xrel, event->motion.yrel); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1012 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1013 case SDL_MOUSEBUTTONDOWN: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1014 handle_mousedown(event->button.which, event->button.button); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1015 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1016 case SDL_MOUSEBUTTONUP: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1017 handle_mouseup(event->button.which, event->button.button); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1018 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1019 case SDL_WINDOWEVENT: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1020 switch (event->window.event) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1021 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1022 case SDL_WINDOWEVENT_SIZE_CHANGED: |
1820
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
1023 if (!main_window) { |
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
1024 break; |
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
1025 } |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1026 need_ui_fb_resize = 1; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1027 #ifndef DISABLE_OPENGL |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1028 if (render_gl) { |
2387
ff2f18dac84b
Fix issue that broke debug views when toggling fullscreen
Michael Pavone <pavone@retrodev.com>
parents:
2376
diff
changeset
|
1029 SDL_GL_MakeCurrent(main_window, main_context); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1030 if (on_context_destroyed) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1031 on_context_destroyed(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1032 } |
1593
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
1033 gl_teardown(); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1034 SDL_GL_DeleteContext(main_context); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1035 main_context = SDL_GL_CreateContext(main_window); |
2308
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1036 SDL_GL_GetDrawableSize(main_window, &main_width, &main_height); |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1037 update_aspect(); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1038 gl_setup(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1039 if (on_context_created) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1040 on_context_created(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1041 } |
2308
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1042 } else { |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1043 #endif |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1044 SDL_GetRendererOutputSize(main_renderer, &main_width, &main_height); |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1045 update_aspect(); |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1046 #ifndef DISABLE_OPENGL |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1047 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1048 #endif |
2308
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1049 if (main_width != event->window.data1 || main_height != event->window.data2) { |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1050 debug_message("Window resized - UI units %dx%d, pixels %dx%d\n", event->window.data1, event->window.data2, main_width, main_height); |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1051 } else { |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1052 debug_message("Window resized: %dx%d\n", main_width, main_height); |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1053 } |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1054 ui_scale_x = (float)main_width / (float)event->window.data1; |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1055 ui_scale_y = (float)main_height / (float)event->window.data2; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1056 break; |
1649
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1057 case SDL_WINDOWEVENT_CLOSE: |
1820
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
1058 if (main_window && SDL_GetWindowID(main_window) == event->window.windowID) { |
1649
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1059 exit(0); |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1060 } else { |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1061 for (int i = 0; i < num_extras; i++) |
1649
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1062 { |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1063 if (SDL_GetWindowID(extras[i].win) == event->window.windowID) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1064 if (extras[i].on_close) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1065 extras[i].on_close(i + FRAMEBUFFER_USER_START); |
1649
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1066 } |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1067 break; |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1068 } |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1069 } |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1070 } |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1071 break; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1072 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1073 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1074 case SDL_DROPFILE: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1075 if (drag_drop_handler) { |
2404
6f8400ce7a0f
Fix reload of zipped and gzipped ROMS
Michael Pavone <pavone@retrodev.com>
parents:
2392
diff
changeset
|
1076 drag_drop_handler(strdup(event->drop.file)); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1077 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1078 SDL_free(event->drop.file); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1079 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1080 case SDL_QUIT: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1081 puts(""); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1082 exit(0); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1083 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1084 return 0; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1085 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1086 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1087 static void drain_events() |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1088 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1089 SDL_Event event; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1090 while(SDL_PollEvent(&event)) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1091 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1092 handle_event(&event); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1093 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1094 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1095 |
2200
f11f4399d64b
Crop display in game gear mode
Michael Pavone <pavone@retrodev.com>
parents:
2093
diff
changeset
|
1096 static char *vid_std_names[NUM_VID_STD] = {"ntsc", "pal", "gamegear"}; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1097 static int display_hz; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1098 static int source_hz; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1099 static int source_frame; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1100 static int source_frame_count; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1101 static int frame_repeat[60]; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1102 |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
1103 static uint32_t sample_rate; |
2663
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1104 typedef struct { |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1105 int rate; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1106 int samples; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1107 uint16_t format; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1108 } audio_config; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1109 |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1110 static audio_config get_audio_config(void) |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1111 { |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1112 audio_config ret; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1113 char * rate_str = tern_find_path(config, "audio\0rate\0", TVAL_PTR).ptrval; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1114 ret.rate = rate_str ? atoi(rate_str) : 0; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1115 if (!ret.rate) { |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1116 ret.rate = 48000; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1117 } |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1118 char *config_format = tern_find_path_default(config, "audio\0format\0", (tern_val){.ptrval="f32"}, TVAL_PTR).ptrval; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1119 ret.format = !strcmp(config_format, "s16") ? AUDIO_S16SYS : AUDIO_F32SYS; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1120 char * samples_str = tern_find_path(config, "audio\0buffer\0", TVAL_PTR).ptrval; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1121 ret.samples = samples_str ? atoi(samples_str) : 0; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1122 if (!ret.samples) { |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1123 ret.samples = 512; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1124 } |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1125 return ret; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1126 } |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1127 |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1128 static audio_config current_audio_config; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1129 static void init_audio(void) |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1130 { |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1131 SDL_AudioSpec desired, actual; |
2663
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1132 audio_config ac = get_audio_config(); |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1133 desired.freq = ac.rate; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1134 desired.format = ac.format; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1135 desired.channels = 2; |
2663
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1136 desired.samples = ac.samples * 2; |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1137 switch (sync_src) |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1138 { |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1139 case SYNC_AUDIO: |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1140 desired.callback = audio_callback; |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1141 break; |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1142 case SYNC_AUDIO_THREAD: |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1143 desired.callback = audio_callback_run_on_audio; |
1978
33d5b9b77aef
Fix regression in run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1977
diff
changeset
|
1144 break; |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1145 default: |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1146 desired.callback = audio_callback_drc; |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1147 } |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1148 desired.userdata = NULL; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1149 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1150 if (SDL_OpenAudio(&desired, &actual) < 0) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1151 fatal_error("Unable to open SDL audio: %s\n", SDL_GetError()); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1152 } |
2663
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1153 current_audio_config = ac; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1154 sample_rate = actual.freq; |
2663
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1155 debug_message("Initialized %d channel audio at frequency %d with a %d sample buffer, ", actual.channels, actual.freq, actual.samples); |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
1156 render_audio_format format = RENDER_AUDIO_UNKNOWN; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1157 if (actual.format == AUDIO_S16SYS) { |
1810
73a9d06413bc
Restore some newlines in debug output that got lost when fixing GDB remote debugging issue
Michael Pavone <pavone@retrodev.com>
parents:
1809
diff
changeset
|
1158 debug_message("signed 16-bit int format\n"); |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
1159 format = RENDER_AUDIO_S16; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1160 } else if (actual.format == AUDIO_F32SYS) { |
1810
73a9d06413bc
Restore some newlines in debug output that got lost when fixing GDB remote debugging issue
Michael Pavone <pavone@retrodev.com>
parents:
1809
diff
changeset
|
1161 debug_message("32-bit float format\n"); |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
1162 format = RENDER_AUDIO_FLOAT; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1163 } else { |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1164 debug_message("unsupported format %X\n", actual.format); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1165 warning("Unsupported audio sample format: %X\n", actual.format); |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
1166 } |
2640
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
1167 #ifdef __EMSCRIPTEN__ |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
1168 if (sync_src == SYNC_AUDIO) { |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
1169 printf("emscripten_set_main_loop_timing %d\n", actual.samples * 500 / actual.freq); |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
1170 emscripten_set_main_loop_timing(EM_TIMING_SETTIMEOUT, actual.samples * 500 / actual.freq); |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
1171 } |
c30e5548154f
Get sync to audio working in emscripten
Michael Pavone <pavone@retrodev.com>
parents:
2638
diff
changeset
|
1172 #endif |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
1173 render_audio_initialized(format, actual.freq, actual.channels, actual.samples, SDL_AUDIO_BITSIZE(actual.format) / 8); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1174 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1175 |
2392
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
1176 static void update_cursor(void) |
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
1177 { |
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
1178 SDL_ShowCursor((is_fullscreen && !force_cursor) ? SDL_DISABLE : SDL_ENABLE); |
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
1179 } |
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
1180 |
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
1181 void render_force_cursor(uint8_t force) |
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
1182 { |
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
1183 if (force != force_cursor) { |
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
1184 force_cursor = force; |
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
1185 update_cursor(); |
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
1186 } |
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
1187 } |
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
1188 |
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
1189 static void window_setup(void) |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1190 { |
2308
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1191 uint32_t flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1192 if (is_fullscreen) { |
719
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
1193 flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1194 } |
2392
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
1195 update_cursor(); |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1196 |
1659
19331a21da3a
Switched default sync source back to audio as the video option is not ready for prime timeop
Mike Pavone <pavone@retrodev.com>
parents:
1658
diff
changeset
|
1197 tern_val def = {.ptrval = "audio"}; |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1198 if (external_sync) { |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1199 sync_src = SYNC_EXTERNAL; |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1200 } else { |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1201 char *sync_src_str = tern_find_path_default(config, "system\0sync_source\0", def, TVAL_PTR).ptrval; |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1202 if (!strcmp(sync_src_str, "audio")) { |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1203 sync_src = SYNC_AUDIO; |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1204 } else if (!strcmp(sync_src_str, "audio_thread")) { |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1205 sync_src = SYNC_AUDIO_THREAD; |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1206 } else { |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1207 sync_src = SYNC_VIDEO; |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1208 } |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1209 } |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1210 |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1211 if (!num_buffers && (sync_src == SYNC_AUDIO_THREAD || sync_src == SYNC_EXTERNAL)) { |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1212 frame_mutex = SDL_CreateMutex(); |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1213 free_buffer_mutex = SDL_CreateMutex(); |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1214 frame_ready = SDL_CreateCond(); |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1215 buffer_storage = 4; |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
1216 frame_buffers = calloc(buffer_storage, sizeof(pixel_t*)); |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1217 frame_buffers[0] = texture_buf; |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1218 num_buffers = 1; |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1219 } |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1220 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1221 const char *vsync; |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
1222 if (sync_src == SYNC_AUDIO) { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1223 def.ptrval = "off"; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1224 vsync = tern_find_path_default(config, "video\0vsync\0", def, TVAL_PTR).ptrval; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1225 } else { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1226 vsync = "on"; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1227 } |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1228 |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
1229 tern_node *video = tern_find_node(config, "video"); |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1230 if (video) |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1231 { |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1232 for (int i = 0; i < NUM_VID_STD; i++) |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1233 { |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
1234 tern_node *std_settings = tern_find_node(video, vid_std_names[i]); |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1235 if (std_settings) { |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
1236 char *val = tern_find_path_default(std_settings, "overscan\0top\0", (tern_val){.ptrval = NULL}, TVAL_PTR).ptrval; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1237 if (val) { |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1238 overscan_top[i] = atoi(val); |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1239 } |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
1240 val = tern_find_path_default(std_settings, "overscan\0bottom\0", (tern_val){.ptrval = NULL}, TVAL_PTR).ptrval; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1241 if (val) { |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1242 overscan_bot[i] = atoi(val); |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1243 } |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
1244 val = tern_find_path_default(std_settings, "overscan\0left\0", (tern_val){.ptrval = NULL}, TVAL_PTR).ptrval; |
1267
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
1245 if (val) { |
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
1246 overscan_left[i] = atoi(val); |
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
1247 } |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
1248 val = tern_find_path_default(std_settings, "overscan\0right\0", (tern_val){.ptrval = NULL}, TVAL_PTR).ptrval; |
1267
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
1249 if (val) { |
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
1250 overscan_right[i] = atoi(val); |
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
1251 } |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1252 } |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1253 } |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1254 } |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1255 render_gl = 0; |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1256 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1257 #ifndef DISABLE_OPENGL |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1258 char *gl_enabled_str = tern_find_path_default(config, "video\0gl\0", def, TVAL_PTR).ptrval; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1259 uint8_t gl_enabled = strcmp(gl_enabled_str, "off") != 0; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1260 if (gl_enabled) |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1261 { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1262 flags |= SDL_WINDOW_OPENGL; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1263 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1264 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1265 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1266 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1267 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1268 #ifdef USE_GLES |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1269 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1270 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1271 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1272 #endif |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1273 } |
1074
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
1274 #endif |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1275 main_window = SDL_CreateWindow(caption, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, main_width, main_height, flags); |
719
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
1276 if (!main_window) { |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1277 fatal_error("Unable to create SDL window: %s\n", SDL_GetError()); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1278 } |
2308
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1279 SDL_GetWindowSize(main_window, &main_width, &main_height); |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1280 debug_message("Window created with size: %d x %d\n", main_width, main_height); |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1281 int orig_width = main_width, orig_height = main_height; |
1074
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
1282 #ifndef DISABLE_OPENGL |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1283 if (gl_enabled) |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1284 { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1285 main_context = SDL_GL_CreateContext(main_window); |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1286 #ifdef USE_GLES |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1287 int major_version; |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1288 if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major_version) == 0 && major_version >= 2) { |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1289 #else |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1290 GLenum res = glewInit(); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1291 if (res != GLEW_OK) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1292 warning("Initialization of GLEW failed with code %d\n", res); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1293 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1294 |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1295 if (res == GLEW_OK && GLEW_VERSION_2_0) { |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1296 #endif |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1297 render_gl = 1; |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1298 SDL_GL_MakeCurrent(main_window, main_context); |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1299 if (!strcmp("tear", vsync)) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1300 if (SDL_GL_SetSwapInterval(-1) < 0) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1301 warning("late tear is not available (%s), using normal vsync\n", SDL_GetError()); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1302 vsync = "on"; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1303 } else { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1304 vsync = NULL; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1305 } |
1004
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
1306 } |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1307 if (vsync) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1308 if (SDL_GL_SetSwapInterval(!strcmp("on", vsync)) < 0) { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
1309 #ifdef __ANDROID__ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
1310 debug_message("Failed to set vsync to %s: %s\n", vsync, SDL_GetError()); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
1311 #else |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1312 warning("Failed to set vsync to %s: %s\n", vsync, SDL_GetError()); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
1313 #endif |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1314 } |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1315 } |
2308
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1316 SDL_GL_GetDrawableSize(main_window, &main_width, &main_height); |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1317 } else { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1318 warning("OpenGL 2.0 is unavailable, falling back to SDL2 renderer\n"); |
1004
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
1319 } |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1320 } |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1321 if (!render_gl) { |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1322 #endif |
1004
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
1323 flags = SDL_RENDERER_ACCELERATED; |
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
1324 if (!strcmp("on", vsync) || !strcmp("tear", vsync)) { |
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
1325 flags |= SDL_RENDERER_PRESENTVSYNC; |
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
1326 } |
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
1327 main_renderer = SDL_CreateRenderer(main_window, -1, flags); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1328 |
1074
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
1329 if (!main_renderer) { |
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
1330 fatal_error("unable to create SDL renderer: %s\n", SDL_GetError()); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1331 } |
2308
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1332 SDL_GetRendererOutputSize(main_renderer, &main_width, &main_height); |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1333 SDL_RendererInfo rinfo; |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1334 SDL_GetRendererInfo(main_renderer, &rinfo); |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1335 debug_message("SDL2 Render Driver: %s\n", rinfo.name); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1336 main_clip.x = main_clip.y = 0; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1337 main_clip.w = main_width; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1338 main_clip.h = main_height; |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1339 #ifndef DISABLE_OPENGL |
719
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
1340 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
1341 #endif |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1342 |
2308
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1343 if (main_width != orig_width || main_height != orig_height) { |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1344 debug_message("True window resolution %d x %d\n", main_width, main_height); |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1345 } |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1346 ui_scale_x = (float)main_width / (float)orig_width; |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1347 ui_scale_y = (float)main_height / (float)orig_height; |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1348 |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1349 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1350 update_aspect(); |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1351 render_alloc_surfaces(); |
1004
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
1352 def.ptrval = "off"; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
1353 scanlines = !strcmp(tern_find_path_default(config, "video\0scanlines\0", def, TVAL_PTR).ptrval, "on"); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1354 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1355 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1356 void render_init(int width, int height, char * title, uint8_t fullscreen) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1357 { |
2308
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1358 #ifdef SDL_HINT_WINDOWS_DPI_SCALING |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1359 //In some ways, the other DPI scaling option for SDL2 on Windows is better for BlastEm's needs, |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1360 //but setting this makes it more consistent with how high DPI support works on other platforms |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1361 SDL_SetHint(SDL_HINT_WINDOWS_DPI_SCALING, "1"); |
b7768c58f0da
Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents:
2303
diff
changeset
|
1362 #endif |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1363 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1364 fatal_error("Unable to init SDL: %s\n", SDL_GetError()); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1365 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1366 atexit(SDL_Quit); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1367 if (height <= 0) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1368 float aspect = config_aspect() > 0.0f ? config_aspect() : 4.0f/3.0f; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1369 height = ((float)width / aspect) + 0.5f; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1370 } |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1371 debug_message("width: %d, height: %d\n", width, height); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1372 windowed_width = width; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1373 windowed_height = height; |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1374 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1375 SDL_DisplayMode mode; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1376 //TODO: Explicit multiple monitor support |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1377 SDL_GetCurrentDisplayMode(0, &mode); |
2600
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
1378 #ifdef __EMSCRIPTEN__ |
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
1379 display_hz = 60; //TODO: FIXME |
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
1380 #else |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1381 display_hz = mode.refresh_rate; |
2600
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
1382 #endif |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1383 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1384 if (fullscreen) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1385 //the SDL2 migration guide suggests setting width and height to 0 when using SDL_WINDOW_FULLSCREEN_DESKTOP |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1386 //but that doesn't seem to work right when using OpenGL, at least on Linux anyway |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1387 width = mode.w; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1388 height = mode.h; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1389 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1390 main_width = width; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1391 main_height = height; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1392 is_fullscreen = fullscreen; |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1393 |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
1394 caption = title; |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1395 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1396 window_setup(); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1397 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1398 audio_mutex = SDL_CreateMutex(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1399 audio_ready = SDL_CreateCond(); |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1400 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1401 init_audio(); |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1402 |
1355
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1403 uint32_t db_size; |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1404 char *db_data = read_bundled_file("gamecontrollerdb.txt", &db_size); |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1405 if (db_data) { |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1406 int added = SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(db_data, db_size), 1); |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1407 free(db_data); |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1408 debug_message("Added %d game controller mappings from gamecontrollerdb.txt\n", added); |
1355
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1409 } |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1410 |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
1411 controller_add_mappings(); |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1412 |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1413 SDL_JoystickEventState(SDL_ENABLE); |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1414 |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1415 render_set_video_standard(VID_NTSC); |
874
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
1416 |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
1417 atexit(render_quit); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1418 } |
2018
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2004
diff
changeset
|
1419 |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2004
diff
changeset
|
1420 void render_reset_mappings(void) |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2004
diff
changeset
|
1421 { |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2004
diff
changeset
|
1422 SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER); |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2004
diff
changeset
|
1423 SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER); |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2004
diff
changeset
|
1424 uint32_t db_size; |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2004
diff
changeset
|
1425 char *db_data = read_bundled_file("gamecontrollerdb.txt", &db_size); |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2004
diff
changeset
|
1426 if (db_data) { |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2004
diff
changeset
|
1427 int added = SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(db_data, db_size), 1); |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2004
diff
changeset
|
1428 free(db_data); |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2004
diff
changeset
|
1429 debug_message("Added %d game controller mappings from gamecontrollerdb.txt\n", added); |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2004
diff
changeset
|
1430 } |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2004
diff
changeset
|
1431 } |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1432 static int in_toggle; |
1590
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1433 |
2664
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1434 #ifdef __EMSCRIPTEN__ |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1435 void resume_config_update(void *arg) |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1436 { |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1437 uint8_t was_paused = arg != NULL; |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1438 quitting = 0; |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1439 init_audio(); |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1440 render_set_video_standard(video_standard); |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1441 |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1442 drain_events(); |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1443 in_toggle = 0; |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1444 if (!was_paused) { |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1445 SDL_PauseAudio(0); |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1446 } |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1447 emscripten_resume_main_loop(); |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1448 } |
2667 | 1449 #endif //__EMSCRIPTEN__ |
2664
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1450 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1451 void render_config_updated(void) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1452 { |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1453 for (int i = 0; i <= FRAMEBUFFER_UI; i++) |
2388
a8c069d847a0
Fix issue that would break debug windows when config update causes window to be recreated
Michael Pavone <pavone@retrodev.com>
parents:
2387
diff
changeset
|
1454 { |
a8c069d847a0
Fix issue that would break debug windows when config update causes window to be recreated
Michael Pavone <pavone@retrodev.com>
parents:
2387
diff
changeset
|
1455 if (sdl_textures[i]) { |
a8c069d847a0
Fix issue that would break debug windows when config update causes window to be recreated
Michael Pavone <pavone@retrodev.com>
parents:
2387
diff
changeset
|
1456 SDL_DestroyTexture(sdl_textures[i]); |
a8c069d847a0
Fix issue that would break debug windows when config update causes window to be recreated
Michael Pavone <pavone@retrodev.com>
parents:
2387
diff
changeset
|
1457 sdl_textures[i] = NULL; |
a8c069d847a0
Fix issue that would break debug windows when config update causes window to be recreated
Michael Pavone <pavone@retrodev.com>
parents:
2387
diff
changeset
|
1458 } |
a8c069d847a0
Fix issue that would break debug windows when config update causes window to be recreated
Michael Pavone <pavone@retrodev.com>
parents:
2387
diff
changeset
|
1459 } |
a8c069d847a0
Fix issue that would break debug windows when config update causes window to be recreated
Michael Pavone <pavone@retrodev.com>
parents:
2387
diff
changeset
|
1460 texture_init = 0; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1461 #ifndef DISABLE_OPENGL |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1462 if (render_gl) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1463 if (on_context_destroyed) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1464 on_context_destroyed(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1465 } |
1593
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
1466 gl_teardown(); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1467 SDL_GL_DeleteContext(main_context); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1468 } else { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1469 #endif |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1470 SDL_DestroyRenderer(main_renderer); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1471 #ifndef DISABLE_OPENGL |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1472 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1473 #endif |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1474 in_toggle = 1; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1475 SDL_DestroyWindow(main_window); |
1820
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
1476 main_window = NULL; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1477 drain_events(); |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1478 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1479 char *config_width = tern_find_path(config, "video\0width\0", TVAL_PTR).ptrval; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1480 if (config_width) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1481 windowed_width = atoi(config_width); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1482 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1483 char *config_height = tern_find_path(config, "video\0height\0", TVAL_PTR).ptrval; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1484 if (config_height) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1485 windowed_height = atoi(config_height); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1486 } else { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1487 float aspect = config_aspect() > 0.0f ? config_aspect() : 4.0f/3.0f; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1488 windowed_height = ((float)windowed_width / aspect) + 0.5f; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1489 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1490 char *config_fullscreen = tern_find_path(config, "video\0fullscreen\0", TVAL_PTR).ptrval; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1491 is_fullscreen = config_fullscreen && !strcmp("on", config_fullscreen); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1492 if (is_fullscreen) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1493 SDL_DisplayMode mode; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1494 //TODO: Multiple monitor support |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1495 SDL_GetCurrentDisplayMode(0, &mode); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1496 main_width = mode.w; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1497 main_height = mode.h; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1498 } else { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1499 main_width = windowed_width; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1500 main_height = windowed_height; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1501 } |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1502 if (on_ui_fb_resized) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1503 on_ui_fb_resized(); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1504 } |
2663
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1505 uint8_t old_sync_src = sync_src; |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1506 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1507 window_setup(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1508 update_aspect(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1509 #ifndef DISABLE_OPENGL |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1510 //need to check render_gl again after window_setup as render option could have changed |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1511 if (render_gl && on_context_created) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1512 on_context_created(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1513 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1514 #endif |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1515 |
2663
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1516 |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1517 uint8_t was_paused = 1; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1518 uint8_t do_audio_reinit = sync_src != old_sync_src; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1519 if (!do_audio_reinit) { |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1520 audio_config ac = get_audio_config(); |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1521 do_audio_reinit = ac.rate != current_audio_config.rate || |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1522 ac.samples != current_audio_config.samples || ac.format != current_audio_config.format; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1523 } |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1524 if (do_audio_reinit) { |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1525 was_paused = SDL_GetAudioStatus() == SDL_AUDIO_PAUSED; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1526 render_close_audio(); |
2664
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1527 #ifdef __EMSCRIPTEN__ |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1528 emscripten_pause_main_loop(); |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1529 emscripten_async_call(resume_config_update, was_paused ? config : NULL, 1000); |
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1530 #else |
2663
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1531 quitting = 0; |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1532 init_audio(); |
2664
36ae207af490
Awful hack to work around what seems like a bug in the Emscripten version of SDL2
Michael Pavone <pavone@retrodev.com>
parents:
2663
diff
changeset
|
1533 #endif |
2663
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1534 } |
1590
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1535 render_set_video_standard(video_standard); |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1536 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1537 drain_events(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1538 in_toggle = 0; |
1590
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1539 if (!was_paused) { |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1540 SDL_PauseAudio(0); |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1541 } |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1542 } |
719
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
1543 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1544 SDL_Window *render_get_window(void) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1545 { |
2493
b62336ceb626
Kinda hacky fix to make sure Nuklear has the right GL context
Michael Pavone <pavone@retrodev.com>
parents:
2492
diff
changeset
|
1546 #ifndef DISABLE_OPENGL |
b62336ceb626
Kinda hacky fix to make sure Nuklear has the right GL context
Michael Pavone <pavone@retrodev.com>
parents:
2492
diff
changeset
|
1547 if (render_gl) { |
b62336ceb626
Kinda hacky fix to make sure Nuklear has the right GL context
Michael Pavone <pavone@retrodev.com>
parents:
2492
diff
changeset
|
1548 SDL_GL_MakeCurrent(main_window, main_context); |
b62336ceb626
Kinda hacky fix to make sure Nuklear has the right GL context
Michael Pavone <pavone@retrodev.com>
parents:
2492
diff
changeset
|
1549 } |
b62336ceb626
Kinda hacky fix to make sure Nuklear has the right GL context
Michael Pavone <pavone@retrodev.com>
parents:
2492
diff
changeset
|
1550 #endif |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1551 return main_window; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1552 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1553 |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
1554 uint32_t render_audio_syncs_per_sec(void) |
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
1555 { |
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
1556 //sync samples with audio thread approximately every 8 lines when doing sync to video |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
1557 return render_is_audio_sync() ? 0 : source_hz * (video_standard == VID_PAL ? 313 : 262) / 8; |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
1558 } |
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
1559 |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1560 void render_set_video_standard(vid_std std) |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1561 { |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1562 video_standard = std; |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
1563 if (render_is_audio_sync()) { |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
1564 return; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
1565 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1566 source_hz = std == VID_PAL ? 50 : 60; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1567 uint32_t max_repeat = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1568 if (abs(source_hz - display_hz) < 2) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1569 memset(frame_repeat, 0, sizeof(int)*display_hz); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1570 } else { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1571 int inc = display_hz * 100000 / source_hz; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1572 int accum = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1573 int dst_frames = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1574 for (int src_frame = 0; src_frame < source_hz; src_frame++) |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1575 { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1576 frame_repeat[src_frame] = -1; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1577 accum += inc; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1578 while (accum > 100000) |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1579 { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1580 accum -= 100000; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1581 frame_repeat[src_frame]++; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1582 max_repeat = frame_repeat[src_frame] > max_repeat ? frame_repeat[src_frame] : max_repeat; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1583 dst_frames++; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1584 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1585 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1586 if (dst_frames != display_hz) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1587 frame_repeat[source_hz-1] += display_hz - dst_frames; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1588 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1589 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1590 source_frame = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1591 source_frame_count = frame_repeat[0]; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1592 max_repeat++; |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1593 min_buffered = (((float)max_repeat * (float)sample_rate/(float)source_hz)/* / (float)buffer_samples*/);// + 0.9999; |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1594 //min_buffered *= buffer_samples; |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1595 debug_message("Min samples buffered before audio start: %d\n", min_buffered); |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1596 max_adjust = BASE_MAX_ADJUST / source_hz; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1597 } |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1598 |
874
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
1599 void render_update_caption(char *title) |
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
1600 { |
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
1601 caption = title; |
1068
624696318b5b
Fix a memory corruption bug from failing to grow the buffer for the window caption when switching games
Michael Pavone <pavone@retrodev.com>
parents:
1033
diff
changeset
|
1602 free(fps_caption); |
624696318b5b
Fix a memory corruption bug from failing to grow the buffer for the window caption when switching games
Michael Pavone <pavone@retrodev.com>
parents:
1033
diff
changeset
|
1603 fps_caption = NULL; |
874
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
1604 } |
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
1605 |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1606 static char *screenshot_path; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1607 void render_save_screenshot(char *path) |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1608 { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1609 if (screenshot_path) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1610 free(screenshot_path); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1611 } |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1612 screenshot_path = path; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1613 } |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1614 |
2295
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1615 #ifndef DISABLE_ZLIB |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1616 static apng_state *apng; |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1617 static FILE *apng_file; |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1618 #endif |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1619 uint8_t render_saving_video(void) |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1620 { |
2553
35f765c2bc87
Fix a couple of bugs with AV recording
Michael Pavone <pavone@retrodev.com>
parents:
2532
diff
changeset
|
1621 #ifndef DISABLE_ZLIB |
2295
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1622 return apng_file != NULL; |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1623 #else |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1624 return 0; |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1625 #endif |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1626 } |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1627 |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1628 void render_end_video(void) |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1629 { |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1630 #ifndef DISABLE_ZLIB |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1631 if (apng) { |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1632 puts("Ending recording"); |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1633 end_apng(apng_file, apng); |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1634 apng = NULL; |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1635 apng_file = NULL; |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1636 } |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1637 #endif |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1638 } |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1639 void render_save_video(char *path) |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1640 { |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1641 render_end_video(); |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1642 #ifndef DISABLE_ZLIB |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1643 apng_file = fopen(path, "wb"); |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1644 if (apng_file) { |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1645 printf("Saving video to %s\n", path); |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1646 } else { |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1647 warning("Failed to open %s for writing\n", path); |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1648 } |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1649 #endif |
2303
c79896ff1a2d
Fix leak in render_save_video
Michael Pavone <pavone@retrodev.com>
parents:
2295
diff
changeset
|
1650 free(path); |
2295
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1651 } |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
1652 |
2638
f5603b4ee14d
Fixup some ifdefs to allow building for some more targets
Michael Pavone <pavone@retrodev.com>
parents:
2600
diff
changeset
|
1653 #ifdef GL_DEBUG_OUTPUT |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1654 void GLAPIENTRY gl_message_callback(GLenum source, GLenum type, GLenum id, GLenum severity, GLsizei length, const GLchar *message, const void *user) |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1655 { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1656 fprintf(stderr, "GL Message: %d, %d, %d - %s\n", source, type, severity, message); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1657 } |
2600
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
1658 #endif |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1659 |
1649
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1660 uint8_t render_create_window(char *caption, uint32_t width, uint32_t height, window_close_handler close_handler) |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1661 { |
1642
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1662 uint8_t win_idx = 0xFF; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1663 for (int i = 0; i < num_extras; i++) |
1642
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1664 { |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1665 if (!extras[i].win) { |
1642
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1666 win_idx = i; |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1667 break; |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1668 } |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1669 } |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1670 |
1642
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1671 if (win_idx == 0xFF) { |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1672 num_extras++; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1673 extras = realloc(extras, num_extras * sizeof(*extras)); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1674 win_idx = num_extras - 1; |
1642
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1675 } |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1676 memset(&extras[win_idx], 0, sizeof(extra_window)); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1677 uint32_t flags = 0; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1678 #ifndef DISABLE_OPENGL |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1679 if (render_gl) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1680 flags |= SDL_WINDOW_OPENGL; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1681 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1682 #endif |
2458
09c9d2c6bac0
Avoid spawning secondary windows right on top of the main one
Michael Pavone <pavone@retrodev.com>
parents:
2438
diff
changeset
|
1683 int x = SDL_WINDOWPOS_UNDEFINED; |
09c9d2c6bac0
Avoid spawning secondary windows right on top of the main one
Michael Pavone <pavone@retrodev.com>
parents:
2438
diff
changeset
|
1684 int y = SDL_WINDOWPOS_UNDEFINED; |
09c9d2c6bac0
Avoid spawning secondary windows right on top of the main one
Michael Pavone <pavone@retrodev.com>
parents:
2438
diff
changeset
|
1685 SDL_GetWindowPosition(main_window, &x, &y); |
09c9d2c6bac0
Avoid spawning secondary windows right on top of the main one
Michael Pavone <pavone@retrodev.com>
parents:
2438
diff
changeset
|
1686 if (x != SDL_WINDOWPOS_UNDEFINED) { |
09c9d2c6bac0
Avoid spawning secondary windows right on top of the main one
Michael Pavone <pavone@retrodev.com>
parents:
2438
diff
changeset
|
1687 x += main_width; |
09c9d2c6bac0
Avoid spawning secondary windows right on top of the main one
Michael Pavone <pavone@retrodev.com>
parents:
2438
diff
changeset
|
1688 } |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1689 extras[win_idx].win = SDL_CreateWindow(caption, x, y, width, height, flags); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1690 if (!extras[win_idx].win) { |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1691 goto fail_window; |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1692 } |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1693 extras[win_idx].width = width; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1694 extras[win_idx].height = height; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1695 #ifndef DISABLE_OPENGL |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1696 if (render_gl) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1697 extras[win_idx].gl_context = SDL_GL_CreateContext(extras[win_idx].win); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1698 SDL_GL_MakeCurrent(extras[win_idx].win, extras[win_idx].gl_context); |
2638
f5603b4ee14d
Fixup some ifdefs to allow building for some more targets
Michael Pavone <pavone@retrodev.com>
parents:
2600
diff
changeset
|
1699 #ifdef GL_DEBUG_OUTPUT |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1700 glEnable(GL_DEBUG_OUTPUT); |
2523
573da2a2e6bb
Fix debug window crash on Mac OS
Michael Pavone <pavone@retrodev.com>
parents:
2514
diff
changeset
|
1701 if (glDebugMessageCallback) { |
573da2a2e6bb
Fix debug window crash on Mac OS
Michael Pavone <pavone@retrodev.com>
parents:
2514
diff
changeset
|
1702 glDebugMessageCallback(gl_message_callback, NULL); |
573da2a2e6bb
Fix debug window crash on Mac OS
Michael Pavone <pavone@retrodev.com>
parents:
2514
diff
changeset
|
1703 } |
2600
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
1704 #endif |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1705 glGenTextures(2, extras[win_idx].gl_texture); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1706 for (int i = 0; i < 2; i++) |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1707 { |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1708 glBindTexture(GL_TEXTURE_2D, extras[win_idx].gl_texture[i]); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1709 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1710 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1711 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1712 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1713 if (i) { |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
1714 glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT, 1, 1, 0, SRC_FORMAT, SRC_TYPE, extras[win_idx].color); |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1715 } else { |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1716 extras[win_idx].tex_width = width; |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1717 extras[win_idx].tex_height = height; |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1718 char *npot_textures = tern_find_path_default(config, "video\0npot_textures\0", (tern_val){.ptrval = "off"}, TVAL_PTR).ptrval; |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1719 if (strcmp(npot_textures, "on")) { |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1720 extras[win_idx].tex_width = nearest_pow2(width); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1721 extras[win_idx].tex_height = nearest_pow2(height); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1722 } |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
1723 extras[win_idx].texture_buf = calloc(PITCH_PIXEL_T(extras[win_idx].tex_width) * extras[win_idx].tex_height, sizeof(pixel_t)); |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
1724 glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT, extras[win_idx].tex_width, extras[win_idx].tex_height, 0, SRC_FORMAT, SRC_TYPE, extras[win_idx].texture_buf); |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1725 } |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1726 } |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1727 glGenBuffers(3, extras[win_idx].gl_buffers); |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1728 glBindBuffer(GL_ARRAY_BUFFER, extras[win_idx].gl_buffers[0]); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1729 glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data_default), vertex_data_default, GL_STATIC_DRAW); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1730 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, extras[win_idx].gl_buffers[1]); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1731 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(element_data), element_data, GL_STATIC_DRAW); |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1732 glBindBuffer(GL_ARRAY_BUFFER, extras[win_idx].gl_buffers[2]); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1733 glBufferData(GL_ARRAY_BUFFER, sizeof(uvs), uvs, GL_STATIC_DRAW); |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1734 extras[win_idx].vshader = load_shader("extra_window.v.glsl", GL_VERTEX_SHADER); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1735 extras[win_idx].fshader = load_shader("extra_window.f.glsl", GL_FRAGMENT_SHADER); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1736 extras[win_idx].program = glCreateProgram(); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1737 glAttachShader(program, extras[win_idx].vshader); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1738 glAttachShader(program, extras[win_idx].fshader); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1739 glLinkProgram(extras[win_idx].program); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1740 GLint link_status; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1741 glGetProgramiv(program, GL_LINK_STATUS, &link_status); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1742 if (!link_status) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1743 fputs("Failed to link shader program\n", stderr); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1744 //TODO: cleanup |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1745 goto sdl_renderer; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1746 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1747 extras[win_idx].un_texture = glGetUniformLocation(program, "texture"); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1748 extras[win_idx].un_width = glGetUniformLocation(program, "width"); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1749 extras[win_idx].un_height = glGetUniformLocation(program, "height"); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1750 extras[win_idx].at_pos = glGetAttribLocation(program, "pos"); |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1751 extras[win_idx].at_uv = glGetAttribLocation(program, "uv"); |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1752 extras[win_idx].color[3] = 255; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1753 } else { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1754 sdl_renderer: |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1755 #endif |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1756 extras[win_idx].renderer = SDL_CreateRenderer(extras[win_idx].win, -1, SDL_RENDERER_ACCELERATED); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1757 if (!extras[win_idx].renderer) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1758 goto fail_renderer; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1759 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1760 extras[win_idx].sdl_texture = SDL_CreateTexture(extras[win_idx].renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1761 if (!extras[win_idx].sdl_texture) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1762 goto fail_texture; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1763 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1764 #ifndef DISABLE_OPENGL |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1765 } |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1766 #endif |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1767 extras[win_idx].on_close = close_handler; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1768 return win_idx + FRAMEBUFFER_USER_START; |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1769 |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1770 fail_texture: |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1771 SDL_DestroyRenderer(extras[win_idx].renderer); |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1772 fail_renderer: |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1773 SDL_DestroyWindow(extras[win_idx].win); |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1774 fail_window: |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1775 return 0; |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1776 } |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1777 |
1642
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1778 void render_destroy_window(uint8_t which) |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1779 { |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1780 uint8_t win_idx = which - FRAMEBUFFER_USER_START; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1781 if (extras[win_idx].renderer) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1782 //Destroying the renderers also frees the textures |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1783 SDL_DestroyRenderer(extras[win_idx].renderer); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1784 extras[win_idx].renderer = NULL; |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1785 free (extras[win_idx].static_images); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1786 extras[win_idx].static_images = NULL; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1787 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1788 #ifndef DISABLE_OPENGL |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1789 else { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1790 SDL_GL_MakeCurrent(extras[win_idx].win, extras[win_idx].gl_context); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1791 glDeleteProgram(extras[win_idx].program); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1792 glDeleteShader(extras[win_idx].vshader); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1793 glDeleteShader(extras[win_idx].fshader); |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1794 glDeleteBuffers(3, extras[win_idx].gl_buffers); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1795 glDeleteTextures(2, extras[win_idx].gl_texture); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1796 for (uint8_t i = 0; i < extras[win_idx].num_static; i++) |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1797 { |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1798 if (extras[win_idx].gl_static_images[i]) { |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1799 glDeleteTextures(1, extras[win_idx].gl_static_images + i); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1800 } |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1801 } |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1802 SDL_GL_DeleteContext(extras[win_idx].gl_context); |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1803 free(extras[win_idx].image_vertices); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1804 extras[win_idx].image_vertices = NULL; |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1805 free(extras[win_idx].gl_static_images); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1806 extras[win_idx].gl_static_images = NULL; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1807 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1808 #endif |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1809 SDL_DestroyWindow(extras[win_idx].win); |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
1810 |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1811 extras[win_idx].win = NULL; |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1812 extras[win_idx].num_static = 0; |
1642
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1813 } |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1814 |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1815 #ifndef DISABLE_OPENGL |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1816 static void extra_draw_quad(extra_window *extra, GLuint texture, float width, float height) |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1817 { |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1818 glUseProgram(extra->program); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1819 glActiveTexture(GL_TEXTURE0); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1820 glBindTexture(GL_TEXTURE_2D, texture); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1821 glUniform1i(extra->un_texture, 0); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1822 |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1823 glUniform1f(extra->un_width, width); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1824 glUniform1f(extra->un_height, height); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1825 |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1826 glVertexAttribPointer(extra->at_pos, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat[2]), (void *)0); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1827 glEnableVertexAttribArray(extra->at_pos); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1828 |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1829 glBindBuffer(GL_ARRAY_BUFFER, extra->gl_buffers[2]); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1830 glVertexAttribPointer(extra->at_uv, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat[2]), (void *)0); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1831 glEnableVertexAttribArray(extra->at_uv); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1832 |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1833 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, extra->gl_buffers[1]); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1834 glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, (void *)0); |
2663
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1835 glDisableVertexAttribArray(extra->at_pos); |
568c1c22f3e3
Allow changing at least some settings in web build without breaking
Michael Pavone <pavone@retrodev.com>
parents:
2644
diff
changeset
|
1836 glDisableVertexAttribArray(extra->at_uv); |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1837 } |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1838 #endif |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1839 |
2438
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2429
diff
changeset
|
1840 uint8_t render_static_image(uint8_t window, uint8_t *buffer, uint32_t size) |
2429
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1841 { |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1842 window -= FRAMEBUFFER_USER_START; |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1843 extra_window *extra = extras + window; |
2429
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1844 uint32_t width, height; |
2438
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2429
diff
changeset
|
1845 uint32_t *pixels = load_png(buffer, size, &width, &height); |
2429
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1846 if (!pixels) { |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1847 return 0xFF; |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1848 } |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1849 uint8_t img_index = 0; |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1850 if (!extra->num_static) { |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1851 extra->num_static = 8; |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1852 #ifndef DISABLE_OPENGL |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1853 if (render_gl) { |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1854 extra->gl_static_images = calloc(extra->num_static, sizeof(GLuint)); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1855 extra->image_vertices = malloc(sizeof(vertex_data_default)); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1856 memcpy(extra->image_vertices, vertex_data_default, sizeof(vertex_data_default)); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1857 SDL_GL_MakeCurrent(extra->win, extra->gl_context); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1858 glGenBuffers(1, &extra->image_buffer); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1859 glBindBuffer(GL_ARRAY_BUFFER, extra->image_buffer); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1860 glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data_default), extra->image_vertices, GL_DYNAMIC_DRAW); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1861 } else |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1862 #endif |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1863 { |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1864 extra->static_images = calloc(extra->num_static, sizeof(SDL_Texture*)); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1865 } |
2429
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1866 } |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1867 for (; img_index < extra->num_static; img_index++) |
2429
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1868 { |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1869 #ifndef DISABLE_OPENGL |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1870 if (render_gl) { |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1871 if (!extra->gl_static_images[img_index]) { |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1872 break; |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1873 } |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1874 } else |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1875 #endif |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1876 if (!extra->static_images[img_index]) { |
2429
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1877 break; |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1878 } |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1879 } |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1880 if (img_index == extra->num_static) { |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1881 extra->num_static *= 2; |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1882 #ifndef DISABLE_OPENGL |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1883 if (render_gl) { |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1884 extra->gl_static_images = realloc(extra->static_images, extra->num_static * sizeof(GLuint)); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1885 } else |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1886 #endif |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1887 { |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1888 extra->static_images = realloc(extra->static_images, extra->num_static * sizeof(SDL_Texture*)); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1889 } |
2429
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1890 } |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1891 #ifndef DISABLE_OPENGL |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1892 if (render_gl) { |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1893 SDL_GL_MakeCurrent(extra->win, extra->gl_context); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1894 |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1895 glGenTextures(1, extra->gl_static_images + img_index); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1896 glBindTexture(GL_TEXTURE_2D, extra->gl_static_images[img_index]); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1897 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1898 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1899 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1900 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1901 //TODO: maybe make this respect the npot texture setting? |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
1902 glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT, width, height, 0, SRC_FORMAT32, GL_UNSIGNED_BYTE, pixels); |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1903 } else |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1904 #endif |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1905 { |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1906 extra->static_images[img_index] = SDL_CreateTexture(extra->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, width, height); |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
1907 SDL_UpdateTexture(extra->static_images[img_index], NULL, pixels, sizeof(pixel_t) * width); |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1908 } |
2429
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1909 free(pixels); |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1910 return img_index; |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1911 } |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1912 |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1913 #ifndef DISABLE_OPENGL |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1914 static void extra_update_verts(extra_window *extra, int x, int y, int width, int height) |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1915 { |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1916 memcpy(extra->image_vertices, vertex_data_default, sizeof(vertex_data_default)); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1917 extra->image_vertices[0] = extra->image_vertices[4] = 2.0f * x / (float)extra->width - 1.0f; |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1918 extra->image_vertices[2] = extra->image_vertices[6] = 2.0f * (x + width) / (float)extra->width - 1.0f; |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1919 extra->image_vertices[1] = extra->image_vertices[3] = -2.0f * (y + height) / (float)extra->height + 1.0f; |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1920 extra->image_vertices[5] = extra->image_vertices[7] = -2.0f * y / (float)extra->height + 1.0f; |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1921 |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1922 SDL_GL_MakeCurrent(extra->win, extra->gl_context); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1923 glBindBuffer(GL_ARRAY_BUFFER, extra->image_buffer); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1924 glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data_default), extra->image_vertices, GL_DYNAMIC_DRAW); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1925 } |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1926 #endif |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1927 |
2429
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1928 void render_draw_image(uint8_t window, uint8_t image, int x, int y, int width, int height) |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1929 { |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1930 extra_window *extra = extras + window - FRAMEBUFFER_USER_START; |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1931 if (extra->renderer) { |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1932 SDL_Rect dst = { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1933 .x = x, |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1934 .y = y, |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1935 .w = width, |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1936 .h = height |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1937 }; |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1938 SDL_RenderCopy(extra->renderer, extra->static_images[image], NULL, &dst); |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1939 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1940 #ifndef DISABLE_OPENGL |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1941 else { |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1942 extra_update_verts(extra, x, y, width, height); |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
1943 extra_draw_quad(extra, extra->gl_static_images[image], 1.0f, 1.0f); |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1944 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1945 #endif |
2429
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1946 } |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1947 |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1948 void render_clear_window(uint8_t window, uint8_t r, uint8_t g, uint8_t b) |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1949 { |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1950 uint8_t win_idx = window - FRAMEBUFFER_USER_START; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1951 if (extras[win_idx].renderer) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1952 SDL_SetRenderDrawColor(extras[win_idx].renderer, r, g, b, 255); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1953 SDL_RenderClear(extras[win_idx].renderer); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1954 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1955 #ifndef DISABLE_OPENGL |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1956 else { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1957 SDL_GL_MakeCurrent(extras[win_idx].win, extras[win_idx].gl_context); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1958 glClearColor(r / 255.0f, g / 255.0f, b / 255.0f, 1.0f); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1959 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1960 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1961 #endif |
2429
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1962 } |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1963 |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1964 void render_fill_rect(uint8_t window, uint8_t r, uint8_t g, uint8_t b, int x, int y, int width, int height) |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1965 { |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1966 extra_window *extra = extras + window - FRAMEBUFFER_USER_START; |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1967 if (extra->renderer) { |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1968 SDL_SetRenderDrawColor(extra->renderer, r, g, b, 255); |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1969 SDL_Rect dst = { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1970 .x = x, |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1971 .y = y, |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1972 .w = width, |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1973 .h = height |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1974 }; |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1975 SDL_RenderFillRect(extra->renderer, &dst); |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1976 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1977 #ifndef DISABLE_OPENGL |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1978 else { |
2514
50cff4c9286e
Fix crash in render_fill_rect in GL mode with no static images
Michael Pavone <pavone@retrodev.com>
parents:
2493
diff
changeset
|
1979 if (!extra->image_vertices) { |
50cff4c9286e
Fix crash in render_fill_rect in GL mode with no static images
Michael Pavone <pavone@retrodev.com>
parents:
2493
diff
changeset
|
1980 extra->image_vertices = malloc(sizeof(vertex_data_default)); |
50cff4c9286e
Fix crash in render_fill_rect in GL mode with no static images
Michael Pavone <pavone@retrodev.com>
parents:
2493
diff
changeset
|
1981 SDL_GL_MakeCurrent(extra->win, extra->gl_context); |
50cff4c9286e
Fix crash in render_fill_rect in GL mode with no static images
Michael Pavone <pavone@retrodev.com>
parents:
2493
diff
changeset
|
1982 glGenBuffers(1, &extra->image_buffer); |
50cff4c9286e
Fix crash in render_fill_rect in GL mode with no static images
Michael Pavone <pavone@retrodev.com>
parents:
2493
diff
changeset
|
1983 } |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1984 extra_update_verts(extra, x, y, width, height); |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1985 extra->color[0] = b; |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1986 extra->color[1] = g; |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1987 extra->color[2] = r; |
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1988 glBindTexture(GL_TEXTURE_2D, extra->gl_texture[1]); |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
1989 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, SRC_FORMAT, SRC_TYPE, extra->color); |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
1990 extra_draw_quad(extra, extra->gl_texture[1], 1.0f, 1.0f); |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1991 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1992 #endif |
2429
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1993 } |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1994 |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1995 void render_window_refresh(uint8_t window) |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
1996 { |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1997 uint8_t win_idx = window - FRAMEBUFFER_USER_START; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1998 if (extras[win_idx].renderer) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
1999 SDL_RenderPresent(extras[win_idx].renderer); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2000 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2001 #ifndef DISABLE_OPENGL |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2002 else { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2003 SDL_GL_SwapWindow(extras[win_idx].win); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2004 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2005 #endif |
2429
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
2006 } |
da3dc881d3f0
Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents:
2405
diff
changeset
|
2007 |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2008 pixel_t *locked_pixels; |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2009 uint32_t locked_pitch; |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2010 pixel_t *render_get_framebuffer(uint8_t which, int *pitch) |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
2011 { |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
2012 if (sync_src == SYNC_AUDIO_THREAD || sync_src == SYNC_EXTERNAL) { |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2013 *pitch = PITCH_BYTES(LINEBUF_SIZE); |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2014 pixel_t *buffer; |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2015 SDL_LockMutex(free_buffer_mutex); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2016 if (num_buffers) { |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2017 buffer = frame_buffers[--num_buffers]; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2018 } else { |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2019 buffer = calloc(tex_width*(tex_height + 1), sizeof(pixel_t)); |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2020 } |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2021 SDL_UnlockMutex(free_buffer_mutex); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2022 locked_pixels = buffer; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2023 return buffer; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2024 } |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2025 #ifndef DISABLE_OPENGL |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2026 if (render_gl && which <= FRAMEBUFFER_EVEN) { |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2027 *pitch = PITCH_BYTES(LINEBUF_SIZE); |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2028 return texture_buf; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2029 } else if (render_gl && which >= FRAMEBUFFER_USER_START) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2030 uint8_t win_idx = which - FRAMEBUFFER_USER_START; |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2031 *pitch = PITCH_BYTES(extras[win_idx].width); |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2032 return extras[win_idx].texture_buf; |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2033 } else { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2034 #endif |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
2035 if (which == FRAMEBUFFER_UI && !sdl_textures[which]) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
2036 sdl_textures[which] = SDL_CreateTexture(main_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, main_width, main_height); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
2037 } |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2038 SDL_Texture *tex; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2039 if (which >= FRAMEBUFFER_USER_START) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2040 uint8_t win_idx = which - FRAMEBUFFER_USER_START; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2041 if (win_idx >= num_extras || !extras[win_idx].renderer) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2042 warning("Request for invalid framebuffer number %d\n", which); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2043 return NULL; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2044 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2045 tex = extras[win_idx].sdl_texture; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2046 } else { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2047 tex = sdl_textures[which]; |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2048 } |
1952
42c12d141f6e
Remove usage of GCC pointer arithmetic on void * extension
Michael Pavone <pavone@retrodev.com>
parents:
1949
diff
changeset
|
2049 uint8_t *pixels; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2050 if (SDL_LockTexture(tex, NULL, (void **)&pixels, pitch) < 0) { |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2051 warning("Failed to lock texture: %s\n", SDL_GetError()); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2052 return NULL; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2053 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2054 static uint8_t last; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2055 if (which <= FRAMEBUFFER_EVEN) { |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2056 locked_pixels = (pixel_t *)pixels; |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2057 if (which == FRAMEBUFFER_EVEN) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2058 pixels += *pitch; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2059 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2060 locked_pitch = *pitch; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2061 if (which != last) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2062 *pitch *= 2; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2063 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2064 last = which; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2065 } |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2066 return (pixel_t *)pixels; |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2067 #ifndef DISABLE_OPENGL |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2068 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2069 #endif |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2070 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
2071 |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2072 static void release_buffer(pixel_t *buffer) |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2073 { |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2074 SDL_LockMutex(free_buffer_mutex); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2075 if (num_buffers == buffer_storage) { |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2076 buffer_storage *= 2; |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2077 frame_buffers = realloc(frame_buffers, sizeof(pixel_t*)*buffer_storage); |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2078 } |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2079 frame_buffers[num_buffers++] = buffer; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2080 SDL_UnlockMutex(free_buffer_mutex); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2081 } |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2082 |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2083 uint8_t events_processed; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2084 #ifdef __ANDROID__ |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2085 #define FPS_INTERVAL 10000 |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2086 #else |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2087 #define FPS_INTERVAL 1000 |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2088 #endif |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2089 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2090 static uint32_t last_width, last_height; |
2390
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2091 static uint8_t interlaced, last_field; |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2092 static void process_framebuffer(pixel_t *buffer, uint8_t which, int width) |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2093 { |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
2094 if (sync_src == SYNC_VIDEO && which <= FRAMEBUFFER_EVEN && source_frame_count < 0) { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
2095 source_frame++; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
2096 if (source_frame >= source_hz) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
2097 source_frame = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
2098 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
2099 source_frame_count = frame_repeat[source_frame]; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
2100 //TODO: Figure out what to do about SDL Render API texture locking |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
2101 return; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
2102 } |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
2103 |
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
2104 uint32_t height = which <= FRAMEBUFFER_EVEN |
2200
f11f4399d64b
Crop display in game gear mode
Michael Pavone <pavone@retrodev.com>
parents:
2093
diff
changeset
|
2105 ? (video_standard == VID_PAL ? 294 : 243) - (overscan_top[video_standard] + overscan_bot[video_standard]) |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
2106 : 240; |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2107 FILE *screenshot_file = NULL; |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2108 char *ext; |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2109 if (which < FRAMEBUFFER_UI) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2110 last_width = width; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2111 width -= overscan_left[video_standard] + overscan_right[video_standard]; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2112 if (screenshot_path && which == FRAMEBUFFER_ODD) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2113 screenshot_file = fopen(screenshot_path, "wb"); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2114 if (screenshot_file) { |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2115 #ifndef DISABLE_ZLIB |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2116 ext = path_extension(screenshot_path); |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2117 #endif |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2118 debug_message("Saving screenshot to %s\n", screenshot_path); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2119 } else { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2120 warning("Failed to open screenshot file %s for writing\n", screenshot_path); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2121 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2122 free(screenshot_path); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2123 screenshot_path = NULL; |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2124 } |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2125 interlaced = last_field != which; |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2126 buffer += overscan_left[video_standard] + PITCH_PIXEL_T(LINEBUF_SIZE) * overscan_top[video_standard]; |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2127 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
2128 #ifndef DISABLE_OPENGL |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2129 if (render_gl && which <= FRAMEBUFFER_EVEN) { |
1633
9b7cba9ba541
Use SDL_GL_MakeCurrent to make the SDL renderer API windows play nice with GL windows
Michael Pavone <pavone@retrodev.com>
parents:
1631
diff
changeset
|
2130 SDL_GL_MakeCurrent(main_window, main_context); |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2131 glBindTexture(GL_TEXTURE_2D, textures[which]); |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2132 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, LINEBUF_SIZE, height, SRC_FORMAT, SRC_TYPE, buffer); |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
2133 |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2134 if (screenshot_file) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2135 //properly supporting interlaced modes here is non-trivial, so only save the odd field for now |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2136 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2137 if (!strcasecmp(ext, "png")) { |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2138 free(ext); |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2139 save_png(screenshot_file, buffer, width, height, PITCH_BYTES(LINEBUF_SIZE)); |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2140 } else { |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2141 free(ext); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2142 #endif |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2143 save_ppm(screenshot_file, buffer, width, height, PITCH_BYTES(LINEBUF_SIZE)); |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2144 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2145 } |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2146 #endif |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2147 } |
2295
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
2148 #ifndef DISABLE_ZLIB |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
2149 if (apng_file) { |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
2150 if (!apng) { |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
2151 //TODO: more precise frame rate |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
2152 apng = start_apng(apng_file, width, height, video_standard == VID_PAL ? 50.0 : 60.0); |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
2153 } |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2154 save_png24_frame(apng_file, buffer, apng, width, height, PITCH_BYTES(LINEBUF_SIZE)); |
2295
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
2155 } |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2239
diff
changeset
|
2156 #endif |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2157 } else if (render_gl && which >= FRAMEBUFFER_USER_START) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2158 uint8_t win_idx = which - FRAMEBUFFER_USER_START; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2159 SDL_GL_MakeCurrent(extras[win_idx].win, extras[win_idx].gl_context); |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
2160 glBindTexture(GL_TEXTURE_2D, extras[win_idx].gl_texture[0]); |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2161 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, extras[win_idx].width, extras[win_idx].height, SRC_FORMAT, SRC_TYPE, buffer); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
2162 } else { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
2163 #endif |
2368
d6a207861cc8
Fix handling of overscan in internal screenshots
Michael Pavone <pavone@retrodev.com>
parents:
2346
diff
changeset
|
2164 uint32_t shot_height = height; |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
2165 //TODO: Support SYNC_AUDIO_THREAD/SYNC_EXTERNAL for render API framebuffers |
2390
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2166 if (which <= FRAMEBUFFER_EVEN && last_field != which) { |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2167 uint8_t *cur_dst = (uint8_t *)locked_pixels; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2168 uint8_t *cur_saved = (uint8_t *)texture_buf; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2169 uint32_t dst_off = which == FRAMEBUFFER_EVEN ? 0 : locked_pitch; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2170 uint32_t src_off = which == FRAMEBUFFER_EVEN ? locked_pitch : 0; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
2171 for (int i = 0; i < height; ++i) |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2172 { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2173 //copy saved line from other field |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2174 memcpy(cur_dst + dst_off, cur_saved, locked_pitch); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2175 //save line from this field to buffer for next frame |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2176 memcpy(cur_saved, cur_dst + src_off, locked_pitch); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2177 cur_dst += locked_pitch * 2; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2178 cur_saved += locked_pitch; |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
2179 } |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2180 height = 480; |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
2181 } |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2182 if (screenshot_file) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2183 uint32_t shot_pitch = locked_pitch; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2184 if (which == FRAMEBUFFER_EVEN) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2185 shot_height *= 2; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2186 } else { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2187 shot_pitch *= 2; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2188 } |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2189 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2190 if (!strcasecmp(ext, "png")) { |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2191 free(ext); |
2368
d6a207861cc8
Fix handling of overscan in internal screenshots
Michael Pavone <pavone@retrodev.com>
parents:
2346
diff
changeset
|
2192 save_png(screenshot_file, locked_pixels, width, shot_height, shot_pitch); |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2193 } else { |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2194 free(ext); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2195 #endif |
2368
d6a207861cc8
Fix handling of overscan in internal screenshots
Michael Pavone <pavone@retrodev.com>
parents:
2346
diff
changeset
|
2196 save_ppm(screenshot_file, locked_pixels, width, shot_height, shot_pitch); |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2197 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2198 } |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2199 #endif |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2200 } |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2201 SDL_UnlockTexture(sdl_textures[which]); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
2202 #ifndef DISABLE_OPENGL |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
2203 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
2204 #endif |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2205 if (which <= FRAMEBUFFER_EVEN) { |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2206 last_height = height; |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2207 render_update_display(); |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
2208 } else if (which == FRAMEBUFFER_UI) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
2209 SDL_RenderCopy(main_renderer, sdl_textures[which], NULL, NULL); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
2210 if (need_ui_fb_resize) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
2211 SDL_DestroyTexture(sdl_textures[which]); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
2212 sdl_textures[which] = NULL; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
2213 if (on_ui_fb_resized) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
2214 on_ui_fb_resized(); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
2215 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
2216 need_ui_fb_resize = 0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
2217 } |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2218 } else { |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2219 uint8_t win_idx = which - FRAMEBUFFER_USER_START; |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2220 if (extras[win_idx].renderer) { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2221 SDL_RenderCopy(extras[win_idx].renderer, extras[win_idx].sdl_texture, NULL, NULL); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2222 SDL_RenderPresent(extras[win_idx].renderer); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2223 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2224 #ifndef DISABLE_OPENGL |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2225 else { |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2226 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2227 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2228 |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2229 glBindBuffer(GL_ARRAY_BUFFER, extras[win_idx].gl_buffers[0]); |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
2230 extra_draw_quad( |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
2231 extras + win_idx, |
2492
88210caedc53
Get rect fills for Pico pad working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2490
diff
changeset
|
2232 extras[win_idx].gl_texture[0], |
2490
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
2233 (float)extras[win_idx].width / (float)extras[win_idx].tex_width, |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
2234 (float)extras[win_idx].height / (float)extras[win_idx].tex_height |
a0837ea61fda
Get static images working in GL mode
Michael Pavone <pavone@retrodev.com>
parents:
2484
diff
changeset
|
2235 ); |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2236 |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2237 SDL_GL_SwapWindow(extras[win_idx].win); |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2238 } |
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2239 #endif |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2240 } |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2241 if (screenshot_file) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2242 fclose(screenshot_file); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
2243 } |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2244 if (which <= FRAMEBUFFER_EVEN) { |
2390
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2245 last_field = which; |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2246 static uint32_t frame_counter, start; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2247 frame_counter++; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2248 last_frame= SDL_GetTicks(); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2249 if ((last_frame - start) > FPS_INTERVAL) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2250 if (start && (last_frame-start)) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2251 #ifdef __ANDROID__ |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
2252 debug_message("%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0)); |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2253 #else |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2254 if (!fps_caption) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2255 fps_caption = malloc(strlen(caption) + strlen(" - 100000000.1 fps") + 1); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2256 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2257 sprintf(fps_caption, "%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0)); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2258 SDL_SetWindowTitle(main_window, fps_caption); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2259 #endif |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2260 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2261 start = last_frame; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2262 frame_counter = 0; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2263 } |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
2264 } |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2265 if (!render_is_audio_sync()) { |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2266 int32_t local_cur_min, local_min_remaining; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2267 SDL_LockAudio(); |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2268 if (last_buffered > NO_LAST_BUFFERED) { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2269 average_change *= 0.9f; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2270 average_change += (cur_min_buffered - last_buffered) * 0.1f; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2271 } |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2272 local_cur_min = cur_min_buffered; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2273 local_min_remaining = min_remaining_buffer; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2274 last_buffered = cur_min_buffered; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2275 SDL_UnlockAudio(); |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2276 float frames_to_problem; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2277 if (average_change < 0) { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2278 frames_to_problem = (float)local_cur_min / -average_change; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2279 } else { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2280 frames_to_problem = (float)local_min_remaining / average_change; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2281 } |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
2282 float adjust_ratio = 0.0f; |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2283 if ( |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2284 frames_to_problem < BUFFER_FRAMES_THRESHOLD |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
2285 || (average_change < 0 && local_cur_min < 3*min_buffered / 4) |
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
2286 || (average_change >0 && local_cur_min > 5 * min_buffered / 4) |
1635
022d01b64496
Fix edge case in DRC audio path
Michael Pavone <pavone@retrodev.com>
parents:
1633
diff
changeset
|
2287 || cur_min_buffered < 0 |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2288 ) { |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
2289 |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2290 if (cur_min_buffered < 0) { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2291 adjust_ratio = max_adjust; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2292 SDL_PauseAudio(1); |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2293 last_buffered = NO_LAST_BUFFERED; |
1589
780604a036e4
Limit underflow warning spam
Michael Pavone <pavone@retrodev.com>
parents:
1588
diff
changeset
|
2294 cur_min_buffered = 0; |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2295 } else { |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
2296 adjust_ratio = -1.0 * average_change / ((float)sample_rate / (float)source_hz); |
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
2297 adjust_ratio /= 2.5 * source_hz; |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2298 if (fabsf(adjust_ratio) > max_adjust) { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2299 adjust_ratio = adjust_ratio > 0 ? max_adjust : -max_adjust; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2300 } |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2301 } |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
2302 } else if (local_cur_min < min_buffered / 2) { |
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
2303 adjust_ratio = max_adjust; |
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
2304 } |
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
2305 if (adjust_ratio != 0.0f) { |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2306 average_change = 0; |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
2307 render_audio_adjust_speed(adjust_ratio); |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
2308 |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2309 } |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2310 while (source_frame_count > 0) |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2311 { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2312 render_update_display(); |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2313 source_frame_count--; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2314 } |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2315 source_frame++; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2316 if (source_frame >= source_hz) { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2317 source_frame = 0; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2318 } |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
2319 source_frame_count = frame_repeat[source_frame]; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
2320 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2321 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2322 |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2323 typedef struct { |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2324 pixel_t *buffer; |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2325 int width; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2326 uint8_t which; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2327 } frame; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2328 frame frame_queue[4]; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2329 int frame_queue_len, frame_queue_read, frame_queue_write; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2330 |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2331 void render_framebuffer_updated(uint8_t which, int width) |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2332 { |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
2333 if (sync_src == SYNC_AUDIO_THREAD || sync_src == SYNC_EXTERNAL) { |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2334 SDL_LockMutex(frame_mutex); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2335 while (frame_queue_len == 4) { |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2336 SDL_CondSignal(frame_ready); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2337 SDL_UnlockMutex(frame_mutex); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2338 SDL_Delay(1); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2339 SDL_LockMutex(frame_mutex); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2340 } |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2341 for (int cur = frame_queue_read, i = 0; i < frame_queue_len; i++) { |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2342 if (frame_queue[cur].which == which) { |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2343 int last = (frame_queue_write - 1) & 3; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2344 frame_queue_len--; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2345 release_buffer(frame_queue[cur].buffer); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2346 if (last != cur) { |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2347 frame_queue[cur] = frame_queue[last]; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2348 } |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2349 frame_queue_write = last; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2350 break; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2351 } |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2352 cur = (cur + 1) & 3; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2353 } |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2354 frame_queue[frame_queue_write++] = (frame){ |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2355 .buffer = locked_pixels, |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2356 .width = width, |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2357 .which = which |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2358 }; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2359 frame_queue_write &= 0x3; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2360 frame_queue_len++; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2361 SDL_CondSignal(frame_ready); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2362 SDL_UnlockMutex(frame_mutex); |
2685
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2363 #ifdef __ANDROID__ |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2364 if (which <= FRAMEBUFFER_EVEN) { |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2365 static uint32_t frame_counter, start; |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2366 frame_counter++; |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2367 uint32_t last_frame= SDL_GetTicks(); |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2368 if ((last_frame - start) > FPS_INTERVAL) { |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2369 if (start && (last_frame-start)) { |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2370 debug_message("%s - %.1f fps (emulated)", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0)); |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2371 } |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2372 start = last_frame; |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2373 frame_counter = 0; |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2374 } |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2375 } |
da2e06c42d16
Add a compile-time flag to use RGB565 instead of ABGR/ARGB
Michael Pavone <pavone@retrodev.com>
parents:
2679
diff
changeset
|
2376 #endif |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2377 return; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2378 } |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2379 //TODO: Maybe fixme for render API |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2380 process_framebuffer(which < FRAMEBUFFER_USER_START ? texture_buf : extras[which - FRAMEBUFFER_USER_START].texture_buf, which, width); |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2381 } |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2382 |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2383 void render_video_loop(void) |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2384 { |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
2385 if (sync_src != SYNC_AUDIO_THREAD && sync_src != SYNC_EXTERNAL) { |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2386 return; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2387 } |
1981
3537514ea206
Go back to unpausing audio in render_video_loop to ensure the core is no longer running on the main thread when audio callbacks start when using run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
2388 SDL_PauseAudio(0); |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2389 SDL_LockMutex(frame_mutex); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2390 for(;;) |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2391 { |
2370 | 2392 while (!frame_queue_len && audio_active) |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2393 { |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2394 SDL_CondWait(frame_ready, frame_mutex); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2395 } |
1979
06c25babe464
Don't hold frame queue mutex while rendering
Michael Pavone <pavone@retrodev.com>
parents:
1978
diff
changeset
|
2396 while (frame_queue_len) |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2397 { |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2398 frame f = frame_queue[frame_queue_read++]; |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2399 frame_queue_read &= 0x3; |
1979
06c25babe464
Don't hold frame queue mutex while rendering
Michael Pavone <pavone@retrodev.com>
parents:
1978
diff
changeset
|
2400 frame_queue_len--; |
06c25babe464
Don't hold frame queue mutex while rendering
Michael Pavone <pavone@retrodev.com>
parents:
1978
diff
changeset
|
2401 SDL_UnlockMutex(frame_mutex); |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2402 process_framebuffer(f.buffer, f.which, f.width); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2403 release_buffer(f.buffer); |
1979
06c25babe464
Don't hold frame queue mutex while rendering
Michael Pavone <pavone@retrodev.com>
parents:
1978
diff
changeset
|
2404 SDL_LockMutex(frame_mutex); |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2405 } |
2370 | 2406 if (!audio_active) { |
1980
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1979
diff
changeset
|
2407 break; |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1979
diff
changeset
|
2408 } |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2409 } |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
2410 |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2411 SDL_UnlockMutex(frame_mutex); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2412 } |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1895
diff
changeset
|
2413 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2414 static ui_render_fun render_ui; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2415 void render_set_ui_render_fun(ui_render_fun fun) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2416 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2417 render_ui = fun; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2418 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2419 |
2600
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
2420 static ui_render_fun frame_presented; |
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
2421 void render_set_frame_presented_fun(ui_render_fun fun) |
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
2422 { |
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
2423 frame_presented = fun; |
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
2424 } |
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
2425 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2426 void render_update_display() |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2427 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2428 #ifndef DISABLE_OPENGL |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2429 if (render_gl) { |
2376
1c09f5be285b
Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents:
2370
diff
changeset
|
2430 SDL_GL_MakeCurrent(main_window, main_context); |
1528
855210dca5b9
Set glClearColor back to black
Michael Pavone <pavone@retrodev.com>
parents:
1483
diff
changeset
|
2431 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2432 glClear(GL_COLOR_BUFFER_BIT); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2433 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2434 glUseProgram(program); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2435 glActiveTexture(GL_TEXTURE0); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2436 glBindTexture(GL_TEXTURE_2D, textures[0]); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2437 glUniform1i(un_textures[0], 0); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2438 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2439 glActiveTexture(GL_TEXTURE1); |
2390
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2440 int bot_texture = 2; //black texture |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2441 if (interlaced) { |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2442 bot_texture = 1; |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2443 } else if (!scanlines && un_scanlines == -1) { |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2444 bot_texture = 0; |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2445 } |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2446 glBindTexture(GL_TEXTURE_2D, textures[bot_texture]); |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2447 glUniform1i(un_textures[1], 1); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2448 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2449 glUniform1f(un_width, render_emulated_width()); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2450 glUniform1f(un_height, last_height); |
1977
f3cca4b3f17a
Allow use of NPOT textures as a config option. Useful for some mobile GPUs
Michael Pavone <pavone@retrodev.com>
parents:
1975
diff
changeset
|
2451 glUniform2f(un_texsize, tex_width, tex_height); |
2390
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2452 if (un_curfield != -1) { |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2453 glUniform1i(un_curfield, last_field); |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2454 } |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2455 if (un_interlaced != -1) { |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2456 glUniform1i(un_interlaced, interlaced); |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2457 } |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2458 if (un_scanlines != -1) { |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2459 glUniform1i(un_scanlines, scanlines); |
9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
Michael Pavone <pavone@retrodev.com>
parents:
2388
diff
changeset
|
2460 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2461 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2462 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2463 glVertexAttribPointer(at_pos, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat[2]), (void *)0); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2464 glEnableVertexAttribArray(at_pos); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2465 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2466 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2467 glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, (void *)0); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2468 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2469 glDisableVertexAttribArray(at_pos); |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
2470 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2471 if (render_ui) { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2472 render_ui(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2473 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2474 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2475 SDL_GL_SwapWindow(main_window); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2476 } else { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2477 #endif |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2478 SDL_Rect src_clip = { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2479 .x = overscan_left[video_standard], |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2480 .y = overscan_top[video_standard], |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2481 .w = render_emulated_width(), |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2482 .h = last_height |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2483 }; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2484 SDL_SetRenderDrawColor(main_renderer, 0, 0, 0, 255); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2485 SDL_RenderClear(main_renderer); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2486 SDL_RenderCopy(main_renderer, sdl_textures[FRAMEBUFFER_ODD], &src_clip, &main_clip); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2487 if (render_ui) { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2488 render_ui(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2489 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2490 SDL_RenderPresent(main_renderer); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2491 #ifndef DISABLE_OPENGL |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2492 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
2493 #endif |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2494 if (!events_processed) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2495 process_events(); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2496 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2497 events_processed = 0; |
2600
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
2498 if (frame_presented) { |
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
2499 frame_presented(); |
251cc75574af
Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents:
2553
diff
changeset
|
2500 } |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2501 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2502 |
1398
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2503 uint32_t render_emulated_width() |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2504 { |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2505 return last_width - overscan_left[video_standard] - overscan_right[video_standard]; |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2506 } |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2507 |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2508 uint32_t render_emulated_height() |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2509 { |
2200
f11f4399d64b
Crop display in game gear mode
Michael Pavone <pavone@retrodev.com>
parents:
2093
diff
changeset
|
2510 return (video_standard == VID_PAL ? 294 : 243) - overscan_top[video_standard] - overscan_bot[video_standard]; |
1398
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2511 } |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2512 |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2513 uint32_t render_overscan_left() |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2514 { |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2515 return overscan_left[video_standard]; |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2516 } |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2517 |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2518 uint32_t render_overscan_top() |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2519 { |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2520 return overscan_top[video_standard]; |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2521 } |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
2522 |
1881
55198fc9cc1f
Don't render lines that are cropped by overscan. Allows submitting frame earlier when bottom overscan is non-zero which can reduce latency in some cases
Mike Pavone <pavone@retrodev.com>
parents:
1865
diff
changeset
|
2523 uint32_t render_overscan_bot() |
55198fc9cc1f
Don't render lines that are cropped by overscan. Allows submitting frame earlier when bottom overscan is non-zero which can reduce latency in some cases
Mike Pavone <pavone@retrodev.com>
parents:
1865
diff
changeset
|
2524 { |
55198fc9cc1f
Don't render lines that are cropped by overscan. Allows submitting frame earlier when bottom overscan is non-zero which can reduce latency in some cases
Mike Pavone <pavone@retrodev.com>
parents:
1865
diff
changeset
|
2525 return overscan_bot[video_standard]; |
55198fc9cc1f
Don't render lines that are cropped by overscan. Allows submitting frame earlier when bottom overscan is non-zero which can reduce latency in some cases
Mike Pavone <pavone@retrodev.com>
parents:
1865
diff
changeset
|
2526 } |
55198fc9cc1f
Don't render lines that are cropped by overscan. Allows submitting frame earlier when bottom overscan is non-zero which can reduce latency in some cases
Mike Pavone <pavone@retrodev.com>
parents:
1865
diff
changeset
|
2527 |
1865
4c322abd9fa5
Split generic part of audio code into a separate file so it can be used in other targets besides SDL
Michael Pavone <pavone@retrodev.com>
parents:
1862
diff
changeset
|
2528 void render_wait_quit(void) |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2529 { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2530 SDL_Event event; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2531 while(SDL_WaitEvent(&event)) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2532 switch (event.type) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2533 case SDL_QUIT: |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2534 return; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2535 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2536 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2537 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2538 |
1623
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2539 int render_lookup_button(char *name) |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2540 { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2541 static tern_node *button_lookup; |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2542 if (!button_lookup) { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2543 for (int i = SDL_CONTROLLER_BUTTON_A; i < SDL_CONTROLLER_BUTTON_MAX; i++) |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2544 { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2545 button_lookup = tern_insert_int(button_lookup, SDL_GameControllerGetStringForButton(i), i); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2546 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2547 //alternative Playstation-style names |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2548 button_lookup = tern_insert_int(button_lookup, "cross", SDL_CONTROLLER_BUTTON_A); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2549 button_lookup = tern_insert_int(button_lookup, "circle", SDL_CONTROLLER_BUTTON_B); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2550 button_lookup = tern_insert_int(button_lookup, "square", SDL_CONTROLLER_BUTTON_X); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2551 button_lookup = tern_insert_int(button_lookup, "triangle", SDL_CONTROLLER_BUTTON_Y); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2552 button_lookup = tern_insert_int(button_lookup, "share", SDL_CONTROLLER_BUTTON_BACK); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2553 button_lookup = tern_insert_int(button_lookup, "select", SDL_CONTROLLER_BUTTON_BACK); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2554 button_lookup = tern_insert_int(button_lookup, "options", SDL_CONTROLLER_BUTTON_START); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2555 button_lookup = tern_insert_int(button_lookup, "l1", SDL_CONTROLLER_BUTTON_LEFTSHOULDER); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2556 button_lookup = tern_insert_int(button_lookup, "r1", SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2557 button_lookup = tern_insert_int(button_lookup, "l3", SDL_CONTROLLER_BUTTON_LEFTSTICK); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2558 button_lookup = tern_insert_int(button_lookup, "r3", SDL_CONTROLLER_BUTTON_RIGHTSTICK); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2559 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2560 return (int)tern_find_int(button_lookup, name, SDL_CONTROLLER_BUTTON_INVALID); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2561 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2562 |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2563 int render_lookup_axis(char *name) |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2564 { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2565 static tern_node *axis_lookup; |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2566 if (!axis_lookup) { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2567 for (int i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2568 { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2569 axis_lookup = tern_insert_int(axis_lookup, SDL_GameControllerGetStringForAxis(i), i); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2570 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2571 //alternative Playstation-style names |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2572 axis_lookup = tern_insert_int(axis_lookup, "l2", SDL_CONTROLLER_AXIS_TRIGGERLEFT); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2573 axis_lookup = tern_insert_int(axis_lookup, "r2", SDL_CONTROLLER_AXIS_TRIGGERRIGHT); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2574 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2575 return (int)tern_find_int(axis_lookup, name, SDL_CONTROLLER_AXIS_INVALID); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2576 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2577 |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2578 int32_t render_translate_input_name(int32_t controller, char *name, uint8_t is_axis) |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2579 { |
1623
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2580 tern_node *button_lookup, *axis_lookup; |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2581 if (controller > MAX_JOYSTICKS || !joysticks[controller]) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2582 return RENDER_NOT_PLUGGED_IN; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2583 } |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
2584 |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2585 if (!SDL_IsGameController(joystick_sdl_index[controller])) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2586 return RENDER_NOT_MAPPED; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2587 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2588 SDL_GameController *control = SDL_GameControllerOpen(joystick_sdl_index[controller]); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2589 if (!control) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2590 warning("Failed to open game controller %d: %s\n", controller, SDL_GetError()); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2591 return RENDER_NOT_PLUGGED_IN; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2592 } |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
2593 |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2594 SDL_GameControllerButtonBind cbind; |
1804
34370330eaf3
Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents:
1799
diff
changeset
|
2595 int32_t is_positive = RENDER_AXIS_POS; |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2596 if (is_axis) { |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
2597 |
1623
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2598 int sdl_axis = render_lookup_axis(name); |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2599 if (sdl_axis == SDL_CONTROLLER_AXIS_INVALID) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2600 SDL_GameControllerClose(control); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2601 return RENDER_INVALID_NAME; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2602 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2603 cbind = SDL_GameControllerGetBindForAxis(control, sdl_axis); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2604 } else { |
1623
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
2605 int sdl_button = render_lookup_button(name); |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2606 if (sdl_button == SDL_CONTROLLER_BUTTON_INVALID) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2607 SDL_GameControllerClose(control); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2608 return RENDER_INVALID_NAME; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2609 } |
1804
34370330eaf3
Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents:
1799
diff
changeset
|
2610 if (sdl_button == SDL_CONTROLLER_BUTTON_DPAD_UP || sdl_button == SDL_CONTROLLER_BUTTON_DPAD_LEFT) { |
34370330eaf3
Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents:
1799
diff
changeset
|
2611 //assume these will be negative if they are an axis |
34370330eaf3
Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents:
1799
diff
changeset
|
2612 is_positive = 0; |
34370330eaf3
Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents:
1799
diff
changeset
|
2613 } |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2614 cbind = SDL_GameControllerGetBindForButton(control, sdl_button); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2615 } |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2616 SDL_GameControllerClose(control); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2617 switch (cbind.bindType) |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2618 { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2619 case SDL_CONTROLLER_BINDTYPE_BUTTON: |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2620 return cbind.value.button; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2621 case SDL_CONTROLLER_BINDTYPE_AXIS: |
1804
34370330eaf3
Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents:
1799
diff
changeset
|
2622 return RENDER_AXIS_BIT | cbind.value.axis | is_positive; |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2623 case SDL_CONTROLLER_BINDTYPE_HAT: |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2624 return RENDER_DPAD_BIT | (cbind.value.hat.hat << 4) | cbind.value.hat.hat_mask; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2625 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2626 return RENDER_NOT_MAPPED; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2627 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2628 |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2629 int32_t render_dpad_part(int32_t input) |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2630 { |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2631 return input >> 4 & 0xFFFFFF; |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2632 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2633 |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2634 uint8_t render_direction_part(int32_t input) |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2635 { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2636 return input & 0xF; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2637 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2638 |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2639 int32_t render_axis_part(int32_t input) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2640 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2641 return input & 0xFFFFFFF; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2642 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2643 |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
2644 void process_events() |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
2645 { |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2646 if (events_processed > MAX_EVENT_POLL_PER_FRAME) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2647 return; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
2648 } |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2649 drain_events(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2650 events_processed++; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2651 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2652 |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2653 #define TOGGLE_MIN_DELAY 250 |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2654 void render_toggle_fullscreen() |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2655 { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2656 //protect against event processing causing us to attempt to toggle while still toggling |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2657 if (in_toggle) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2658 return; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2659 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2660 in_toggle = 1; |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
2661 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2662 //toggling too fast seems to cause a deadlock |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2663 static uint32_t last_toggle; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2664 uint32_t cur = SDL_GetTicks(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2665 if (last_toggle && cur - last_toggle < TOGGLE_MIN_DELAY) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2666 in_toggle = 0; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2667 return; |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
2668 } |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2669 last_toggle = cur; |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
2670 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2671 drain_events(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2672 is_fullscreen = !is_fullscreen; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2673 if (is_fullscreen) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2674 SDL_DisplayMode mode; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2675 //TODO: Multiple monitor support |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2676 SDL_GetCurrentDisplayMode(0, &mode); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2677 //In theory, the SDL2 docs suggest this is unnecessary |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2678 //but without it the OpenGL context remains the original size |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2679 //This needs to happen before the fullscreen transition to have any effect |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2680 //because SDL does not apply window size changes in fullscreen |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2681 SDL_SetWindowSize(main_window, mode.w, mode.h); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2682 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2683 SDL_SetWindowFullscreen(main_window, is_fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); |
2392
a71176b9903d
Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents:
2390
diff
changeset
|
2684 update_cursor(); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2685 //Since we change the window size on transition to full screen |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2686 //we need to set it back to normal so we can also go back to windowed mode |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2687 //normally you would think that this should only be done when actually transitioning |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2688 //but something is screwy in the guts of SDL (at least on Linux) and setting it each time |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2689 //is the only thing that seems to work reliably |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2690 //when we've just switched to fullscreen mode this should be harmless though |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2691 SDL_SetWindowSize(main_window, windowed_width, windowed_height); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2692 drain_events(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
2693 in_toggle = 0; |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
2694 need_ui_fb_resize = 1; |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
2695 } |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
2696 |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
2697 void render_errorbox(char *title, char *message) |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
2698 { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
2699 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, NULL); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
2700 } |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
2701 |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
2702 void render_warnbox(char *title, char *message) |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
2703 { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
2704 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, title, message, NULL); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
2705 } |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
2706 |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
2707 void render_infobox(char *title, char *message) |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
2708 { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
2709 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, title, message, NULL); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
2710 } |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
2711 |
1482
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
2712 uint32_t render_elapsed_ms(void) |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
2713 { |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
2714 return SDL_GetTicks(); |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
2715 } |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
2716 |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
2717 void render_sleep_ms(uint32_t delay) |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
2718 { |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
2719 return SDL_Delay(delay); |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
2720 } |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
2721 |
1483
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
2722 uint8_t render_has_gl(void) |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
2723 { |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
2724 return render_gl; |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
2725 } |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2726 |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2727 uint8_t render_get_active_framebuffer(void) |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2728 { |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2729 if (SDL_GetWindowFlags(main_window) & SDL_WINDOW_INPUT_FOCUS) { |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2730 return FRAMEBUFFER_ODD; |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2731 } |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2732 for (int i = 0; i < num_extras; i++) |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2733 { |
2484
ccee8dccd9cc
Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents:
2458
diff
changeset
|
2734 if (extras[i].win && (SDL_GetWindowFlags(extras[i].win) & SDL_WINDOW_INPUT_FOCUS)) { |
2093
46ee354f29bd
Hack fix for audio deadlock issue
Michael Pavone <pavone@retrodev.com>
parents:
2031
diff
changeset
|
2735 return FRAMEBUFFER_USER_START + i; |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2736 } |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2737 } |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2738 return 0xFF; |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2739 } |
1967
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
2740 |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
2741 uint8_t render_create_thread(render_thread *thread, const char *name, render_thread_fun fun, void *data) |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
2742 { |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
2743 *thread = SDL_CreateThread(fun, name, data); |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
2744 return *thread != 0; |
bd70f1e15684
Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents:
1952
diff
changeset
|
2745 } |
2532
f4a471730ba4
Implement clipboard paste for SC-3000
Michael Pavone <pavone@retrodev.com>
parents:
2523
diff
changeset
|
2746 |
f4a471730ba4
Implement clipboard paste for SC-3000
Michael Pavone <pavone@retrodev.com>
parents:
2523
diff
changeset
|
2747 char *render_read_clipboard(void) |
f4a471730ba4
Implement clipboard paste for SC-3000
Michael Pavone <pavone@retrodev.com>
parents:
2523
diff
changeset
|
2748 { |
f4a471730ba4
Implement clipboard paste for SC-3000
Michael Pavone <pavone@retrodev.com>
parents:
2523
diff
changeset
|
2749 char *tmp = SDL_GetClipboardText(); |
f4a471730ba4
Implement clipboard paste for SC-3000
Michael Pavone <pavone@retrodev.com>
parents:
2523
diff
changeset
|
2750 char *ret = strdup(tmp); |
f4a471730ba4
Implement clipboard paste for SC-3000
Michael Pavone <pavone@retrodev.com>
parents:
2523
diff
changeset
|
2751 SDL_free(tmp); |
f4a471730ba4
Implement clipboard paste for SC-3000
Michael Pavone <pavone@retrodev.com>
parents:
2523
diff
changeset
|
2752 return ret; |
f4a471730ba4
Implement clipboard paste for SC-3000
Michael Pavone <pavone@retrodev.com>
parents:
2523
diff
changeset
|
2753 } |