From c9150497e3472e1057ed8286237fcf07106a075d Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Wed, 7 Jan 2015 21:07:40 +0100 Subject: [PATCH 1/3] - Move sdlglvideo code from sdl to posix/sdl. Re-add sdlglvideo.cpp path in CMakeLists.txt . Warning: it won't compile yet. --- src/CMakeLists.txt | 6 ++---- src/{ => posix}/sdl/sdlglvideo.cpp | 0 src/{ => posix}/sdl/sdlglvideo.h | 0 3 files changed, 2 insertions(+), 4 deletions(-) rename src/{ => posix}/sdl/sdlglvideo.cpp (100%) rename src/{ => posix}/sdl/sdlglvideo.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4803006c2f..3edcbaf5da 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -584,13 +584,11 @@ set( PLAT_SDL_SOURCES posix/sdl/i_joystick.cpp posix/sdl/i_main.cpp posix/sdl/i_timer.cpp - posix/sdl/sdlvideo.cpp ) + posix/sdl/sdlvideo.cpp + posix/sdl/sdlglvideo.cpp ) set( PLAT_OSX_SOURCES posix/osx/iwadpicker_cocoa.mm posix/osx/zdoom.icns ) - -# Fixme: This must be adjusted to the new way of doing things: -# sdl/sdlglvideo.cpp set( PLAT_COCOA_SOURCES posix/cocoa/hid/HID_Config_Utilities.c posix/cocoa/hid/HID_Error_Handler.c diff --git a/src/sdl/sdlglvideo.cpp b/src/posix/sdl/sdlglvideo.cpp similarity index 100% rename from src/sdl/sdlglvideo.cpp rename to src/posix/sdl/sdlglvideo.cpp diff --git a/src/sdl/sdlglvideo.h b/src/posix/sdl/sdlglvideo.h similarity index 100% rename from src/sdl/sdlglvideo.h rename to src/posix/sdl/sdlglvideo.h From 37321d1d483cee0c01285774921fb861bd6f9c1e Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Thu, 8 Jan 2015 00:23:14 +0100 Subject: [PATCH 2/3] - Implement SDL2 into GZDoom (needs improvements). Make also minor fixes. Now it compiles and runs fine for me, except for the invisible cursor in the menu (no idea why). --- src/posix/sdl/sdlglvideo.cpp | 67 +++++++++++++++++++++--------------- src/posix/sdl/sdlglvideo.h | 9 ++--- 2 files changed, 44 insertions(+), 32 deletions(-) diff --git a/src/posix/sdl/sdlglvideo.cpp b/src/posix/sdl/sdlglvideo.cpp index 649989e6da..9331c0f020 100644 --- a/src/posix/sdl/sdlglvideo.cpp +++ b/src/posix/sdl/sdlglvideo.cpp @@ -1,8 +1,6 @@ // HEADER FILES ------------------------------------------------------------ -#include - #include "doomtype.h" #include "templates.h" @@ -48,6 +46,7 @@ extern IVideo *Video; // extern int vid_renderer; EXTERN_CVAR (Float, Gamma) +EXTERN_CVAR (Int, vid_adapter) EXTERN_CVAR (Int, vid_displaybits) EXTERN_CVAR (Int, vid_renderer) @@ -156,14 +155,19 @@ bool SDLGLVideo::NextMode (int *width, int *height, bool *letterbox) } else { - SDL_Rect **modes = SDL_ListModes (NULL, SDL_FULLSCREEN|SDL_HWSURFACE); - if (modes != NULL && modes[IteratorMode] != NULL) + SDL_DisplayMode mode = {}, oldmode = {}; + if(IteratorMode != 0) + SDL_GetDisplayMode(vid_adapter, IteratorMode-1, &oldmode); + do { - *width = modes[IteratorMode]->w; - *height = modes[IteratorMode]->h; + if (SDL_GetDisplayMode(vid_adapter, IteratorMode, &mode) != 0) + return false; ++IteratorMode; - return true; - } + } while(mode.w == oldmode.w && mode.h == oldmode.h); + + *width = mode.w; + *height = mode.h; + return true; } return false; } @@ -182,11 +186,11 @@ DFrameBuffer *SDLGLVideo::CreateFrameBuffer (int width, int height, bool fullscr if (fb->Width == width && fb->Height == height) { - bool fsnow = (fb->Screen->flags & SDL_FULLSCREEN) != 0; + bool fsnow = (SDL_GetWindowFlags (fb->Screen) & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0; if (fsnow != fullscreen) { - SDL_WM_ToggleFullScreen (fb->Screen); + SDL_SetWindowFullscreen (fb->Screen, fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); } return old; } @@ -336,30 +340,37 @@ SDLGLFB::SDLGLFB (void *, int width, int height, int, int, bool fullscreen) return; } - - Screen = SDL_SetVideoMode (width, height, - 32, - SDL_HWSURFACE|SDL_HWPALETTE|SDL_OPENGL | SDL_GL_DOUBLEBUFFER|SDL_ANYFORMAT| - (fullscreen ? SDL_FULLSCREEN : 0)); + FString caption; + caption.Format(GAMESIG " %s (%s)", GetVersionString(), GetGitTime()); + Screen = SDL_CreateWindow (caption, + SDL_WINDOWPOS_UNDEFINED_DISPLAY(vid_adapter), SDL_WINDOWPOS_UNDEFINED_DISPLAY(vid_adapter), + width, height, (fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)|SDL_WINDOW_OPENGL); if (Screen == NULL) return; - m_supportsGamma = -1 != SDL_GetGammaRamp(m_origGamma[0], m_origGamma[1], m_origGamma[2]); - -#if defined(__APPLE__) - // Need to set title here because a window is not created yet when calling the same function from main() - char caption[100]; - mysnprintf(caption, countof(caption), GAMESIG " %s (%s)", GetVersionString(), GetGitTime()); - SDL_WM_SetCaption(caption, NULL); -#endif // __APPLE__ + GLContext = SDL_GL_CreateContext(Screen); + if (GLContext == NULL) + return; + + m_supportsGamma = -1 != SDL_GetWindowGammaRamp(Screen, m_origGamma[0], m_origGamma[1], m_origGamma[2]); } SDLGLFB::~SDLGLFB () { - if (m_supportsGamma) + if (Screen) { - SDL_SetGammaRamp(m_origGamma[0], m_origGamma[1], m_origGamma[2]); + if (m_supportsGamma) + { + SDL_SetWindowGammaRamp(Screen, m_origGamma[0], m_origGamma[1], m_origGamma[2]); + } + + if (GLContext) + { + SDL_GL_DeleteContext(GLContext); + } + + SDL_DestroyWindow(Screen); } } @@ -386,7 +397,7 @@ bool SDLGLFB::CanUpdate () void SDLGLFB::SetGammaTable(WORD *tbl) { - SDL_SetGammaRamp(&tbl[0], &tbl[256], &tbl[512]); + SDL_SetWindowGammaRamp(Screen, &tbl[0], &tbl[256], &tbl[512]); } bool SDLGLFB::Lock(bool buffered) @@ -420,7 +431,7 @@ bool SDLGLFB::IsLocked () bool SDLGLFB::IsFullscreen () { - return (Screen->flags & SDL_FULLSCREEN) != 0; + return (SDL_GetWindowFlags (Screen) & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0; } @@ -443,6 +454,6 @@ void SDLGLFB::NewRefreshRate () void SDLGLFB::SwapBuffers() { - SDL_GL_SwapBuffers (); + SDL_GL_SwapWindow (Screen); } diff --git a/src/posix/sdl/sdlglvideo.h b/src/posix/sdl/sdlglvideo.h index 205e416c03..3867be69c6 100644 --- a/src/posix/sdl/sdlglvideo.h +++ b/src/posix/sdl/sdlglvideo.h @@ -3,7 +3,6 @@ #include "hardware.h" #include "v_video.h" -#include #include "gl/system/gl_system.h" EXTERN_CVAR (Float, dimamount) @@ -70,9 +69,11 @@ protected: SDLGLFB () {} BYTE GammaTable[3][256]; bool UpdatePending; - - SDL_Surface *Screen; - + + SDL_Window *Screen; + + SDL_GLContext GLContext; + void UpdateColors (); int m_Lock; From cab509c4d20f0e5e57099d24792a853a7adaa326 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Thu, 8 Jan 2015 01:39:29 +0100 Subject: [PATCH 3/3] Various improvements to SDL2 video code. - Ported the missing resolutions from zdoom. - Remove unneeded code which was removed also from zdoom. - Uncomment DOUBLEBUFFER GL attribute. It was present in the old SDL_SetVideoMode call code, so why not. --- src/posix/sdl/sdlglvideo.cpp | 60 +++++++++++++++--------------------- src/posix/sdl/sdlglvideo.h | 1 - 2 files changed, 25 insertions(+), 36 deletions(-) diff --git a/src/posix/sdl/sdlglvideo.cpp b/src/posix/sdl/sdlglvideo.cpp index 9331c0f020..54506b8137 100644 --- a/src/posix/sdl/sdlglvideo.cpp +++ b/src/posix/sdl/sdlglvideo.cpp @@ -77,6 +77,7 @@ static MiniModeInfo WinModes[] = { 720, 480 }, // 16:10 { 720, 540 }, { 800, 450 }, // 16:9 + { 800, 480 }, { 800, 500 }, // 16:10 { 800, 600 }, { 848, 480 }, // 16:9 @@ -91,23 +92,33 @@ static MiniModeInfo WinModes[] = { 1152, 720 }, // 16:10 { 1152, 864 }, { 1280, 720 }, // 16:9 + { 1280, 854 }, { 1280, 800 }, // 16:10 { 1280, 960 }, - { 1344, 756 }, // 16:9 + { 1280, 1024 }, // 5:4 { 1360, 768 }, // 16:9 + { 1366, 768 }, { 1400, 787 }, // 16:9 { 1400, 875 }, // 16:10 - { 1440, 900 }, { 1400, 1050 }, + { 1440, 900 }, + { 1440, 960 }, + { 1440, 1080 }, { 1600, 900 }, // 16:9 { 1600, 1000 }, // 16:10 { 1600, 1200 }, - { 1680, 1050 }, // 16:10 - { 1920, 1080 }, // 16:9 - { 1920, 1200 }, // 16:10 - { 2054, 1536 }, - { 2560, 1440 }, // 16:9 - { 2880, 1800 } // 16:10 + { 1920, 1080 }, + { 1920, 1200 }, + { 2048, 1536 }, + { 2560, 1440 }, + { 2560, 1600 }, + { 2560, 2048 }, + { 2880, 1800 }, + { 3200, 1800 }, + { 3840, 2160 }, + { 3840, 2400 }, + { 4096, 2160 }, + { 5120, 2880 } }; // CODE -------------------------------------------------------------------- @@ -115,7 +126,6 @@ static MiniModeInfo WinModes[] = SDLGLVideo::SDLGLVideo (int parm) { IteratorBits = 0; - IteratorFS = false; if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError( ) ); @@ -135,38 +145,18 @@ void SDLGLVideo::StartModeIterator (int bits, bool fs) { IteratorMode = 0; IteratorBits = bits; - IteratorFS = fs; } bool SDLGLVideo::NextMode (int *width, int *height, bool *letterbox) { if (IteratorBits != 8) return false; - - if (!IteratorFS) - { - if ((unsigned)IteratorMode < sizeof(WinModes)/sizeof(WinModes[0])) - { - *width = WinModes[IteratorMode].Width; - *height = WinModes[IteratorMode].Height; - ++IteratorMode; - return true; - } - } - else - { - SDL_DisplayMode mode = {}, oldmode = {}; - if(IteratorMode != 0) - SDL_GetDisplayMode(vid_adapter, IteratorMode-1, &oldmode); - do - { - if (SDL_GetDisplayMode(vid_adapter, IteratorMode, &mode) != 0) - return false; - ++IteratorMode; - } while(mode.w == oldmode.w && mode.h == oldmode.h); - *width = mode.w; - *height = mode.h; + if ((unsigned)IteratorMode < sizeof(WinModes)/sizeof(WinModes[0])) + { + *width = WinModes[IteratorMode].Width; + *height = WinModes[IteratorMode].Height; + ++IteratorMode; return true; } return false; @@ -294,7 +284,7 @@ bool SDLGLVideo::SetupPixelFormat(bool allowsoftware, int multisample) SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 ); SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 8 ); -// SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); if (multisample > 0) { SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 ); SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, multisample ); diff --git a/src/posix/sdl/sdlglvideo.h b/src/posix/sdl/sdlglvideo.h index 3867be69c6..c2be3ba47e 100644 --- a/src/posix/sdl/sdlglvideo.h +++ b/src/posix/sdl/sdlglvideo.h @@ -32,7 +32,6 @@ class SDLGLVideo : public IVideo private: int IteratorMode; int IteratorBits; - bool IteratorFS; }; class SDLGLFB : public DFrameBuffer {