diff --git a/ps3/main.c b/ps3/main.c index e6f24ba8e8..d327ebc7d1 100644 --- a/ps3/main.c +++ b/ps3/main.c @@ -223,6 +223,7 @@ int main(int argc, char *argv[]) get_path_settings(return_to_MM); + ps3_graphics_init(); ps3_input_init(); menu_init(); @@ -244,4 +245,5 @@ int main(int argc, char *argv[]) return ssnes_main(sizeof(argv_) / sizeof(argv_[0]) - 1, argv_); ps3_input_deinit(); + ps3_graphics_deinit(); } diff --git a/ps3/ps3_input.c b/ps3/ps3_input.c index 395259130d..0d4863a8fd 100644 --- a/ps3/ps3_input.c +++ b/ps3/ps3_input.c @@ -98,7 +98,6 @@ static int16_t ps3_input_state(void *data, const struct snes_keybind **binds, static void ps3_free_input(void *data) { (void)data; - cell_pad_input_deinit(); } static void* ps3_input_initialize(void) diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index c8d771eb5d..b8cb60336b 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -91,6 +91,7 @@ static bool load_fbo_proc(void) { return true; } static bool g_quitting; unsigned g_frame_count; +void *g_gl; typedef struct gl { @@ -804,6 +805,9 @@ static void psgl_deinit(gl_t *gl) static void gl_free(void *data) { + if (g_gl) + return; + gl_t *gl = data; gl_shader_deinit(); @@ -903,6 +907,9 @@ static void psgl_init_dbgfont(gl_t *gl) static void *gl_init(const video_info_t *video, const input_driver_t **input, void **input_data) { + if (g_gl) + return g_gl; + gl_t *gl = calloc(1, sizeof(gl_t)); if (!gl) return NULL; @@ -1032,8 +1039,10 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo return NULL; } - *input = NULL; - *input_data = NULL; + if (input) + *input = NULL; + if (input_data) + *input_data = NULL; return gl; } @@ -1061,3 +1070,26 @@ const video_driver_t video_gl = { .ident = "gl" }; +// PS3 needs a working graphics stack before SSNES even starts. +// To deal with this main.c, +// the top level module owns the instance, and is created beforehand. +// When SSNES gets around to init it, it is already allocated. +// When SSNES wants to free it, it is ignored. +void ps3_video_init(void) +{ + video_info_t video_info = {0}; + // Might have to supply correct values here. + video_info.vsync = true; + video_info.force_aspect = true; + video_info.smooth = true; + video_info.input_scale = 2; + g_gl = gl_init(&video, NULL, NULL); +} + +void ps3_video_deinit(void) +{ + void *data = g_gl; + g_gl = NULL; + gl_free(data); +} + diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index 85240fd068..a13414dde0 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -24,4 +24,7 @@ #include #include +void ps3_video_init(void); +void ps3_video_deinit(void); + #endif