X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=share%2Fvideo.c;h=36e626a519712ddc37f107701cea40667956c15c;hb=ac370bc6af16c91cd962b36229f39f04d2a29962;hp=19408a00e4e566ec6bfe4f280d228c7d7e6d9a18;hpb=183caf10562e520b85063a55329ef2b63b0d6c72;p=neverball diff --git a/share/video.c b/share/video.c index 19408a0..36e626a 100644 --- a/share/video.c +++ b/share/video.c @@ -16,6 +16,43 @@ #include "vec3.h" #include "glext.h" #include "config.h" +#include "syswm.h" +#include "sync.h" + +/*---------------------------------------------------------------------------*/ + +int video_init(const char *title, const char *icon) +{ + SDL_QuitSubSystem(SDL_INIT_VIDEO); + + if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) + { + fprintf(stderr, "%s\n", SDL_GetError()); + return 0; + } + + /* This has to happen before mode setting... */ + + set_SDL_icon(icon); + + /* Initialize the video. */ + + if (!video_mode(config_get_d(CONFIG_FULLSCREEN), + config_get_d(CONFIG_WIDTH), + config_get_d(CONFIG_HEIGHT))) + { + fprintf(stderr, "%s\n", SDL_GetError()); + return 0; + } + + /* ...and this has to happen after it. */ + + set_EWMH_icon(icon); + + SDL_WM_SetCaption(title, title); + + return 1; +} /*---------------------------------------------------------------------------*/ @@ -38,7 +75,7 @@ int check_extension(const char *needle) return 0; } -int config_mode(int f, int w, int h) +int video_mode(int f, int w, int h) { int stereo = config_get_d(CONFIG_STEREO) ? 1 : 0; int stencil = config_get_d(CONFIG_REFLECTION) ? 1 : 0; @@ -52,6 +89,14 @@ int config_mode(int f, int w, int h) SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, samples); SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, vsync); + /* Require 16-bit double buffer with 16-bit depth buffer. */ + + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + /* Try to set the currently specified mode. */ if (SDL_SetVideoMode(w, h, 0, SDL_OPENGL | (f ? SDL_FULLSCREEN : 0))) @@ -77,14 +122,6 @@ int config_mode(int f, int w, int h) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthFunc(GL_LEQUAL); - /* - * Mac OS X might still need this, because apparently SDL doesn't do - * SDL_GL_SWAP_CONTROL on OS X. TODO: investigate. - */ -#if 0 - if (vsync) sync_init(); -#endif - /* If GL supports multisample, and SDL got a multisample buffer... */ #ifdef GL_ARB_multisample @@ -96,6 +133,13 @@ int config_mode(int f, int w, int h) } #endif + glReadBuffer(GL_FRONT); + + /* Attempt manual swap control if SDL's is broken. */ + + if (vsync && SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &vsync) == -1) + sync_init(); + return 1; } @@ -104,7 +148,7 @@ int config_mode(int f, int w, int h) else if (stereo) { config_set_d(CONFIG_STEREO, 0); - return config_mode(f, w, h); + return video_mode(f, w, h); } /* If the mode failed, try decreasing the level of multisampling. */ @@ -112,7 +156,7 @@ int config_mode(int f, int w, int h) else if (buffers) { config_set_d(CONFIG_MULTISAMPLE, samples / 2); - return config_mode(f, w, h); + return video_mode(f, w, h); } /* If that mode failed, try it without reflections. */ @@ -120,7 +164,7 @@ int config_mode(int f, int w, int h) else if (stencil) { config_set_d(CONFIG_REFLECTION, 0); - return config_mode(f, w, h); + return video_mode(f, w, h); } /* If THAT mode failed, punt. */ @@ -136,12 +180,12 @@ static int last = 0; static int ticks = 0; static int frames = 0; -int config_perf(void) +int video_perf(void) { return fps; } -void config_swap(void) +void video_swap(void) { int dt; @@ -186,7 +230,7 @@ void config_swap(void) static int grabbed = 0; -void config_set_grab(int w) +void video_set_grab(int w) { if (w) { @@ -204,21 +248,21 @@ void config_set_grab(int w) grabbed = 1; } -void config_clr_grab(void) +void video_clr_grab(void) { SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_ShowCursor(SDL_ENABLE); grabbed = 0; } -int config_get_grab(void) +int video_get_grab(void) { return grabbed; } /*---------------------------------------------------------------------------*/ -void config_push_persp(float fov, float n, float f) +void video_push_persp(float fov, float n, float f) { GLdouble m[4][4]; @@ -256,7 +300,7 @@ void config_push_persp(float fov, float n, float f) glMatrixMode(GL_MODELVIEW); } -void config_push_ortho(void) +void video_push_ortho(void) { GLdouble w = (GLdouble) config_get_d(CONFIG_WIDTH); GLdouble h = (GLdouble) config_get_d(CONFIG_HEIGHT); @@ -270,7 +314,7 @@ void config_push_ortho(void) glMatrixMode(GL_MODELVIEW); } -void config_pop_matrix(void) +void video_pop_matrix(void) { glMatrixMode(GL_PROJECTION); { @@ -279,7 +323,7 @@ void config_pop_matrix(void) glMatrixMode(GL_MODELVIEW); } -void config_clear(void) +void video_clear(void) { if (config_get_d(CONFIG_REFLECTION)) glClear(GL_COLOR_BUFFER_BIT |