// // SDLVideoDriver::InitGraphicsMode // // killough 11/98: New routine, for setting hires and page flipping // sf: now returns true if an error occurred // bool SDLVideoDriver::InitGraphicsMode() { // haleyjd 06/19/11: remember characteristics of last successful modeset static int fallback_w = 640; static int fallback_h = 480; static int fallback_w_flags = SDL_WINDOW_ALLOW_HIGHDPI; // SDL_RENDERER_SOFTWARE causes failures in creating renderer static int fallback_r_flags = SDL_RENDERER_TARGETTEXTURE; bool wantfullscreen = false; bool wantdesktopfs = false; bool wantvsync = false; bool wanthardware = false; bool wantframe = true; int v_w = 640; int v_h = 480; int v_displaynum = 0; int window_flags = SDL_WINDOW_ALLOW_HIGHDPI; // SDL_RENDERER_SOFTWARE causes failures in creating renderer int renderer_flags = SDL_RENDERER_TARGETTEXTURE; // haleyjd 04/11/03: "vsync" or page-flipping support if(use_vsync) wantvsync = true; // haleyjd 07/15/09: set defaults using geom string from configuration file I_ParseGeom(i_videomode, &v_w, &v_h, &wantfullscreen, &wantvsync, &wanthardware, &wantframe, &wantdesktopfs); // haleyjd 06/21/06: allow complete command line overrides but only // on initial video mode set (setting from menu doesn't support this) I_CheckVideoCmds(&v_w, &v_h, &wantfullscreen, &wantvsync, &wanthardware, &wantframe, &wantdesktopfs); // Wanting vsync forces framebuffer acceleration on if(wantvsync) { SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "1"); renderer_flags |= SDL_RENDERER_PRESENTVSYNC; } else if(wanthardware) SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "1"); else SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "0"); // haleyjd 10/27/09 if(!wantframe) window_flags |= SDL_WINDOW_BORDERLESS; if(displaynum < SDL_GetNumVideoDisplays()) v_displaynum = displaynum; else displaynum = 0; if(!(window = SDL_CreateWindow(ee_wmCaption, SDL_WINDOWPOS_CENTERED_DISPLAY(v_displaynum), SDL_WINDOWPOS_CENTERED_DISPLAY(v_displaynum), v_w, v_h, window_flags))) { // try 320x200w safety mode if(!(window = SDL_CreateWindow(ee_wmCaption, SDL_WINDOWPOS_CENTERED_DISPLAY(v_displaynum), SDL_WINDOWPOS_CENTERED_DISPLAY(v_displaynum), fallback_w, fallback_h, fallback_w_flags))) { // SDL_TODO: Trim fat from this error message I_FatalError(I_ERR_KILL, "I_SDLInitGraphicsMode: couldn't create window for mode %dx%d;\n" " Also failed to restore fallback mode %dx%d.\n" " Check your SDL video driver settings.\n", v_w, v_h, fallback_w, fallback_h); } // reset these for below population of video struct v_w = fallback_w; v_h = fallback_h; window_flags = fallback_w_flags; } #if EE_CURRENT_PLATFORM == EE_PLATFORM_MACOSX // this and the below #else block are done here as monitor video mode isn't // set when SDL_WINDOW_FULLSCREEN (sans desktop) is ORed in during window creation if(wantfullscreen) SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); #else if(wantfullscreen && wantdesktopfs) SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); else if(wantfullscreen) // && !wantdesktopfs SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN); #endif if(!(renderer = SDL_CreateRenderer(window, -1, renderer_flags))) { if(!(renderer = SDL_CreateRenderer(window, -1, fallback_r_flags))) { // SDL_TODO: Trim fat from this error message I_FatalError(I_ERR_KILL, "I_SDLInitGraphicsMode: couldn't create renderer for mode %dx%d;\n" " Also failed to restore fallback mode %dx%d.\n" " Check your SDL video driver settings.\n", v_w, v_h, fallback_w, fallback_h); } fallback_r_flags = renderer_flags; } // Record successful mode set for use as a fallback mode fallback_w = v_w; fallback_h = v_h; fallback_w_flags = window_flags; fallback_r_flags = renderer_flags; // haleyjd 10/09/05: keep track of fullscreen state fullscreen = !!(SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP); UpdateFocus(window); UpdateGrab(window); // check for letterboxing if(I_VideoShouldLetterbox(v_w, v_h)) { int hs = I_VideoLetterboxHeight(v_w); staticDestRect.x = 0; staticDestRect.y = static_cast<Sint16>(I_VideoLetterboxOffset(v_h, hs)); staticDestRect.w = static_cast<Uint16>(v_w); staticDestRect.h = static_cast<Uint16>(hs); video.width = v_w; video.height = hs; destrect = &staticDestRect; } else { video.width = v_w; video.height = v_h; destrect = nullptr; } video.bitdepth = 8; video.pixelsize = 1; UnsetPrimaryBuffer(); SetPrimaryBuffer(); // haleyjd 11/12/09: set surface palettes immediately I_SDLSetPaletteDirect(static_cast<byte *>(wGlobalDir.cacheLumpName("PLAYPAL", PU_CACHE))); return false; }
// // SDLVideoDriver::InitGraphicsMode // // killough 11/98: New routine, for setting hires and page flipping // sf: now returns true if an error occurred // bool SDLVideoDriver::InitGraphicsMode() { // haleyjd 06/19/11: remember characteristics of last successful modeset static int fallback_w = 640; static int fallback_h = 480; static int fallback_bd = 8; static int fallback_flags = SDL_SWSURFACE; bool wantfullscreen = false; bool wantvsync = false; bool wanthardware = false; bool wantframe = true; int v_w = 640; int v_h = 480; int v_bd = 8; int flags = SDL_SWSURFACE; // haleyjd 12/03/07: cross-bit-depth support if(M_CheckParm("-8in32")) v_bd = 32; else if(i_softbitdepth > 8) { switch(i_softbitdepth) { case 16: // Valid screen bitdepth settings case 24: case 32: v_bd = i_softbitdepth; break; default: break; } } if(v_bd != 8) crossbitdepth = true; // haleyjd 04/11/03: "vsync" or page-flipping support if(use_vsync) wantvsync = true; // haleyjd 07/15/09: set defaults using geom string from configuration file I_ParseGeom(i_videomode, &v_w, &v_h, &wantfullscreen, &wantvsync, &wanthardware, &wantframe); // haleyjd 06/21/06: allow complete command line overrides but only // on initial video mode set (setting from menu doesn't support this) I_CheckVideoCmds(&v_w, &v_h, &wantfullscreen, &wantvsync, &wanthardware, &wantframe); if(wanthardware) flags = SDL_HWSURFACE; if(wantvsync) flags = SDL_HWSURFACE | SDL_DOUBLEBUF; if(wantfullscreen) flags |= SDL_FULLSCREEN; // haleyjd 10/27/09 if(!wantframe) flags |= SDL_NOFRAME; if(!SDL_VideoModeOK(v_w, v_h, v_bd, flags) || !(sdlscreen = SDL_SetVideoMode(v_w, v_h, v_bd, flags))) { // try 320x200w safety mode if(!SDL_VideoModeOK(fallback_w, fallback_h, fallback_bd, fallback_flags) || !(sdlscreen = SDL_SetVideoMode(fallback_w, fallback_h, fallback_bd, fallback_flags))) { I_FatalError(I_ERR_KILL, "I_SDLInitGraphicsMode: couldn't set mode %dx%dx%d;\n" " Also failed to restore fallback mode %dx%dx%d.\n" " Check your SDL video driver settings.\n", v_w, v_h, v_bd, fallback_w, fallback_h, fallback_bd); } // reset these for below population of video struct v_w = fallback_w; v_h = fallback_h; v_bd = fallback_bd; flags = fallback_flags; } // Record successful mode set for use as a fallback mode fallback_w = v_w; fallback_h = v_h; fallback_bd = v_bd; fallback_flags = flags; // haleyjd 10/14/09: wait for a bit so the screen can settle if(flags & SDL_FULLSCREEN) I_Sleep(500); // haleyjd 10/09/05: keep track of fullscreen state fullscreen = (sdlscreen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN; // haleyjd 12/03/07: if the video surface is not high-color, we // disable cross-bit-depth drawing for efficiency if(sdlscreen->format->BitsPerPixel == 8) crossbitdepth = false; SDL_WM_SetCaption(ee_wmCaption, ee_wmCaption); UpdateFocus(); UpdateGrab(); video.width = v_w; video.height = v_h; video.bitdepth = 8; video.pixelsize = 1; // haleyjd 11/12/09: set surface palettes immediately I_SDLSetPaletteDirect((byte *)wGlobalDir.cacheLumpName("PLAYPAL", PU_CACHE)); return false; }