From 80fd38374f2af4363b2fbef3d3768a27a8513fb7 Mon Sep 17 00:00:00 2001 From: riccardom Date: Wed, 16 Mar 2011 21:42:53 +0000 Subject: [PATCH] Reinitialize GL after SDL_SetVideoMode On some systems SDL_SetVideoMode resets OpenGL context, dropping the screen texture and leading to glTexSubimage2D failure when using the --opengl-2d switch. Attached patch reinitialized OpenGL after window resize. This is a forward port of Jakub Higersberger patch at #2839785. This fix the broken resize with cli frontend reported in #3195218. --- desmume/src/cli/main.cpp | 28 ++++++++++++++++++++++------ desmume/src/ctrlssdl.cpp | 2 +- desmume/src/ctrlssdl.h | 11 ++++++++++- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/desmume/src/cli/main.cpp b/desmume/src/cli/main.cpp index b7d60d291..9ccbe76c6 100644 --- a/desmume/src/cli/main.cpp +++ b/desmume/src/cli/main.cpp @@ -318,11 +318,19 @@ initGL( GLuint *screen_texture) { } static void -resizeWindow( u16 width, u16 height) { +resizeWindow( u16 width, u16 height, GLuint *screen_texture) { + int comp_width = 3 * width; int comp_height = 2 * height; GLenum errCode; + surface = SDL_SetVideoMode(width, height, 32, sdl_videoFlags); + initGL(screen_texture); + +#ifdef HAVE_LIBAGG + Hud.reset(); +#endif + if ( comp_width > comp_height) { width = 2*height/3; } @@ -353,9 +361,6 @@ resizeWindow( u16 width, u16 height) { errString = gluErrorString(errCode); fprintf( stderr, "GL resize failed: %s\n", errString); } - - surface = SDL_SetVideoMode( width, height, 32, - sdl_videoFlags ); } @@ -422,9 +427,15 @@ opengl_Draw( GLuint *texture, int software_convert) { #endif /* this is a stub for resizeWindow_stub in the case of no gl headers or no opengl 2d */ +#ifdef INCLUDE_OPENGL_2D static void -resizeWindow_stub (u16 width, u16 height) { +resizeWindow_stub (u16 width, u16 height, GLuint *screen_texture) { } +#else +static void +resizeWindow_stub (u16 width, u16 height, void *screen_texture) { +} +#endif static void Draw( void) { @@ -681,7 +692,7 @@ int main(int argc, char ** argv) { /* set the initial window size */ if ( my_config.opengl_2d) { - resizeWindow( 256, 192*2); + resizeWindow( 256, 192*2, screen_texture); } #endif @@ -709,6 +720,11 @@ int main(int argc, char ** argv) { ctrls_cfg.focused = 1; ctrls_cfg.fake_mic = 0; ctrls_cfg.keypad = 0; +#ifdef INCLUDE_OPENGL_2D + ctrls_cfg.screen_texture = screen_texture; +#else + ctrls_cfg.screen_texture = NULL; +#endif ctrls_cfg.resize_cb = &resizeWindow_stub; while(!ctrls_cfg.sdl_quit) { diff --git a/desmume/src/ctrlssdl.cpp b/desmume/src/ctrlssdl.cpp index b3d55ea09..8e3ba39e5 100644 --- a/desmume/src/ctrlssdl.cpp +++ b/desmume/src/ctrlssdl.cpp @@ -428,7 +428,7 @@ process_ctrls_event( SDL_Event& event, switch (event.type) { case SDL_VIDEORESIZE: - cfg->resize_cb( event.resize.w, event.resize.h); + cfg->resize_cb( event.resize.w, event.resize.h, cfg->screen_texture); break; case SDL_ACTIVEEVENT: diff --git a/desmume/src/ctrlssdl.h b/desmume/src/ctrlssdl.h index 5c983f8a8..0b3c24378 100644 --- a/desmume/src/ctrlssdl.h +++ b/desmume/src/ctrlssdl.h @@ -23,6 +23,10 @@ #ifndef CTRLSSDL_H #define CTRLSSDL_H +#ifdef HAVE_GL_GL_H +#include +#endif + #include #include #include @@ -90,7 +94,12 @@ struct ctrls_event_config { int sdl_quit; int boost; int fake_mic; - void (*resize_cb)(u16 width, u16 height); + GLuint *screen_texture; +#ifdef HAVE_GL_GL_H + void (*resize_cb)(u16 width, u16 height, GLuint *screen_texture); +#else + void (*resize_cb)(u16 width, u16 height, void *screen_texture); +#endif }; void load_default_config(const u16 kbCfg[]);