X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsdl.c;h=ebfd6a5c48b279fc7ff84abd233f241b2ade0d9a;hb=ae3b4e39699426588abeb16a6114819652aa2cdb;hp=480677c31bb117b3f26c07ccca2351f6841a2b42;hpb=d0409bd76aa84a8745ec2ea6d8a5480c8bea0bcd;p=rocksndiamonds.git diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 480677c3..ebfd6a5c 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -57,7 +57,7 @@ static void FinalizeScreen() gfx.draw_global_anim_function(DRAW_GLOBAL_ANIM_STAGE_2); } -static void UpdateScreen(SDL_Rect *rect) +static void UpdateScreenExt(SDL_Rect *rect, boolean with_frame_delay) { static unsigned int update_screen_delay = 0; unsigned int update_screen_delay_value = 50; /* (milliseconds) */ @@ -106,6 +106,12 @@ static void UpdateScreen(SDL_Rect *rect) #if defined(TARGET_SDL2) SDL_Texture *sdl_texture = sdl_texture_stream; + // deactivate use of target texture if render targets are not supported + if ((video.screen_rendering_mode == SPECIAL_RENDERING_TARGET || + video.screen_rendering_mode == SPECIAL_RENDERING_DOUBLE) && + sdl_texture_target == NULL) + video.screen_rendering_mode = SPECIAL_RENDERING_OFF; + if (video.screen_rendering_mode == SPECIAL_RENDERING_TARGET) sdl_texture = sdl_texture_target; @@ -148,7 +154,8 @@ static void UpdateScreen(SDL_Rect *rect) #endif // global synchronization point of the game to align video frame delay - WaitUntilDelayReached(&video.frame_delay, video.frame_delay_value); + if (with_frame_delay) + WaitUntilDelayReached(&video.frame_delay, video.frame_delay_value); #if defined(TARGET_SDL2) // show render target buffer on screen @@ -161,6 +168,16 @@ static void UpdateScreen(SDL_Rect *rect) #endif } +static void UpdateScreen_WithFrameDelay(SDL_Rect *rect) +{ + UpdateScreenExt(rect, TRUE); +} + +static void UpdateScreen_WithoutFrameDelay(SDL_Rect *rect) +{ + UpdateScreenExt(rect, FALSE); +} + static void SDLSetWindowIcon(char *basename) { /* (setting the window icon on Mac OS X would replace the high-quality @@ -374,13 +391,8 @@ void SDLInitVideoBuffer(boolean fullscreen) { video.window_scaling_percent = setup.window_scaling_percent; video.window_scaling_quality = setup.window_scaling_quality; - video.screen_rendering_mode = - (strEqual(setup.screen_rendering_mode, STR_SPECIAL_RENDERING_BITMAP) ? - SPECIAL_RENDERING_BITMAP : - strEqual(setup.screen_rendering_mode, STR_SPECIAL_RENDERING_TARGET) ? - SPECIAL_RENDERING_TARGET: - strEqual(setup.screen_rendering_mode, STR_SPECIAL_RENDERING_DOUBLE) ? - SPECIAL_RENDERING_DOUBLE : SPECIAL_RENDERING_OFF); + + SDLSetScreenRenderingMode(setup.screen_rendering_mode); #if defined(TARGET_SDL2) // SDL 2.0: support for (desktop) fullscreen mode available @@ -434,6 +446,18 @@ static boolean SDLCreateScreen(boolean fullscreen) int surface_flags_fullscreen = SURFACE_FLAGS; // (no fullscreen in SDL 1.2) #endif +#if defined(TARGET_SDL2) +#if 1 + int renderer_flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE; +#else + /* If SDL_CreateRenderer() is called from within a VirtualBox Windows VM + _without_ enabling 2D/3D acceleration and/or guest additions installed, + it will crash if flags are *not* set to SDL_RENDERER_SOFTWARE (because + it will try to use accelerated graphics and apparently fails miserably) */ + int renderer_flags = SDL_RENDERER_SOFTWARE; +#endif +#endif + int width = video.width; int height = video.height; int surface_flags = (fullscreen ? surface_flags_fullscreen : @@ -490,17 +514,8 @@ static boolean SDLCreateScreen(boolean fullscreen) if (sdl_window != NULL) { -#if 0 - /* if SDL_CreateRenderer() is called from within a VirtualBox Windows VM - *without* enabling 2D/3D acceleration and/or guest additions installed, - it will crash if flags are *not* set to SDL_RENDERER_SOFTWARE (because - it will try to use accelerated graphics and apparently fails miserably) */ if (sdl_renderer == NULL) - sdl_renderer = SDL_CreateRenderer(sdl_window, -1, SDL_RENDERER_SOFTWARE); -#else - if (sdl_renderer == NULL) - sdl_renderer = SDL_CreateRenderer(sdl_window, -1, 0); -#endif + sdl_renderer = SDL_CreateRenderer(sdl_window, -1, renderer_flags); if (sdl_renderer != NULL) { @@ -513,13 +528,13 @@ static boolean SDLCreateScreen(boolean fullscreen) SDL_TEXTUREACCESS_STREAMING, width, height); - sdl_texture_target = SDL_CreateTexture(sdl_renderer, - SDL_PIXELFORMAT_ARGB8888, - SDL_TEXTUREACCESS_TARGET, - width, height); + if (SDL_RenderTargetSupported(sdl_renderer)) + sdl_texture_target = SDL_CreateTexture(sdl_renderer, + SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_TARGET, + width, height); - if (sdl_texture_stream != NULL && - sdl_texture_target != NULL) + if (sdl_texture_stream != NULL) { // use SDL default values for RGB masks and no alpha channel new_surface = SDL_CreateRGBSurface(0, width, height, 32, 0,0,0, 0); @@ -629,13 +644,8 @@ boolean SDLSetVideoMode(boolean fullscreen) video.fullscreen_enabled = FALSE; video.window_scaling_percent = setup.window_scaling_percent; video.window_scaling_quality = setup.window_scaling_quality; - video.screen_rendering_mode = - (strEqual(setup.screen_rendering_mode, STR_SPECIAL_RENDERING_BITMAP) ? - SPECIAL_RENDERING_BITMAP : - strEqual(setup.screen_rendering_mode, STR_SPECIAL_RENDERING_TARGET) ? - SPECIAL_RENDERING_TARGET: - strEqual(setup.screen_rendering_mode, STR_SPECIAL_RENDERING_DOUBLE) ? - SPECIAL_RENDERING_DOUBLE : SPECIAL_RENDERING_OFF); + + SDLSetScreenRenderingMode(setup.screen_rendering_mode); } } @@ -711,8 +721,7 @@ void SDLSetWindowScalingQuality(char *window_scaling_quality) { SDL_Texture *new_texture; - if (sdl_texture_stream == NULL || - sdl_texture_target == NULL) + if (sdl_texture_stream == NULL) return; SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, window_scaling_quality); @@ -729,10 +738,13 @@ void SDLSetWindowScalingQuality(char *window_scaling_quality) sdl_texture_stream = new_texture; } - new_texture = SDL_CreateTexture(sdl_renderer, - SDL_PIXELFORMAT_ARGB8888, - SDL_TEXTUREACCESS_TARGET, - video.width, video.height); + if (SDL_RenderTargetSupported(sdl_renderer)) + new_texture = SDL_CreateTexture(sdl_renderer, + SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_TARGET, + video.width, video.height); + else + new_texture = NULL; if (new_texture != NULL) { @@ -746,17 +758,6 @@ void SDLSetWindowScalingQuality(char *window_scaling_quality) video.window_scaling_quality = window_scaling_quality; } -void SDLSetScreenRenderingMode(char *screen_rendering_mode) -{ - video.screen_rendering_mode = - (strEqual(screen_rendering_mode, STR_SPECIAL_RENDERING_BITMAP) ? - SPECIAL_RENDERING_BITMAP : - strEqual(screen_rendering_mode, STR_SPECIAL_RENDERING_TARGET) ? - SPECIAL_RENDERING_TARGET: - strEqual(screen_rendering_mode, STR_SPECIAL_RENDERING_DOUBLE) ? - SPECIAL_RENDERING_DOUBLE : SPECIAL_RENDERING_OFF); -} - void SDLSetWindowFullscreen(boolean fullscreen) { if (sdl_window == NULL) @@ -777,12 +778,27 @@ void SDLSetWindowFullscreen(boolean fullscreen) video.fullscreen_initial = FALSE; } } +#endif + +void SDLSetScreenRenderingMode(char *screen_rendering_mode) +{ +#if defined(TARGET_SDL2) + video.screen_rendering_mode = + (strEqual(screen_rendering_mode, STR_SPECIAL_RENDERING_BITMAP) ? + SPECIAL_RENDERING_BITMAP : + strEqual(screen_rendering_mode, STR_SPECIAL_RENDERING_TARGET) ? + SPECIAL_RENDERING_TARGET: + strEqual(screen_rendering_mode, STR_SPECIAL_RENDERING_DOUBLE) ? + SPECIAL_RENDERING_DOUBLE : SPECIAL_RENDERING_OFF); +#else + video.screen_rendering_mode = SPECIAL_RENDERING_BITMAP; +#endif +} void SDLRedrawWindow() { - UpdateScreen(NULL); + UpdateScreen_WithoutFrameDelay(NULL); } -#endif void SDLCreateBitmapContent(Bitmap *bitmap, int width, int height, int depth) @@ -843,7 +859,7 @@ void SDLCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, &src_rect, real_dst_bitmap->surface, &dst_rect); if (dst_bitmap == window) - UpdateScreen(&dst_rect); + UpdateScreen_WithFrameDelay(&dst_rect); } void SDLBlitTexture(Bitmap *bitmap, @@ -889,7 +905,7 @@ void SDLFillRectangle(Bitmap *dst_bitmap, int x, int y, int width, int height, SDL_FillRect(real_dst_bitmap->surface, &rect, color); if (dst_bitmap == window) - UpdateScreen(&rect); + UpdateScreen_WithFrameDelay(&rect); } void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height, @@ -1070,7 +1086,7 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height, if (draw_border_function != NULL) draw_border_function(); - UpdateScreen(&dst_rect2); + UpdateScreen_WithFrameDelay(&dst_rect2); } } } @@ -1129,7 +1145,7 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height, draw_border_function(); /* only update the region of the screen that is affected from fading */ - UpdateScreen(&dst_rect2); + UpdateScreen_WithFrameDelay(&dst_rect2); } } else /* fading in, fading out or cross-fading */ @@ -1160,7 +1176,7 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height, draw_border_function(); /* only update the region of the screen that is affected from fading */ - UpdateScreen(&dst_rect); + UpdateScreen_WithFrameDelay(&dst_rect); } } @@ -1174,7 +1190,7 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height, while (time_current < time_post_delay) { // updating the screen contains waiting for frame delay (non-busy) - UpdateScreen(NULL); + UpdateScreen_WithFrameDelay(NULL); time_current = SDL_GetTicks(); }